def main(): from DIRAC.Core.Base import Script Script.registerSwitch('', 'Path=', ' Path to search for') Script.registerSwitch( '', 'SE=', ' (comma-separated list of) SEs/SE-groups to be searched') Script.parseCommandLine(ignoreErrors=True) args = Script.getPositionalArgs() import DIRAC from DIRAC import gLogger from DIRAC.Resources.Catalog.FileCatalog import FileCatalog from DIRAC.DataManagementSystem.Client.MetaQuery import MetaQuery, FILE_STANDARD_METAKEYS from DIRAC.DataManagementSystem.Utilities.DMSHelpers import resolveSEGroup path = '/' seList = None for opt, val in Script.getUnprocessedSwitches(): if opt == 'Path': path = val elif opt == 'SE': seList = resolveSEGroup(val.split(',')) if seList: args.append("SE=%s" % ','.join(seList)) fc = FileCatalog() result = fc.getMetadataFields() if not result['OK']: gLogger.error('Can not access File Catalog:', result['Message']) DIRAC.exit(-1) typeDict = result['Value']['FileMetaFields'] typeDict.update(result['Value']['DirectoryMetaFields']) # Special meta tags typeDict.update(FILE_STANDARD_METAKEYS) if len(args) < 1: print("Error: No argument provided\n%s:" % Script.scriptName) gLogger.notice("MetaDataDictionary: \n%s" % str(typeDict)) Script.showHelp(exitCode=1) mq = MetaQuery(typeDict=typeDict) result = mq.setMetaQuery(args) if not result['OK']: gLogger.error("Illegal metaQuery:", result['Message']) DIRAC.exit(-1) metaDict = result['Value'] path = metaDict.pop('Path', path) result = fc.findFilesByMetadata(metaDict, path) if not result['OK']: gLogger.error('Can not access File Catalog:', result['Message']) DIRAC.exit(-1) lfnList = sorted(result['Value']) gLogger.notice('\n'.join(lfn for lfn in lfnList))
def checkMatchQuery(self, mq, mqParent): """ Check the logical intersection between the two metaqueries :param dict mq: a dictionary of the MetaQuery to be checked against the mqParent :param dict mqParent: a dictionary of the parent MetaQuery to be checked against the mq """ # Get the metadata types defined in the catalog catalog = FileCatalog() res = catalog.getMetadataFields() if not res['OK']: gLogger.error("Error in getMetadataFields: %s" % res['Message']) return res if not res['Value']: gLogger.error("Error: no metadata fields defined") return res MetaTypeDict = res['Value']['FileMetaFields'] MetaTypeDict.update(res['Value']['DirectoryMetaFields']) res = self.checkformatQuery(mq) if not res['OK']: return res MetaQueryDict = res['Value'] res = self.checkformatQuery(mqParent) if not res['OK']: return res ParentMetaQueryDict = res['Value'] for meta, value in MetaQueryDict.items(): if meta not in MetaTypeDict: msg = 'Metadata %s is not defined in the Catalog' % meta return S_ERROR(msg) mtype = MetaTypeDict[meta] if mtype.lower() not in ['varchar(128)', 'int', 'float']: msg = 'Metatype %s is not supported' % mtype.lower() return S_ERROR(msg) if meta not in ParentMetaQueryDict: msg = 'Metadata %s is not in parent transformation query' % meta return S_ERROR(msg) if self.compareValues(value, ParentMetaQueryDict[meta]): continue else: msg = "Metadata values %s do not match with %s" % ( value, ParentMetaQueryDict[meta]) gLogger.error(msg) return S_OK(False) return S_OK(True)
) Script.parseCommandLine( ignoreErrors = True ) args = Script.getPositionalArgs() from DIRAC.Resources.Catalog.FileCatalog import FileCatalog from DIRAC.DataManagementSystem.Client.MetaQuery import MetaQuery, FILE_STANDARD_METAKEYS from DIRAC import gLogger path = '/' for opt, val in Script.getUnprocessedSwitches(): if opt == 'Path': path = val fc = FileCatalog() result = fc.getMetadataFields() if not result['OK']: gLogger.error( 'Can not access File Catalog:', result['Message'] ) DIRAC.exit( -1 ) typeDict = result['Value']['FileMetaFields'] typeDict.update( result['Value']['DirectoryMetaFields'] ) # Special meta tags typeDict.update( FILE_STANDARD_METAKEYS ) if len( args ) < 1: print "Error: No argument provided\n%s:" % Script.scriptName Script.showHelp() gLogger.notice( "MetaDataDictionary: \n%s" % str( typeDict ) ) DIRAC.exit( -1 )
])) Script.parseCommandLine(ignoreErrors=True) args = Script.getPositionalArgs() from DIRAC.Resources.Catalog.FileCatalog import FileCatalog from DIRAC.DataManagementSystem.Client.MetaQuery import MetaQuery, FILE_STANDARD_METAKEYS from DIRAC import gLogger if len(args) < 1: print "Error: No argument provided\n%s:" % Script.scriptName Script.showHelp() DIRAC.exit(-1) fc = FileCatalog() result = fc.getMetadataFields() if not result['OK']: gLogger.error('Can not access File Catalog:', result['Message']) DIRAC.exit(-1) typeDict = result['Value']['FileMetaFields'] typeDict.update(result['Value']['DirectoryMetaFields']) # Special meta tags typeDict.update(FILE_STANDARD_METAKEYS) mq = MetaQuery(typeDict=typeDict) result = mq.setMetaQuery(args) if not result['OK']: gLogger.error("Illegal metaQuery:", result['Message']) DIRAC.exit(-1) metaDict = result['Value'] path = metaDict.get('Path', '/')
def main(): Script.registerSwitch("", "Path=", " Path to search for") Script.registerSwitch( "", "SE=", " (comma-separated list of) SEs/SE-groups to be searched") # Registering arguments will automatically add their description to the help menu Script.registerArgument( [ "metaspec: metadata index specification (of the form: " '"meta=value" or "meta<value", "meta!=value", etc.)' ], mandatory=False, ) Script.parseCommandLine(ignoreErrors=True) args = Script.getPositionalArgs() import DIRAC from DIRAC import gLogger from DIRAC.Resources.Catalog.FileCatalog import FileCatalog from DIRAC.DataManagementSystem.Client.MetaQuery import MetaQuery, FILE_STANDARD_METAKEYS from DIRAC.DataManagementSystem.Utilities.DMSHelpers import resolveSEGroup path = "/" seList = None for opt, val in Script.getUnprocessedSwitches(): if opt == "Path": path = val elif opt == "SE": seList = resolveSEGroup(val.split(",")) if seList: args.append("SE=%s" % ",".join(seList)) fc = FileCatalog() result = fc.getMetadataFields() if not result["OK"]: gLogger.error("Can not access File Catalog:", result["Message"]) DIRAC.exit(-1) typeDict = result["Value"]["FileMetaFields"] typeDict.update(result["Value"]["DirectoryMetaFields"]) # Special meta tags typeDict.update(FILE_STANDARD_METAKEYS) if len(args) < 1: print("Error: No argument provided\n%s:" % Script.scriptName) gLogger.notice("MetaDataDictionary: \n%s" % str(typeDict)) Script.showHelp(exitCode=1) mq = MetaQuery(typeDict=typeDict) result = mq.setMetaQuery(args) if not result["OK"]: gLogger.error("Illegal metaQuery:", result["Message"]) DIRAC.exit(-1) metaDict = result["Value"] path = metaDict.pop("Path", path) result = fc.findFilesByMetadata(metaDict, path) if not result["OK"]: gLogger.error("Can not access File Catalog:", result["Message"]) DIRAC.exit(-1) lfnList = sorted(result["Value"]) gLogger.notice("\n".join(lfn for lfn in lfnList))