Exemplo n.º 1
0
 def _checkHeader(self,fnp):
     rc  = 0 
     ln  =-1; rowc=-1; dc = -1 ;idx=-5
     tok = 'Records:'           
     
     try:
         # Check header count 
         fname  = fu.getFileLine(fnp,1).strip()
         rowchr = fu.getFileLine(fnp,2).strip()
         self.log.debug('fname = %s rowchr = %s' % (fname,rowchr))
         
         #Check filename (base Filenamme)
         
         idx    = string.find(rowchr,tok)
         if idx == -1 : 
             self.log.error('Token "%s" not found in file %s ' % (tok,fname))
             rc = idx
             return rc
         rowc   = rowchr[idx + len(tok):]
          
         # Check Number of lines 
         ln  = fu.getLines(fnp)            
         dc =  int(ln) - int(rowc) - _TalentMapFile.FILE_OFFSET_ROW          # ln file has 4 extra lines header
             
         if  dc != 0 :
                 self.log.error('fn %s === \tFile record count %s do not match header = %s # of records diff = %d!' % (fnp,ln,rowc,dc))
                 rc = 1
        
     except:
         self.log.error("EXCEP %s %s "  % (sys.exc_type, sys.exc_info()[1]))
         rc = 2
         
     finally : 
         self.log.debug("fnp = %s rowchr = %s rowc = %s ln = %s dc = %s idx= %s" % (fnp,rowchr,rowc,ln,dc,idx))
         return rc
Exemplo n.º 2
0
 def _chkDataRecCnt(self,fnp,cl):
     
     tl = fu.getLines(fnp)
     rc = tl - cl
     if rc != 0 :
         self.log.error('Count on File = %d Count on Ctl File = %d Does not match diff = %d' % (tl,cl,rc))        
     return rc
Exemplo n.º 3
0
    def _checkTrailer(self,fnp,fn,fdr):
        self.log.info("Filename : %s " %  fnp)
        fd = -1; ln =-1; tr=-1; date=-1;rowc=-1; dt=-1; lc=-1
        self.log.debug('fnp=%s fn=%s fdr=%s' % (fnp,fn,fdr))
        try:
            # Check if valid Date & truncate last line (trailer Line)
#            tr         = fu.getLastLine(fnp,1).rstrip()     # Trailer Line
#            dt, rowc = tr[:8],int(tr[8:])
#            date = '%s/%s/%s' % (dt[4:6],dt[6:8],dt[:4])
#            if su.isValidDate(date,'%m/%d/%Y') is False : 
#                self.log.error('fn %s === \tInvalid date %s!' % (fnp,date))
#                return 1
#              
#            fd  = fdr[:8]
#            if dt != fd :
#                self.log.error('fn %s === \tFile Date = %s do not match trailer = %s!' % (fnp,fd,dt))
#                return 2            
            
            # Dly
            if len(fdr) > 6 : 
                rowc = self._chkDlyTrailer(fnp,fdr)
                if rowc < 0 :
                    self.log.debug('_chkDlyTrailer : rowc = %s !' % (rowc))       
                    return 1
            # Mthly
            else:
                rowc = self._chkMthlyTrailer(fnp,fdr)
                if rowc < 0 :
                    self.log.debug('__chkMthlyTrailer : rowc = %s !' % (rowc))       
                    return 1
                
            # Check Number of lines 
            ln  = fu.getLines(fnp)
            dc =  int(ln) - int(rowc)             # ln file has 2 extra lines header/trailer, but at this point trailer rec had been removed.
            lc = int(ln) - 1
            if  dc != 1 :
                self.log.error('fn %s === \tFile record count %s do not match trailer = %s # of records diff = %d!' % (fnp,rowc,lc,dc-1))
                return 3
            
            f = self._getFileProcName(fn)
            if f in self.srcCount:
                self.srcCount[f] = lc
                self.log.info('file  %s\tLineCnt = %d ' % (fn,lc))
            else:
                self.log.error("UNKNOWN KEY %s" % f)  # Should never get this Error !
                return 4
            
            return 0
        
        # Invalid datatypes fields for verification process !!
        except:            
            self.log.error(' ==EXCEP %s ' % (sys.exc_info()[1]))
            return 5
        
        finally:
            self.log.debug('fn = %s == date %s\t lines %s' % (fnp,fd,ln))
            self.log.debug('trl= %s == date %s\t lines %s' % (tr,dt,rowc))
Exemplo n.º 4
0
 def _checkTrailer(self,fnp,trl_date):
     self.log.info("Filename : %s " %  fnp)
     fd = -1; ln =-1; tr=-1; rowc=-1; dt=-1; lc=-1;tok = []
     try:
         # Check if valid Date & truncate last line (trailer Line)
         tr         = fu.getLastLine(fnp,1).rstrip()     # Trailer Line
         tok        = tr.split()
         self.log.debug('Last line = ', tr , ' tokens ', tok)
         if len(tok) != 4 :
             self.log.error('filename %s === \tInvalid Number of tokens.It has %d need to be 4 !' % (fnp,len(tok)))
             return 1
         
         if tok[0] != 'TRAILER':
             self.log.error('filename %s === \tInvalid TRAILER LINE.It need to start with TRAILER insted of !' % (fnp,tok[0]))
             return 2
         
         dt = tok[1]
         if su.isValidDate(dt,'%Y%m%d') is False : 
             self.log.error('fn %s === \tInvalid date %s!' % (fnp,dt))
             return 3
         
         rowc = su.toInt(tok[3])
         if rowc is None:
             self.log.error('fn %s === \tInvalid row count %s!' % (fnp,tok[3]))
             return 4
         
         if dt != trl_date:
             self.log.error('fn %s === \tInvalid Trailer ran date of %s. Should be %s  ' % (fnp,dt,trl_date))
             return 5
                 
         # 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 6
         
         return 0
     
     # Invalid datatypes fields for verification process !!
     except:            
         self.log.error(' ==EXCEP %s ' % (sys.exc_info()[1]))
         return 5
     
     finally:
         self.log.debug('fn  %s == date %s\t lines %s' % (fnp,fd,ln))
         self.log.debug('trl %s == date %s\t lines %s' % (tr,dt,rowc))
Exemplo n.º 5
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