#/bin/bin/env python """blah blah blah""" from __future__ import print_function def listCatalogDir(self, directoryLFN, printOutput=False): """lists the contents of a directory in the DFC example usage: dirac.listCatalogDir("/lz/data/test", printOutput=True) param directoryLFN: LFN(s) of the directory to be listed type directoryLFN: string or list in LFN format param printOutput: prints output in a more human readable form type printOutput: Boolean""" ret = self._checkFileArgument(directoryLFN, 'LFN') if not ret['OK']: return ret fc = FileCatalog() res = fc.listDirectory(directoryLFN) if not res['OK']: self.log.warn(res['Message']) return res # treat a string as array with a single entry if isinstance(directoryLFN, str): directoryLFN = [directoryLFN] if not res['Value']['Successful']: self.log.warn("listCatalogDir failed for all LFNs (%s). Giving up." %directoryLFN) return res # now deal with the case where *some* of the LFNs are OK if res['Value']['Failed']: self.log.warn("listCatalogDir failed for: %s" %(res['Value']['Failed'])) # do not return, we still want to process the good ones if printOutput: for directory in directoryLFN: if directory in res['Value']['Successful']: print("Listing content of: %s" %directory) subdirs = res['Value']['Successful'][directory]['SubDirs'] files = res['Value']['Successful'][directory]['Files'] print("Subdirectories:") print('\n'.join("{}".format(k, v) for k, v in subdirs.items())) print("Files:") print('\n'.join("{}".format(k, v) for k, v in files.items())) # do I let the user decide ? # del (res['Value']['Failed']) return res