示例#1
0
class DownloadWorker(IWorker):
  """
  """
  #if file failed download,then append in errorDict
  errorDict = {}

  def __init__(self):
    self.badger = Badger()
    if queryFlag:
      self.m_list = self.badger.getFilesByMetadataQuery(setQuery)
    elif setNameFlag:
      self.m_list = self.badger.getFilesByDatasetName(setName)
    elif dfcDirFlag:
      self.m_list = self.badger.listDir(dfcDir)
    elif filenameFlag:
      with open(filename) as f:
        for line in f:
          self.m_list.append(line.strip())

  def get_file_list(self):
    return self.m_list

  def Do(self, item):
    badger = Badger()
    result = badger.downloadFilesByFilelist([item])#,destDir)
    if not result['OK']:
      #print result['Message'],type(result['Message'])
      errorDict.update(result['Message'])
      print errorDict
import DIRAC
from DIRAC.Core.Base import Script

from DIRAC.Resources.Catalog.FileCatalogClient import FileCatalogClient

Script.setUsageMessage(__doc__)
Script.parseCommandLine(ignoreErrors=True)
from IHEPDIRAC.Badger.API.Badger import Badger

badger = Badger()
dirs = Script.getPositionalArgs()
dfcdir = dirs[0]
localDir = dirs[1]

#get DFC file dict
lfns = badger.listDir(dfcdir)
lfnDict = badger.getSize(lfns)
base_lfnDict = {}
for k, v in lfnDict.items():
    k = os.path.basename(k)
    base_lfnDict[k] = v
#get local files dict
localFiles = badger.getFilenamesByLocaldir(localDir)
base_localDict = {}
for file in localFiles:
    base_localDict[os.path.basename(file)] = os.path.getsize(file)

filesOK = True
omitList = []
partList = []
if len(lfns) >= len(localFiles):