Beispiel #1
0
def main():
    usage = "usage: %prog [options] dcache-dir-relative-to-user-dir"
    optParser = optparse.OptionParser(usage)
    optParser.add_option("-c", "--config", dest="cfgfile",
                         help="global configuration file",
                         default=ara.defaultConfigFileName)
    (options, args) = optParser.parse_args()
    if len(args) != 1:
        optParser.print_help()
        return 1

    ara.config.read(options.cfgfile)

    # get file names from Grid storage element
    srmfiles = ara.uberftpls(ara.getUserStoragePath(args[0]), True)
    # sum up size
    totalsize = 0
    for (size, filename) in srmfiles:
        totalsize = totalsize + size

    TB = int(totalsize/1000000000000)
    GB = int(totalsize/1000000000) % 1000
    MB = int(totalsize/1000000) % 1000
    KB = int(totalsize/1000) % 1000
    B  = int(totalsize % 1000)
    print "Found", len(srmfiles), "files:", TB, "TB", GB, "GB", MB, "MB", KB, "KB", B, "B"

    return 0
Beispiel #2
0
def main():
    usage = "usage: %prog [options] dcache-dir-relative-to-user-dir"
    optParser = optparse.OptionParser(usage)
    optParser.add_option("-c", "--config", dest="cfgfile",
                         help="global configuration file",
                         default=ara.defaultConfigFileName)
    (options, args) = optParser.parse_args()
    if len(args) != 1:
        optParser.print_help()
        return 1

    ara.config.read(options.cfgfile)

    # get file names from Grid storage element
    path = ara.getUserStoragePath(args[0])
    srmfiles = ara.srmls(path, True)
    filenames=[]
    for (size, filename) in srmfiles:
        filenames.append(filename)

    # remove individual files
    if len(filenames) > 0:
        print "Removing files"
        msg = ara.srmrm(path, filenames)
        if msg != '':
            print msg

    # remove directory
    print "Removing directory", path
    msg = ara.srmrmdir(path)
    if msg != '':
        print msg
    return 0
def main():
    usage = """usage: %prog [options] dcache-dir

This program transfers files from the given directory on dcache to 
the current local directory. It checks the time stamp and sizes of
all files, and only transfers those files which are newer or not
completely transferred."""
    optParser = optparse.OptionParser(usage)
    optParser.add_option("-c", "--config", dest="cfgfile",
                         help="global configuration file",
                         default=ara.defaultConfigFileName)
    optParser.add_option("-f", "--force-deletion", action="store_true", 
                         dest="forcedeletion",
                         help="force deletion of local files",
                         default=False)
    (options, args) = optParser.parse_args()
    ara.config.read(options.cfgfile)

    # user must give path as argument
    if len(args) != 1:
        optParser.print_help()
        return 1

    # get file names from Grid storage element
    print "Reading files from grid storage, please be patient..."
    srcpath = ara.getUserStoragePath(args[0])
    srmfiles = ara.uberftpls(srcpath, True)
    # get local file names
    print "Reading local file names and stats..."
    filelist = os.listdir(".")
    localfiles = [ ]
    for localfile in filelist:
        file_stats = os.stat(localfile)
        if stat.S_ISREG(file_stats.st_mode):
            size = file_stats.st_size
            localfiles.append([size, localfile])

    # loop over all grid files and see if they are here
    print "Reconciling changes..."
    transferfiles = [ ] 
    for srmfile in srmfiles:
        if not srmfile[1].endswith(".root"):
            print "Warning: Found non-ROOT file on grid storage:", srmfile
            continue
        try:
            index = localfiles.index(srmfile)
        except ValueError:
            transferfiles.append(srmfile[1])
            print "Need to transfer file", srmfile[1]

    # determine if local ROOT files need to be deleted
    deletefiles = [ ]
    for localfile in localfiles:
        if not localfile[1].endswith(".root"):
            continue
        try:
            index = srmfiles.index(localfile)
        except ValueError:
            deletefiles.append(localfile[1])
            
    for localfile in deletefiles:
        if options.forcedeletion:
            print "Deleting local file", localfile
            os.unlink(localfile)
        else:
            print "Need to delete", localfile

    if len(deletefiles) > 0 and not options.forcedeletion:
        print "Use -f switch to delete files or remove files manually"
        return 1

    srcpath=ara.config.get('Grid', 'se')+srcpath
    destpath = 'file:///'+os.getcwd()+'/'
    for filename in transferfiles:
        print filename
        p = subprocess.Popen(["srmcp", srcpath+filename, destpath+filename],
                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        stdout, stderr = p.communicate()
        if len(stderr) > 0:
            print "Errors found:", stderr
            return 1
        if len(stdout) > 0:
            print "Stdout", stdout

    print "Done."

    return 0