#!/usr/bin/env sampy """ Example script for fixing fileSize and CRC information for files that have been stored with 0 size (hence, possibly also unknown crc info). Usage: You must be logged into a node with /pnfs space mounted. setup [-q appropriateEnv] sam setup fileinfo python """ import os import sys import string from SamUserApi import getSam from SamUtility.DbDerivedClient import DbDerivedClient from SamStruct.SamSize import SamSize # from the sam_admin_pyapi package: from EnstoreFileInfoHandler import EnstoreFileInfoHandler, EnstoreFileInfoHandlerException class Updater: def __init__(self): self.sam = getSam() self.db = DbDerivedClient('DbDataFiles') def update(self): # get the list of files with size 0 rows = self.db.get(['fileName'], {'fileSizeInBytes':0}) theList = [] for row in rows: theList.append(row[0]) # for each, get the locations: for file in theList: locList = self.sam.locate(args=file) # any in pnfs space? pnfsLoc = None for loc in locList: if string.find(loc.getFullPath(), "/pnfs") != -1: pnfsLoc = loc break if pnfsLoc is not None: try: enstoreData = EnstoreFileInfoHandler("%s/%s" % (pnfsLoc.getFullPath(), file)) size = enstoreData.getFileInfoDict().get('size') crcValue = enstoreData.getCRCValue() crcType = enstoreData.getCRCType() if size != 0L: print("updating file size for file '%s'..." % file) self.sam.updateFileSize(fileName=file, fileSize="%sB" % size) if crcValue != "unknown crc value": print("updating file CRC for file '%s'..." % file) self.sam.updateFileCRC(fileName=file, crcValue=crcValue, crcType=crcType) except EnstoreFileInfoHandlerException: pass if __name__ == "__main__": updater = Updater() updater.update()