From bd6c985f43da8b8c7c8a3e396b72fde8cf4309a8 Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Fri, 11 May 2012 10:24:47 -0400 Subject: [PATCH] support recurisve listing with -r option --- sfa/client/sfaadmin.py | 7 +++++-- sfa/client/sfi.py | 10 ++++++++-- sfa/managers/registry_manager.py | 17 ++++++++++------- sfa/methods/List.py | 4 ++-- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/sfa/client/sfaadmin.py b/sfa/client/sfaadmin.py index 657c9531..75bd3370 100755 --- a/sfa/client/sfaadmin.py +++ b/sfa/client/sfaadmin.py @@ -43,10 +43,13 @@ class RegistryCommands(Commands): @args('-x', '--xrn', dest='xrn', metavar='', help='authority to list (hrn/urn - mandatory)') @args('-t', '--type', dest='type', metavar='', help='object type', default=None) - def list(self, xrn, type=None): + @args('-r', '--recursive', dest='recursive', metavar='', help='list all child records', + action='store_true', default=False) + def list(self, xrn, type=None, recursive=False): """List names registered at a given authority - possibly filtered by type""" xrn = Xrn(xrn, type) - records = self.api.manager.List(self.api, xrn.get_hrn()) + options = {'recursive': recursive} + records = self.api.manager.List(self.api, xrn.get_hrn(), options=options) for record in records: if not type or record['type'] == type: print "%s (%s)" % (record['hrn'], record['type']) diff --git a/sfa/client/sfi.py b/sfa/client/sfi.py index 90d86476..1f1a112e 100644 --- a/sfa/client/sfi.py +++ b/sfa/client/sfi.py @@ -301,7 +301,9 @@ class Sfi: parser.add_option("-F", "--fileformat", dest="fileformat", type="choice", help="output file format ([xml]|xmllist|hrnlist)", default="xml", choices=("xml", "xmllist", "hrnlist")) - + if command == 'list': + parser.add_option("-r", "--recursive", dest="recursive", action='store_true', + help="list all child records", default=False) if command in ("delegate"): parser.add_option("-u", "--user", action="store_true", dest="delegate_user", default=False, @@ -703,8 +705,12 @@ or version information about sfi itself self.print_help() sys.exit(1) hrn = args[0] + opts = {} + if options.recursive: + opts['recursive'] = options.recursive + try: - list = self.registry().List(hrn, self.my_credential_string) + list = self.registry().List(hrn, self.my_credential_string, options) except IndexError: raise Exception, "Not enough parameters for the 'list' command" diff --git a/sfa/managers/registry_manager.py b/sfa/managers/registry_manager.py index 12aea4eb..16ccd9f2 100644 --- a/sfa/managers/registry_manager.py +++ b/sfa/managers/registry_manager.py @@ -184,14 +184,10 @@ class RegistryManager: return records - def List (self, api, xrn, origin_hrn=None): - hrn, type = urn_to_hrn(xrn) - recursive = False - if hrn.endswith('*'): - hrn = hrn[:-1] - recursive = True + def List (self, api, xrn, origin_hrn=None, options={}): # load all know registry names into a prefix tree and attempt to find # the longest matching prefix + hrn, type = urn_to_hrn(xrn) registries = api.registries registry_hrns = registries.keys() tree = prefixTree() @@ -208,13 +204,20 @@ class RegistryManager: credential = api.getCredential() interface = api.registries[registry_hrn] server_proxy = api.server_proxy(interface, credential) - record_list = server_proxy.List(xrn, credential) + record_list = server_proxy.List(xrn, credential, options) # same as above, no need to process what comes from through xmlrpc # pass foreign records as-is record_dicts = record_list # if we still have not found the record yet, try the local registry if not record_dicts: + recursive = False + if ('recursive' in options and options['recursive']): + recursive = True + elif hrn.endswith('*'): + hrn = hrn[:-1] + recursive = True + if not api.auth.hierarchy.auth_exists(hrn): raise MissingAuthority(hrn) if recursive: diff --git a/sfa/methods/List.py b/sfa/methods/List.py index c023fa01..d53a0a5e 100644 --- a/sfa/methods/List.py +++ b/sfa/methods/List.py @@ -25,7 +25,7 @@ class List(Method): # xxx used to be [SfaRecord] returns = [Parameter(dict, "registry record")] - def call(self, xrn, creds): + def call(self, xrn, creds, options={}): hrn, type = urn_to_hrn(xrn) valid_creds = self.api.auth.checkCredentials(creds, 'list') @@ -33,4 +33,4 @@ class List(Method): origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn() self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name)) - return self.api.manager.List(self.api, xrn) + return self.api.manager.List(self.api, xrn, options=options) -- 2.47.0