当前位置: 首页>>代码示例>>Python>>正文


Python DataManager.getFilesFromDirectory方法代码示例

本文整理汇总了Python中DIRAC.DataManagementSystem.Client.DataManager.DataManager.getFilesFromDirectory方法的典型用法代码示例。如果您正苦于以下问题:Python DataManager.getFilesFromDirectory方法的具体用法?Python DataManager.getFilesFromDirectory怎么用?Python DataManager.getFilesFromDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DIRAC.DataManagementSystem.Client.DataManager.DataManager的用法示例。


在下文中一共展示了DataManager.getFilesFromDirectory方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getOutputData

# 需要导入模块: from DIRAC.DataManagementSystem.Client.DataManager import DataManager [as 别名]
# 或者: from DIRAC.DataManagementSystem.Client.DataManager.DataManager import getFilesFromDirectory [as 别名]
def getOutputData(baseDir, logLevel="INFO"):
    gLogger.setLevel(logLevel)
    exitCode = 0
    res = getProxyInfo(False, False)
    if not res["OK"]:
        gLogger.error("Failed to get client proxy information.", res["Message"])
        DIRAC.exit(71)

    print "Will search for files in %s" % baseDir
    activeDirs = [baseDir]
    # ######################################################################################################## #
    # before is from dirac-dms-user-lfns
    rm = DataManager()
    allFiles = []
    while len(activeDirs) > 0:
        currentDir = activeDirs[0]
        res = rm.getFilesFromDirectory(currentDir)
        activeDirs.remove(currentDir)
        if not res["OK"]:
            gLogger.error("Error retrieving directory contents", "%s %s" % (currentDir, res["Message"]))
        else:
            allFiles = res["Value"]
    # ######################################################################################################## #
    # get file
    ntries = 5
    # getFile supports bulk requests
    files_to_transfer = sortList(allFiles)
    successful_files = []
    failed_files = []
    while ntries > 0:
        if len(failed_files):
            files_to_transfer = failed_files
        gLogger.info("getting the following *list* of files %s" % str(files_to_transfer))
        result = rm.getFile(files_to_transfer)
        if not result["OK"]:
            gLogger.error("Could not complete DataManager request")
            gLogger.error(str(result["Message"]))
            gLogger.info("sleep for 10s and re-try")
            time.sleep(10)
            break
        # next is to check what files we got
        successful_files = result["Value"]["Successful"].keys()
        failed_files = result["Value"]["Failed"].keys()
        if len(failed_files):
            gLogger.info("Could not retrieve one or more files")
            for key in failed_files:
                gLogger.error("%s:%s" % (key, result["Value"]["Failed"][key]))
            for s in successful_files:
                files_to_transfer.remove(s)
            for f in failed_files:
                gLogger.verbose("could not retrieve: %s" % f)
        else:
            break
        ntries -= 1
    if len(failed_files):
        gLogger.error("ERROR could not get all files after %i trials. Giving up :(" % ntries)
        exitCode = 23

    if exitCode:
        return {"OK": False, "Message": "Failed to finish operations.", "RC": exitCode}
    return S_OK(successful_files)
开发者ID:Glast,项目名称:GlastDIRAC,代码行数:63,代码来源:GridAccess.py


注:本文中的DIRAC.DataManagementSystem.Client.DataManager.DataManager.getFilesFromDirectory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。