diff --git a/Script/utils.py b/Script/utils.py index 90d1b21a3e6093d88526868166ef786f20bbe85e..b444b327f69cb36114e5dc0e9ed5b6def2cf99cf 100644 --- a/Script/utils.py +++ b/Script/utils.py @@ -25,7 +25,7 @@ def castorChecksum(castorfile, castorenv, logger): 'line':logger.findCaller()[1]} logger.debug('Fetching checksum from castor for: ' + castorfile, extra = logInfo) - nsls = Popen(['nsls', '-l', '--checksum',castorfile], + nsls = Popen(['nsls', '-l', '--checksum', castorfile], stdout=PIPE, stderr=STDOUT, env=castorenv) ret = nsls.wait() nslsOut = nsls.stdout.read() @@ -44,3 +44,51 @@ def castorChecksum(castorfile, castorenv, logger): + castorfile + '. nsls output: ' + nslsOut ,extra=logInfo) return None + + +def castorinfo(castorfile, castorenv, logger): + + logInfo = {'file':logger.findCaller()[0], + 'line':logger.findCaller()[1]} + logger.debug('Fetching checksum from castor for: ' + + castorfile, extra = logInfo) + nsls = Popen(['nsls', '-l', '--checksum', castorfile], + stdout=PIPE, stderr=STDOUT, env=castorenv) + ret = nsls.wait() + nslsOut = nsls.stdout.read() + logInfo = {'file':logger.findCaller()[0], + 'line':logger.findCaller()[1]} + logger.debug(nslsOut, extra=logInfo) + + size = checksum = None + if ret == 0: + logInfo = {'file':logger.findCaller()[0], + 'line':logger.findCaller()[1]} + + try: + splitted = nslsOut.split() + + size = splitted[4] + + id = splitted.index('AD') + checksum = nslsOut.split()[id+1] + + except ValueError: + size = checksum = None + + logger.warning('Adler32 checksum not found for ' + + castorfile + '. nsls output: ' + + nslsOut, extra=logInfo) + + except IndexError: + size = checksum = None + + logger.warning('Error parsing nsls output ' + + nslsOut, extra=logInfo) + + return size,checksum + + + + +