def moveFilesInES(self, iFileList, fileOut): """High-level method to move a list of files to fileOut destination. All job is done by using L{moveFileInES} method. @type iFileList: list @param iFileList: list of files @type fileOut: string @param fileOut: file name @rtype: integer @return: status code """ if len(iFileList) > 1 and not os.path.isdir(fileOut): print "Output directory %s doesn't exists" % fileOut return self.error fstat = os.stat(fileOut) perm = oct(stat.S_IMODE(fstat[stat.ST_MODE])) if int(perm[1]) < 6: # on Unix 6 is enough to write print "ERROR: you don't have permission to write to", fileOut return self.error fileInList = [] for iFile in iFileList: print "Processing", iFile fileType = file_util.fileType(iFile) if self.allow(fileType): fileInList.append(iFile) self.writeToLog("moveFilesInES") if self.verbose: print "Using moveFilesInES" status = self.error okList = [] compList = [] for file in fileInList: if os.path.isfile(file): status, query, cQuery = self.moveFileInES(file, fileOut) if status == self.error: print "############" print "Fail to move %s %s" % (file, fileOut) print "##############################################" print "List of successfull queries:" for item in okList: print item print "##############################################" print "List of compensating queries:" for item in compList: print item print "##############################################" print "MAKE YOUR DECISION. Either invoke compensating" print "queries or proceed." break okList.append(query) compList.append(cQuery) return status
def fileContent(args): """fileContent is a wrapper over format dependent dump routines It dump content of all supported file formats in EventStore.""" import os,sys,string,array import file_util, key_dump usage = """ESFileContent prints the content of data(hddm)/key/location files. Usage: ESFileContent [ -v ] <file> Use -v option for verbose output """ if len(args) == 1 or args[1] == "-help" or args[1] == "--help": print usage sys.exit() verbose=0 # verbose flag if len(args)==3: if args[1]=="-v": verbose=1 fileName = args[2] elif len(args)==2: fileName = args[1] else: print usage sys.exit() if os.path.isfile(fileName): fileDesc = open(fileName,'rb') else: print "File %s not found"%fileName print usage sys.exit() what = file_util.fileType(fileName) if what == "hddm": print "Found hddm file",fileName,"\n" cmd = "hddm-xml " + fileName proc = subprocess.Popen(cmd.split(' '), stdout=subprocess.PIPE) for line in proc.stdout: print line.rstrip() elif what == "ikey": print "Found key file",fileName,"\n" key_dump.dump(fileName,verbose) #elif what == "lhddm": # print "Found HDDM location file",fileName,"\n" # lhddm_dump.dump(fileName,verbose) else: print "File format is not recognized\n"
def fileContent(args): """fileContent is a wrapper over format dependent dump routines It dump content of all supported file formats in EventStore.""" import os, sys, string, array import file_util, key_dump usage = """ESFileContent prints the content of data(hddm)/key/location files. Usage: ESFileContent [ -v ] <file> Use -v option for verbose output """ if len(args) == 1 or args[1] == "-help" or args[1] == "--help": print usage sys.exit() verbose = 0 # verbose flag if len(args) == 3: if args[1] == "-v": verbose = 1 fileName = args[2] elif len(args) == 2: fileName = args[1] else: print usage sys.exit() if os.path.isfile(fileName): fileDesc = open(fileName, 'rb') else: print "File %s not found" % fileName print usage sys.exit() what = file_util.fileType(fileName) if what == "hddm": print "Found hddm file", fileName, "\n" cmd = "hddm-xml " + fileName proc = subprocess.Popen(cmd.split(' '), stdout=subprocess.PIPE) for line in proc.stdout: print line.rstrip() elif what == "ikey": print "Found key file", fileName, "\n" key_dump.dump(fileName, verbose) #elif what == "lhddm": # print "Found HDDM location file",fileName,"\n" # lhddm_dump.dump(fileName,verbose) else: print "File format is not recognized\n"
def moveFilesInES(self,iFileList,fileOut): """High-level method to move a list of files to fileOut destination. All job is done by using L{moveFileInES} method. @type iFileList: list @param iFileList: list of files @type fileOut: string @param fileOut: file name @rtype: integer @return: status code """ if len(iFileList)>1 and not os.path.isdir(fileOut): print "Output directory %s doesn't exists"%fileOut return self.error fstat = os.stat(fileOut) perm = oct(stat.S_IMODE(fstat[stat.ST_MODE])) if int(perm[1]) < 6: # on Unix 6 is enough to write print "ERROR: you don't have permission to write to",fileOut return self.error fileInList = [] for iFile in iFileList: print "Processing",iFile fileType = file_util.fileType(iFile) if self.allow(fileType): fileInList.append(iFile) self.writeToLog("moveFilesInES") if self.verbose: print "Using moveFilesInES" status = self.error okList = [] compList = [] for file in fileInList: if os.path.isfile(file): status, query, cQuery = self.moveFileInES(file,fileOut) if status == self.error: print "############" print "Fail to move %s %s"%(file,fileOut) print "##############################################" print "List of successfull queries:" for item in okList: print item print "##############################################" print "List of compensating queries:" for item in compList: print item print "##############################################" print "MAKE YOUR DECISION. Either invoke compensating" print "queries or proceed." break okList.append(query) compList.append(cQuery) return status
# Author: Valentin Kuznetsov, 2004 # """Make a skim file out of input PDS and IDXA files""" import os, sys, string, array import idxa_reader, pds_dump, file_util if __name__ == "__main__": usage = "\nUsage: makeSkim pdsFileName idxaFileName" usage += "\n Examples: makeSkim my.pds my.idxa" usage += "\n will produce my_skim.pds file" if len(sys.argv) != 3: print usage sys.exit(1) pdsFile = sys.argv[1] if file_util.fileType(pdsFile) != "pds": print "File %s is not a PDS file" % pdsFile print usage sys.exit(1) idxaFile = sys.argv[2] if file_util.fileType(idxaFile) != "idxa": print "File %s is not a IDXA file" % idxaFile print usage sys.exit(1) skimName = string.split(pdsFile, ".")[0] + "_skim.pds" fileDesc = open(skimName, 'w+b') pdsHeader = pds_dump.getPDSHeader(pdsFile) pdsHeader.tofile(fileDesc) # parse IDXA file and loop over its syncValues idxaReader = idxa_reader.IDXAFileReader(idxaFile)
"""IDXA file maker from provided REST file""" import os, sys, string, array import idxa_reader, hddm_r_dump, file_util if __name__ == "__main__": usage = "\nUsage: make_REST_IDXA hddmFileName <idxaFileName>" usage+= "\n Examples: make_REST_IDXA my.hddm" usage+= "\n will produce my.idxa file" usage+= "\n Examples: make_REST_IDXA my.hddm o.idxa" if len(sys.argv)==1: print usage sys.exit(1) hddmFile = sys.argv[1] #if file_util.fileType(hddmFile)!="hddm": print "FILE TYPE = %s" % (file_util.fileType(hddmFile)) #if file_util.fileType(hddmFile)!="rest": if file_util.fileType(hddmFile)!="hddm": print "File %s is not a HDDM file"%hddmFile print usage sys.exit(1) if len(sys.argv)==3: idxaFile = sys.argv[2] if file_util.fileType(idxaFile)!="idxa": print "File %s is not a IDXA file"%idxaFile print usage sys.exit(1) else: idxaFile = string.split(hddmFile,".")[0]+".idxa" hddmReader= hddm_r_dump.HDDMFileReader(hddmFile)
"""IDXA file maker from provided REST file""" import os, sys, string, array import idxa_reader, evio_dump, file_util if __name__ == "__main__": usage = "\nUsage: make_evio_IDXA evioFileName <idxaFileName>" usage += "\n Examples: make_evio_IDXA my.evio" usage += "\n will produce my.idxa file" usage += "\n Examples: make_evio_IDXA my.evio o.idxa" if len(sys.argv) == 1: print usage sys.exit(1) evioFile = sys.argv[1] #print "FILE TYPE = %s" % (file_util.fileType(evioFile)) if file_util.fileType(evioFile) != "evio": print "File %s is not a EVIO file" % evioFile print usage sys.exit(1) if len(sys.argv) == 3: idxaFile = sys.argv[2] #if file_util.fileType(idxaFile)!="idxa": # print "File %s is not a IDXA file"%idxaFile # print usage # sys.exit(1) else: idxaFile = string.split(evioFile, ".")[0] + ".idxa" evioReader = evio_dump.EVIOFileReader(evioFile) header = ['IDXA']
# Author: Valentin Kuznetsov, 2004 # """Make a skim file out of input PDS and IDXA files""" import os, sys, string, array import idxa_reader, pds_dump, file_util if __name__ == "__main__": usage = "\nUsage: makeSkim pdsFileName idxaFileName" usage+= "\n Examples: makeSkim my.pds my.idxa" usage+= "\n will produce my_skim.pds file" if len(sys.argv)!=3: print usage sys.exit(1) pdsFile = sys.argv[1] if file_util.fileType(pdsFile)!="pds": print "File %s is not a PDS file"%pdsFile print usage sys.exit(1) idxaFile = sys.argv[2] if file_util.fileType(idxaFile)!="idxa": print "File %s is not a IDXA file"%idxaFile print usage sys.exit(1) skimName = string.split(pdsFile,".")[0]+"_skim.pds" fileDesc = open(skimName,'w+b') pdsHeader = pds_dump.getPDSHeader(pdsFile) pdsHeader.tofile(fileDesc) # parse IDXA file and loop over its syncValues idxaReader= idxa_reader.IDXAFileReader(idxaFile)
"""IDXA file maker from provided REST file""" import os, sys, string, array import idxa_reader, evio_dump, file_util if __name__ == "__main__": usage = "\nUsage: make_evio_IDXA evioFileName <idxaFileName>" usage+= "\n Examples: make_evio_IDXA my.evio" usage+= "\n will produce my.idxa file" usage+= "\n Examples: make_evio_IDXA my.evio o.idxa" if len(sys.argv)==1: print usage sys.exit(1) evioFile = sys.argv[1] #print "FILE TYPE = %s" % (file_util.fileType(evioFile)) if file_util.fileType(evioFile)!="evio": print "File %s is not a EVIO file"%evioFile print usage sys.exit(1) if len(sys.argv)==3: idxaFile = sys.argv[2] #if file_util.fileType(idxaFile)!="idxa": # print "File %s is not a IDXA file"%idxaFile # print usage # sys.exit(1) else: idxaFile = string.split(evioFile,".")[0]+".idxa" evioReader= evio_dump.EVIOFileReader(evioFile) header = ['IDXA']