diff --git a/nbank/script.py b/nbank/script.py index 064d734..921c133 100644 --- a/nbank/script.py +++ b/nbank/script.py @@ -18,12 +18,16 @@ import logging import requests as rq +try: + from urllib.parse import urlunparse +except ImportError: + from urlparse import urlunparse + from nbank import __version__ from nbank import core, archive, registry log = logging.getLogger('nbank') # root logger - def userpwd(arg): """ If arg is of the form username:password, returns them as a tuple. Otherwise None. """ ret = arg.split(':') @@ -118,6 +122,9 @@ def main(argv=None): pp.add_argument("content_type", help="the MIME content-type for the data type") pp.set_defaults(func=add_datatype) + pp = sub.add_parser('domains', help='list available domains (archives)') + pp.set_defaults(func=list_domains) + args = p.parse_args(argv) ch = logging.StreamHandler() @@ -243,5 +250,17 @@ def add_datatype(args): print("added datatype %(name)s (content-type: %(content_type)s)" % data) +def list_domains(args): + if args.registry_url is None: + log.error("error: supply a registry url with '-r' or %s environment variable", core.env_registry) + return + for domain in registry.get_domains(args.registry_url): + if domain["scheme"] == "neurobank": + print("%(name)-25s\t%(root)s" % domain) + else: + url = urlunparse(domain["scheme"], domain["root"], '', '', '', '') + print("%-25s\t%s" % (domain["name"], url)) + + # Variables: # End: