Ejemplo n.º 1
0
    def getFilesByMetadataQuery(self, query):
        """Return a list of LFNs satisfying given query conditions.

           Example usage:
           >>> brunH_GT_29756adger.getFilesByMetadataQuery('resonance=jpsi bossVer=6.5.5 round=exp1')
           ['/bes/File/jpsi/6.5.5/data/all/exp1/file1', .....]

        """
        #TODO: checking of output, error catching

        fc = self.client
        #TODO: calling the FileCatalog CLI object and its private method
        # is not a good way of doing this! but use it to allow construction of
        # the query meantime, until createQuery is made a public method
        cli = FileCatalogClientCLI(fc)
        metadataDict = cli._FileCatalogClientCLI__createQuery(query)
        result = fc.findFilesByMetadata(metadataDict, '/')
        if result['OK']:
            lfns = fc.findFilesByMetadata(metadataDict, '/')['Value']
            lfns.sort()
            return lfns
        else:
            print "ERROR: No files found which match query conditions."
            return None
Ejemplo n.º 2
0
    fcType = res['Value']

if not fcType:
    res = gConfig.getSections("/Resources/FileCatalogs", listOrdered=True)
    if res['OK']:
        fcType = res['Value'][0]

for switch in Script.getUnprocessedSwitches():
    if switch[0].lower() == "f" or switch[0].lower() == "file-catalog":
        fcType = switch[1]

from DIRAC.DataManagementSystem.Client.FileCatalogClientCLI import FileCatalogClientCLI

if fcType == "LcgFileCatalog" or fcType == "LFC":
    from DIRAC.Resources.Catalog.LcgFileCatalogClient import LcgFileCatalogClient
    cli = FileCatalogClientCLI(LcgFileCatalogClient())
    try:
        host = os.environ['LFC_HOST']
    except Exception, x:
        print "LFC_HOST environment variable not defined"
        sys.exit(1)
    print "Starting LFC FileCatalog client"
    cli.cmdloop()
elif fcType == "LcgFileCatalogProxy" or fcType == "LFCproxy":
    from DIRAC.Resources.Catalog.LcgFileCatalogProxyClient import LcgFileCatalogProxyClient
    cli = FileCatalogClientCLI(LcgFileCatalogProxyClient())
    print "Starting LFC Proxy FileCatalog client"
    cli.cmdloop()
elif fcType == "LcgFileCatalogCombined" or fcType == "LFCCombined":
    from DIRAC.Resources.Catalog.LcgFileCatalogCombinedClient import LcgFileCatalogCombinedClient
    cli = FileCatalogClientCLI(LcgFileCatalogCombinedClient())
Ejemplo n.º 3
0
res = gConfig.getSections("/Resources/FileCatalogs", listOrdered=True)
if not res['OK']:
    dexit(1)
fcList = res['Value']
if not fcType:
    if res['OK']:
        fcType = res['Value'][0]

for switch in Script.getUnprocessedSwitches():
    if switch[0].lower() == "f" or switch[0].lower() == "file-catalog":
        fcType = switch[1]

if not fcType:
    print "No file catalog given and defaults could not be obtained"
    sys.exit(1)

from DIRAC.DataManagementSystem.Client.FileCatalogClientCLI import FileCatalogClientCLI

result = FileCatalogFactory().createCatalog(fcType)
if not result['OK']:
    print result['Message']
    if fcList:
        print "Possible choices are:"
        for fc in fcList:
            print ' ' * 5, fc
    sys.exit(1)
print "Starting %s client" % fcType
catalog = result['Value']
cli = FileCatalogClientCLI(catalog)
cli.cmdloop()
Ejemplo n.º 4
0
 def mkdir(self, path, mode):
     print '*** mkdir', path, oct(mode)
     from DIRAC.DataManagementSystem.Client.FileCatalogClientCLI import FileCatalogClientCLI
     from COMDIRAC.Interfaces import DCatalog
     FileCatalogClientCLI(DCatalog().catalog).do_mkdir(path)
     return 0
Ejemplo n.º 5
0
Script.registerSwitch("f:", "file-catalog=",
                      "   Catalog client type to use (default %s)" % _fcType)

Script.parseCommandLine(ignoreErrors=False)

# By a Switch ?
for switch in Script.getUnprocessedSwitches():
    if switch[0].lower() == "f" or switch[0].lower() == "file-catalog":
        _fcType = switch[1]

# Create File Catalog Client
from DIRAC.Resources.Catalog.FileCatalogClient import FileCatalogClient
_client = FileCatalogClient("DataManagement/" + _fcType)

from DIRAC.DataManagementSystem.Client.FileCatalogClientCLI import FileCatalogClientCLI
_helper_fc_cli = FileCatalogClientCLI(_client)
_helper_create_query = _helper_fc_cli._FileCatalogClientCLI__createQuery


def getLFNsByQueryString(query):
    metadataDict = _helper_create_query(query)

    lfns = _client.findFilesByMetadata(metadataDict, '/')

    if not lfns["OK"]:
        import sys
        sys.stderr.write(repr(lfns))
        return list()

    return lfns["Value"]