def copyApk(self): log.log_print("copy Apk") if self.Apk: self.copyBaseApk = fileutils.copyFile( self.Apk, constrant.TMP_ROOT_DIR + os.sep + constrant.TMP_COPY_APK) else: self.copyBaseApk = fileutils.copyFile( self.filelist[0], constrant.TMP_ROOT_DIR + os.sep + constrant.TMP_COPY_APK)
def procBuRegFile(self): butn = len(self.procBuReg) if butn > 1: self.log.warn('BU_REGION ctl file records are %d. Should be one file only !' % butn) btfs = self.procBuReg.keys() btfs.sort() self.log.debug('Bu region files = ' , btfs) fn = self.ib.srcFile[0] t = '%s/%s' % (self.ib.workDir,fn) fnp = '%s/%s' % (self.ib.landDir,fn) cl = self.procBuReg[fn] rc = self._chkDataRecCnt(fnp,cl) if rc != 0 : return rc rc = fu.copyFile(fnp, t) if rc != 0 : self.log.error('Could not copy File %s to %s' % (fnp,t)) return 5 # Archive the file rc = self.archGenFiles([fnp,], self.ts) self.log.info ('Archiving file rc = %s' % rc) return 0
def procCustFiles(self): tgtFiles = [] fnl = self.ib.custFileName.split(",") for fnp in fnl: fs = self.checkIncFiles(fnp) if len(fs) == 1: fnOff = len("_YYYYMMDD.csv") self.log.info("Processing %s " % fs[0]) fn = fu.getFileBaseName(fs[0]) d = "%s/%s" % (self.ib.archDir, fn) rc = fu.copyFile(fs[0], d) self.log.info("Archiving %s to %s\trc=%s" % (fs[0], d, rc)) d = "%s/%s.csv" % (self.ib.workDir, fn[:-fnOff]) rc = fu.moveFile(fs[0], d) self.log.info("Moving %s to %s\trc=%s" % (fs[0], d, rc)) tgtFiles.append(d) else: fnOff = len("_*[0-9].csv") fn = fu.getFileBaseName(fnp) d = "%s/%s.csv" % (self.ib.workDir, fn[:-fnOff]) self.log.debug("fn = %s, dest = %s" % (fn, d)) self.log.warn("File %s was not found" % fnp) rc = fu.crtEmpFile(d) self.log.info("Creating 0 byte file %s\trc=%s" % (d, rc)) # Verify Column Numbers: if self.checkFileColsFlag is True: rc = self.checkFileCols(tgtFiles, ",") if rc != 0: self.log.error("Issue with column number. PLease check bad directory under %s" % self.ib.badDir) # Implement email notification. # return rc return 0
def procHierSCOS(self): # Check for file existence src = '%s/%s/%s' % (self.ib.shareDir,self.outDir,self.ib.outFile) r = fu.fileExists(src) if r == False : self.log.error('File %s does not exist' % src) return 1 # Move File to output dir dt = su.getTodayDtStr('%y%m%d') self.outFile = 'SCS_Org_Hierarchy%s.csv' % dt outFile = '%s/%s/%s/%s' % (self.ib.shareDir,self.outDir,self.ib.outDirname,self.outFile) r = fu.moveFile(src,outFile) if r != 0 : self.log.error("Could not move %s to %s " % (src,outFile)) self.log.debug('Moved src = %s to self.outFile = %s RC = %s' % (src,outFile,r)) # Archive File . arcfn = '%s/%s/%s/%s-%s' % (self.ib.shareDir,self.outDir,self.outArchDir,self.ts,self.outFile) r = fu.copyFile(outFile,arcfn) if r != 0 : self.log.error("Could not copy %s to %s " % (outFile,arcfn)) self.log.debug('Copied src = %s to racfn = %s RC = %s' % (outFile,arcfn,r)) return 0
def cpFileToWorkDir(self): self.workFiles = [] for src in self.incFiles: fn = fu.getFileBaseName(src) d = '%s/%s' % (self.ib.workDir, fn) rc = fu.copyFile(src, d) if rc == 0 : self.workFiles.append(d) self.log.info('Copying file %s to %s rc= %s' % (src, d, rc)) if len(self.workFiles) < 1 : return 1 else : return 0
def cpSrcToTgtFiles(self): self.workFiles = [] srcLen = len(self.srcFile) incLen = len(self.incFiles) if srcLen != incLen: self.log.error('srcFiles len = %d Does not match IncFiles len %d' % (srcLen,incLen)) self.log.debug('srcFiles = ',self.srcFile, '\tincFiles = ', self.incFiles) return 1 for i in range (srcLen): #fn = self.incFiles[i] d = '%s/%s' % (self.ib.workDir, self.srcFile[i]) rc = fu.copyFile(self.incFiles[i], d) if rc == 0 : self.workFiles.append(d) self.log.info('Copying file %s to %s rc= %s' % (self.incFiles[i], d, rc)) if len(self.workFiles) < 1 : return 2 else : return 0
def cpFileToWorkDir(self): fnp = '%s' % self.incFiles[0] t = '%s/%s' % (self.ib.workDir,self.srcFile) rc = fu.copyFile(fnp, t) return rc
def procCortFiles(self): dataFile = [] ctlFile = '%s/%s.ctl' % (self.ib.ctlDir,self.appName) setn = len (self.procCort) self.log.info( ' ---- Starting Processing. Total of %d iteration(s) ----' % setn) fileset = self.procCort.keys() fileset.sort() self.log.debug('Process Order = ' , fileset) for fn in fileset: f = '%s/%s' % (self.ib.landDir,fn) if not fu.fileExists(f): self.log.error('File %s have not been downloaded!' % f) return 1 # Processing loop. for fn in fileset: self.log.info( 'Processing file %s/%s ' % (self.ib.landDir,fn)) cur_dayr = self._getDateRunStr(fn) if cur_dayr is None : self.log.error('cur_dayr is None. No Date Run String ') return 2 # cur_dayr = YYYYMMDD from filename . eg. Cortera_Trx_Extract_20130502.txt # pdate format YYYY-MM-DD pdate = '%s-%s-%s' % (cur_dayr[:4],cur_dayr[4:6],cur_dayr[6:8]) self.log.debug('cur_dayr = %s pdate = %s' % (cur_dayr,pdate)) rc = su.isValidDate(pdate,'%Y-%m-%d') if rc is False : self.log.error('Invalid Date %s on file %s ' % (pdate,fn)) return 2 self.log.debug('self.checkNextRunFlg is %s' % self.checkNextRunFlg) if self.checkNextRunFlg is True: prev_dayr = self._getCtlFile() pd,pr = self._getDay(prev_dayr,DP_LEN) rc = self._chkNextRun(cur_dayr,prev_dayr,pd,pr,RUN_PER_DAY) if rc != 0 : self.log.error("self._chkNextRun rc = %s" % rc) return rc # Cortera t = '%s/%s' % (self.ib.workDir,self.ib.srcFile[1]) fnp = '%s/%s' % (self.ib.landDir,fn) cl = self.procCort[fn] rc = self._chkDataRecCnt(fnp,cl) if rc != 0 : return rc rc = fu.copyFile(fnp, t) if rc != 0 : self.log.error('Could not copy File %s to %s' % (fnp,t)) return 5 self.log.info ('Copying File from %s to %s' % (fnp,t)) rc = self.archGenFiles([fnp,], self.ts) self.log.info ('Archiving file rc = %s' % rc) # Invoke workflow. rc = pi.runWkflWait(self.ib,self.log) if rc != 0 : self.log.error('Running %s.%s rc = %s' % (self.ib.fld,self.ib.wkf,rc)) if self.exitOnError: self.log.debug('ExitOnError is TRUE rc = %s' % (rc)) return rc else : self.log.info('Ran %s.%s rc = %s' % (self.ib.fld,self.ib.wkf,rc)) # Update Control table in Netezza with date. rc = self._updLeaseCrdTbl(pdate) if rc != 0 : self.log.error('No rows were updated for process date %s' % pdate) return rc # Loading Staging Succeeded. Update the control file. rc = fu.updFile(ctlFile,cur_dayr) if rc == 0 : if self.checkNextRunFlg: self.log.info('Updated Cur Load Date from %s to %s , Control File %s' % (prev_dayr,cur_dayr, ctlFile)) else : self.log.info('Overwriting Cur Load Date to %s , Control File %s' % (cur_dayr, ctlFile)) else : self.log.error('Could not Update Load Date %s, Control File %s rc = %s' % (cur_dayr,ctlFile,rc)) return rc r = fu.delFile(t) self.log.info('Removing %s rc = %s ' % (t,r)) # Delete BU Region. fnp = '%s/%s' % (self.ib.workDir,self.ib.srcFile[0]) # BU_region rc = fu.delFile(fnp) self.log.info('Removing %s rc = %s ' % (fnp,rc)) return rc