示例#1
0
    def _chkIfValidLock(self):

        rc = True
        # Check if there is a lock file.
        if fu.fileExists(self.lckFn):
            sPid = fu.readFile(self.lckFn)
            pid = su.toInt(sPid)
            self.log.info('Lock File  %s EXISTS. sPid = %s , pid = %s' %
                          (self.lckFn, sPid, pid))
            # Check if file has a valid PID (number)
            if pid is None:
                rc = fu.delFile(self.lckFn)
                if rc == 0:
                    self.log.info('Removed File  %s' % (self.lckFn))
                else:
                    self.log.error('Could not removed File  %s' % (self.lckFn))
                return False

            # If pid is a valid number, check if the process is running ...
            rc = ps.isProcRunning(pid, self.log)
            self.log.debug('isProcRunning returned %s' % (rc))
            return rc

        # No lock file exists.
        else:
            return False
示例#2
0
def parseCanCPI(fn):
    data = fu.readFile(fn)
    if data is None or data is '' : return []

    soup = BeautifulSoup(data)
    table = soup.find("table", { "class" : "table table-bordered table-striped table-hover cpi" })
    rows = table.findChildren(['tr'])
    return _parseCanCPITable(rows)
示例#3
0
 def getStateFile(self):
     fn = '%s/%s.state' % (self.ib.ctlDir, self.appName)
     if fu.fileExists(fn) is False:
         self.log.error('State File:%s does not exist' % fn)
         return None
     
     self.log.info('Reading State File :%s' % fn)
     return fu.readFile(fn).strip()
示例#4
0
 def _getCtlFile(self):
     fn = '%s/%s.ctl' % (self.ib.ctlDir, self.appName)
     if fu.fileExists(fn) is False:
         self.log.error('Control File:%s does not exist' % fn)
         return None
     
     self.log.info('Loading Control File:%s' % fn)
     return fu.readFile(fn).strip()
示例#5
0
def getIORateTrans(fnp):
    real =[]; usr = []; syst=[]
     
    data = fu.readFile(fnp)
    if len(data) < 5 : return 1
    lines = data.split('\n')
    i = 0 
    for l in lines:
        i+=1
        if l.strip() == '' : continue
        if   l.startswith('real'): 
                print 'real %s'  % l[5:].strip()
                n = su.convToSecs(l[5:].strip())
                if n is None : print "Error invalid int on line %d " % i
                else         : real.append(n)
        elif l.startswith('user'): 
                print 'user %s'  % l[5:].strip()
                n = su.convToSecs(l[5:].strip())
                if n is None : print "Error invalid int on line %d " % i
                else         : usr.append(n)
示例#6
0
    def verTrigFileDate(self):
        global RUN_DATE
        rc = 0
        
        rdayoffset = su.toInt(self.ib.rdayoffset)
        if rdayoffset is None or rdayoffset < 0:
            self.log.error('rdayoffset needs to be a number => 0. Current Value = %s' % self.ib.rdayoffset)
            
        if rdayoffset != 0 :
            RUN_DATE = su.getDayMinusStr(rdayoffset, RUN_DATE, '%Y%m%d')

        for fn in self.trigFiles:
            fdt = fu.readFile(fn).strip(' \t\n\r')
            self.log.debug('fn = %s fdt = %s RUN_DATE=%s rdayoffset = %s ' % (fn,fdt,RUN_DATE, rdayoffset))
            if fdt != RUN_DATE:
                self.log.error("%s date field %s does not match the process RUN_DATE %s." % (fn,fdt,RUN_DATE))
                rc = 1
            else :
                self.log.info("%s date field %s matches the process RUN_DATE %s." % (fn,fdt,RUN_DATE))
        return rc
示例#7
0
    def _chkHeader(self,fnp,rdoff):
        RUN_DATE = su.getTodayDtStr(fmt='%y%m%d')
        rdayoffset = su.toInt(rdoff)
        
        hdr   = fu.readFile(fnp)
        
        if len(hdr) != 14 :
            self.log.error('Invalid len= %d  for %s. Need to be 14\nhdr=%s' % (len(hdr),fnp,hdr))
            return 1
            
        rowc     = su.toInt(hdr[0:8])
        hdr_date = hdr[8:]                  # Run Date from file.
          
        dt = su.getDayMinusStr(rdayoffset, RUN_DATE, '%Y%m%d')

        # Check run date.
        if dt != hdr_date:
            self.log.warn('fn %s === \tInvalid Header ran date of %s. Should be %s  ' % (fnp,dt,hdr_date))
        
        if rdayoffset < 1 : 
            self.log.error('Could not attempt next day since rdayoffset is %s < 1' % rdayoffset)
            return 2
            
        dt = su.getDayMinusStr(rdayoffset - 1, RUN_DATE, '%Y%m%d')
        # Check run date + 1.
        if dt != hdr_date:
            self.log.error('fn %s === \tInvalid Header ran date of %s. Should be %s  ' % (fnp,dt,hdr_date))
            return 3
        
        # Check Number of lines 
        ln  = fu.getLines(fnp)      # Number of lines w/o trailer.
        dc =  int(ln) - rowc        # ln file has 2 extra lines header/trailer, but at this point trailer rec had been removed.
        self.log.debug('fn %s === \tFile record count %s trailer = %s diff %s' % (fnp,ln,rowc,dc))
        if  dc != 0 :
            self.log.error('fn %s === \tFile record count %s do not match trailer = %s # of records diff = %d!' % (fnp,ln,rowc,dc))
            return 4
        
        return 0
示例#8
0
    def splitMainCntFile(self):
        #Get Header.
        fnp = '%s/%s' % (self.ib.workDir,self.srcFile)
        s   = fu.readFile(fnp)
        hdr = su.remSpacefrStr(s)
        if len(hdr) != 38 :
            self.log.error('Invalid len= %d  for %s. Need to be 38\nhdr=%s' % (len(hdr),fnp,hdr))
            return 1
    
        self.log.debug('hdr = %s' % hdr)
        
        # Get counts 
        po870D30 = su.toInt(hdr[0:8])
        po875D30 = su.toInt(hdr[8:16])
        po880D30 = su.toInt(hdr[16:24])
        po225D15 = su.toInt(hdr[24:32])
        rdate    = hdr[32:]
        
        self.log.debug('po870D30=%s po875D30=%s po880D30=%s po225D15=%s rdate=%s' % (po870D30, po875D30,po880D30,po225D15,rdate))
        
        # Sanity check.
        if  (po870D30 is None or po875D30 is None or po880D30 is None or po225D15 is None or su.isValidDate(rdate,'%m%d%y') == False) :
            self.log.error('po870D30=%s po875D30=%s po880D30=%s po225D15=%s rdate=%s' % (po870D30, po875D30,po880D30,po225D15,rdate))
            return 2
        
        # Create count files.
        rc = 0 
        r = fu.createFile('%s/po870d30comp.cnt' % self.ib.workDir, '%08d%s' % (po870D30,rdate))  ; rc+= r
        self.log.info (' Creating file %s/po870d30comp.cnt rc = %s' % (self.ib.workDir, r))
        r = fu.createFile('%s/po875D30.cnt' % self.ib.workDir, '%08d%s' % (po875D30,rdate))  ; rc+= r
        self.log.info (' Creating file %s/po875d30.cnt rc = %s' % (self.ib.workDir, r))
        r = fu.createFile('%s/po880D30.cnt' % self.ib.workDir, '%08d%s' % (po880D30,rdate))  ; rc+= r
        self.log.info (' Creating file %s/po880d30.cnt rc = %s' % (self.ib.workDir, r))
        r = fu.createFile('%s/po225D15.cnt' % self.ib.workDir, '%08d%s' % (po225D15,rdate))  ; rc+= r
        self.log.info (' Creating file %s/po225d15.cnt rc = %s' % (self.ib.workDir, r))

        return rc 
示例#9
0
 def _chkIfValidLock(self):
     
     rc = True
     # Check if there is a lock file.
     if  fu.fileExists(self.lckFn):
         sPid = fu.readFile(self.lckFn)
         pid = su.toInt(sPid)
         self.log.info('Lock File  %s EXISTS. sPid = %s , pid = %s' % (self.lckFn,sPid,pid))
         # Check if file has a valid PID (number)
         if pid is None : 
             rc = fu.delFile(self.lckFn)      
             if rc == 0 : 
                 self.log.info('Removed File  %s' % (self.lckFn))
             else:
                 self.log.error('Could not removed File  %s' % (self.lckFn))
             return False
         
         # If pid is a valid number, check if the process is running ...
         rc = ps.isProcRunning(pid,self.log)
         self.log.debug('isProcRunning returned %s' % (rc))
         return rc
     
     # No lock file exists.
     else: return False