diff options
author | 2017-01-01 23:54:10 -0500 | |
---|---|---|
committer | 2017-01-01 23:54:10 -0500 | |
commit | 4af894ac1b6b3290ef2aeed6cbfa9a90de495428 (patch) | |
tree | 04db8308e3ace54f05282feaea5718a4b045969b | |
parent | server/static/about.html: fix the repo URI (diff) | |
download | gentoostats-4af894ac1b6b3290ef2aeed6cbfa9a90de495428.tar.gz gentoostats-4af894ac1b6b3290ef2aeed6cbfa9a90de495428.tar.bz2 gentoostats-4af894ac1b6b3290ef2aeed6cbfa9a90de495428.zip |
client/gentoostats-cli: add a command line option to specify the port
Remain consistent with gentoostats-send which has a ('-p', '--port')
command line option to specify the port for the remote server.
-rwxr-xr-x | client/gentoostats-cli | 1 | ||||
-rw-r--r-- | client/gentoostats/list.py | 18 | ||||
-rw-r--r-- | client/gentoostats/search.py | 2 | ||||
-rw-r--r-- | client/gentoostats/utils.py | 6 |
4 files changed, 14 insertions, 13 deletions
diff --git a/client/gentoostats-cli b/client/gentoostats-cli index 768a1ed..2ce2b2e 100755 --- a/client/gentoostats-cli +++ b/client/gentoostats-cli @@ -8,6 +8,7 @@ from gentoostats import search def main(): parser = argparse.ArgumentParser() parser.add_argument('-s', '--server', default='soc.dev.gentoo.org') + parser.add_argument('-p', '--port', type = int, default=443) parser.add_argument('-u', '--url', default='/gentoostats') # http://bugs.python.org/issue9253 diff --git a/client/gentoostats/list.py b/client/gentoostats/list.py index 8c369ab..dc1a64f 100644 --- a/client/gentoostats/list.py +++ b/client/gentoostats/list.py @@ -46,35 +46,35 @@ def list_arch(args): """ /arch """ - data = list(args.server, args.url, '/arch', utils.headers) + data = list(args.server, args.port, args.url, '/arch', utils.headers) pprint('Arch', data) def list_feature(args): """ /feature """ - data = list(args.server, args.url, '/feature', utils.headers) + data = list(args.server, args.port, args.url, '/feature', utils.headers) pprint('Feature', data) def list_lang(args): """ /lang """ - data = list(args.server, args.url, '/lang', utils.headers) + data = list(args.server, args.port, args.url, '/lang', utils.headers) pprint('Lang', data) def list_mirror(args): """ /mirror """ - data = list(args.server, args.url, '/mirror', utils.headers) + data = list(args.server, args.port, args.url, '/mirror', utils.headers) pprint('Mirror', data) def list_repo(args): """ /repo """ - data = list(args.server, args.url, '/repo', utils.headers) + data = list(args.server, args.port, args.url, '/repo', utils.headers) pprint('Repo', data) def list_package(args): @@ -97,7 +97,7 @@ def list_package(args): title = 'Category-Package-Version: ' + args.category + '/' + args.package + '-' + args.version url_pkg += '-' + args.version - data = list(args.server, args.url, url_pkg + url_top, utils.headers) + data = list(args.server, args.port, args.url, url_pkg + url_top, utils.headers) pprint(title, data) def list_use(args): @@ -110,14 +110,14 @@ def list_use(args): title = 'Useflag: ' + args.use url_use += '/' + args.use - data = list(args.server, args.url, url_use, utils.headers) + data = list(args.server, args.port, args.url, url_use, utils.headers) pprint(title, data) -def list(server, url_base, url_extra, headers): +def list(server, port, url_base, url_extra, headers): """ Get and decode json from url """ - get_data = utils.GET(server=server, url=url_base+url_extra, headers=headers) + get_data = utils.GET(server=server, port=port, url=url_base+url_extra, headers=headers) data = utils.deserialize(get_data) return data diff --git a/client/gentoostats/search.py b/client/gentoostats/search.py index 89b4d20..81265fa 100644 --- a/client/gentoostats/search.py +++ b/client/gentoostats/search.py @@ -37,7 +37,7 @@ def search(args): url_extra += ('?', '&')[bool(url_extra)] + 'min_hosts=' + str(args.min_hosts) if args.min_hosts else '' url_extra += ('?', '&')[bool(url_extra)] + 'max_hosts=' + str(args.max_hosts) if args.max_hosts else '' - get_data = utils.GET(server = args.server, url = args.url + url_base + url_extra, headers = utils.headers) + get_data = utils.GET(server = args.server, port=args.port, url = args.url + url_base + url_extra, headers = utils.headers) data = utils.deserialize(get_data) pprint ('Search results', data) diff --git a/client/gentoostats/utils.py b/client/gentoostats/utils.py index af8dab2..cc23033 100644 --- a/client/gentoostats/utils.py +++ b/client/gentoostats/utils.py @@ -8,14 +8,14 @@ except ImportError: # json headers for gentoostats-cli headers = {'Accept': 'application/json'} -def GET(server, url, headers, https=True): +def GET(server, port, url, headers, https=True): """ Get url from server using headers """ if https: - conn = httplib.HTTPSConnection(server) + conn = httplib.HTTPSConnection(server, port) else: - conn = httplib.HTTPConnection(server) + conn = httplib.HTTPConnection(server, port) try: conn.request('GET', url=url, headers=headers) data = conn.getresponse().read().decode("utf-8") |