support recurisve listing with -r option
authorTony Mack <tmack@paris.CS.Princeton.EDU>
Fri, 11 May 2012 14:24:47 +0000 (10:24 -0400)
committerTony Mack <tmack@paris.CS.Princeton.EDU>
Fri, 11 May 2012 14:24:47 +0000 (10:24 -0400)
sfa/client/sfaadmin.py
sfa/client/sfi.py
sfa/managers/registry_manager.py
sfa/methods/List.py

index 657c953..75bd337 100755 (executable)
@@ -43,10 +43,13 @@ class RegistryCommands(Commands):
 
     @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='authority to list (hrn/urn - mandatory)') 
     @args('-t', '--type', dest='type', metavar='<type>', help='object type', default=None) 
-    def list(self, xrn, type=None):
+    @args('-r', '--recursive', dest='recursive', metavar='<recursive>', 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'])
index 90d8647..1f1a112 100644 (file)
@@ -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"
 
index 12aea4e..16ccd9f 100644 (file)
@@ -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:
index c023fa0..d53a0a5 100644 (file)
@@ -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