Skip to content

Commit

Permalink
add domains command (closes #8)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmeliza committed May 8, 2018
1 parent 2965a62 commit 3b44d7a
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion nbank/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(':')
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:

0 comments on commit 3b44d7a

Please sign in to comment.