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))
fcc = FileCatalogClient('DataManagement/FileCatalog') result = fcc.getMetadataFields() if not result['OK']: gLogger.error("Error: %s" % result['Message']) exit(0) if not result['Value']: gLogger.error("Error: no metadata fields defined") exit(0) typeDict = result['Value']['FileMetaFields'] typeDict.update(result['Value']['DirectoryMetaFields']) # Special meta tags typeDict.update(FILE_STANDARD_METAKEYS) mq = MetaQuery(typeDict=typeDict) mq.setMetaQuery([metaTransfer]) query = mq.getMetaQuery() gLogger.notice('Query: {0}'.format(query)) t = Transformation() tc = TransformationClient() t.setTransformationName(transformationName) # Must be unique t.setTransformationGroup("Transfer") t.setType(transformationType) t.setPlugin(plugin) t.setDescription("Data Transfer") t.setLongDescription("Data Transfer") # Mandatory t.setGroupSize( groupSize ) # Here you specify how many files should be grouped within he same request, e.g. 100
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', '/') metaDict.pop('Path') print metaDict result = fc.findFilesByMetadata(metaDict, path) if not result['OK']: gLogger.error('Can not access File Catalog:', result['Message']) DIRAC.exit(-1) lfnList = result['Value']
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 ) 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 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))