-
Notifications
You must be signed in to change notification settings - Fork 1
/
manage.py
executable file
·96 lines (77 loc) · 2.83 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python3
"""
Copyright (c) 2016, Regents of the University of California.
This file is part of NDN-FCH (Find Closest NDN Hub). See AUTHORS.md
for complete list of NFD authors and contributors.
NDN-FCH is free software: you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.
NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
NDN-FCH, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
"""
import os
import sys
BASEDIR = os.path.abspath(os.path.dirname(__file__))
if BASEDIR not in sys.path:
sys.path.append(BASEDIR)
import coverage
COV = coverage.coverage(
branch=True,
include='ndn_fch/*',
)
COV.start()
import flask_script
import urllib
import gzip
import shutil
import unittest
import ndn_fch
app = ndn_fch.create("%s/config.py" % os.path.abspath(os.path.dirname(__file__)))
manager = flask_script.Manager(app)
@manager.command
def list_hubs():
"""List the hub list"""
# urllib.request.urlretrieve(manager.app.config['HUBS_URL'], filename=manager.app.config['HUBS_PATH'])
for item in app.HUB_INDEX.inorder():
print(item.data)
return 0
@manager.command
def update_hubs():
"""Fetch/update the hub list"""
urllib.request.urlretrieve(manager.app.config['HUBS_URL'], filename=manager.app.config['HUBS_PATH'])
return 0
@manager.command
def update_geodb():
"""Fetch/update the ip-location database"""
tmpFile = "%s.gz" % manager.app.config['GEODB_PATH']
urllib.request.urlretrieve(manager.app.config['GEODB_URL'], filename=tmpFile)
with gzip.open(tmpFile, 'rb') as inF, open(manager.app.config['GEODB_PATH'], 'wb') as outF:
shutil.copyfileobj(inF, outF)
return 0
@manager.command
def test():
"""Runs the unit tests without test coverage."""
tests = unittest.TestLoader().discover('tests', pattern='test*.py')
result = unittest.TextTestRunner(verbosity=2).run(tests)
if result.wasSuccessful():
return 0
return 1
@manager.command
def cov():
"""Run unit tests with test coverage."""
tests = unittest.TestLoader().discover('tests', pattern='test*.py')
result = unittest.TextTestRunner(verbosity=2).run(tests)
if result.wasSuccessful():
COV.stop()
COV.save()
print('Coverage Summary:')
COV.report()
COV.html_report(directory="%s/.tmp/coverage" % os.path.abspath(os.path.dirname(__file__)))
COV.erase()
return 0
return 1
if __name__ == '__main__':
manager.run()