def scanForData(self): self.data = [] files = [_f for _f in os.listdir(self.incoming) if _f[:7] == 'AgnMail'] if len(files) > 0: data = [] finals = [] db = agn.DBase() if db is None: agn.log(agn.LV_ERROR, 'scan', 'Unable to get database instance') return 0 inst = db.cursor() if inst is None: db.close() agn.log(agn.LV_ERROR, 'scan', 'Unable to get database cursor') return 0 deleted = {} for fname in files: block = Block(self.incoming + os.sep + fname) if not deleted.has_key(block.mailingID): r = inst.querys( 'SELECT deleted FROM mailing_tbl WHERE mailing_id = %d' % block.mailingID) if not r is None: deleted[block.mailingID] = r[0] if deleted.has_key(block.mailingID): if deleted[block.mailingID] != 0: block.moveTo(agn.mkArchiveDirectory(self.deleted)) else: if block.isdata and block.stamp in files: data.append(block) elif block.isfinal: finals.append(block) inst.close() db.close() now = time.localtime() ts = 'D%04d%02d%02d%02d%02d%02d' % now[:6] for block in data: for final in finals: if final.isFinalFor(block): final.finalcount += 1 if block.readyToSend(ts): self.data.append(block) break for final in finals: if final.finalcount == 0: final.moveTo(agn.mkArchiveDirectory(self.archive)) self.data.sort() return len(self.data)
def scanForData(self): self.data = [] files = [_f for _f in os.listdir(self.incoming) if _f[:7] == "AgnMail"] if len(files) > 0: data = [] finals = [] db = agn.DBase() if db is None: agn.log(agn.LV_ERROR, "scan", "Unable to get database instance") return 0 inst = db.cursor() if inst is None: db.close() agn.log(agn.LV_ERROR, "scan", "Unable to get database cursor") return 0 deleted = {} for fname in files: block = Block(self.incoming + os.sep + fname) if not deleted.has_key(block.mailingID): r = inst.querys("SELECT deleted FROM mailing_tbl WHERE mailing_id = %d" % block.mailingID) if not r is None: deleted[block.mailingID] = r[0] if deleted.has_key(block.mailingID): if deleted[block.mailingID] != 0: block.moveTo(agn.mkArchiveDirectory(self.deleted)) else: if block.isdata and block.stamp in files: data.append(block) elif block.isfinal: finals.append(block) inst.close() db.close() now = time.localtime() ts = "D%04d%02d%02d%02d%02d%02d" % now[:6] for block in data: for final in finals: if final.isFinalFor(block): final.finalcount += 1 if block.readyToSend(ts): self.data.append(block) break for final in finals: if final.finalcount == 0: final.moveTo(agn.mkArchiveDirectory(self.archive)) self.data.sort() return len(self.data)
def doit (self, basename): (src, stamp, final) = [agn.mkpath (self.incoming, '%s.%s' % (basename, _e)) for _e in 'xml.gz', 'stamp', 'final'] if os.path.isfile (src): target = self.recover ok = True for path in stamp, final: if os.path.isfile (path): try: os.unlink (path) except OSError, e: agn.log (agn.LV_ERROR, 'doit', 'Failed to remove %s: %s' % (path, str (e))) ok = False else: agn.log (agn.LV_ERROR, 'doit', 'Failed to find file %s' % path) ok = False if ok: queue = self.__nextQueue () if self.mta (src, targetDirectory = queue, flushCount = '2'): agn.log (agn.LV_INFO, 'doit', 'Unpacked %s in %s' % (src, queue)) try: target = agn.mkArchiveDirectory (self.archive) except agn.error as e: agn.log (agn.LV_ERROR, 'unpack', 'Failed to setup archive directory %s: %s' % (self.archive, e)) target = self.archive else: agn.log (agn.LV_ERROR, 'doit', 'Failed to unpack %s in %s' % (src, queue)) target = self.recover else: agn.log (agn.LV_INFO, 'doit', 'Do not process %s as control file(s) is/are missing' % src) dst = agn.mkpath (target, os.path.basename (src)) try: shutil.move (src, dst) except (shutil.Error, IOError, OSError), e: agn.log (agn.LV_ERROR, 'doit', 'Failed to move %s to %s: %s' % (src, dst, str (e))) try: os.unlink (src) except OSError, e: agn.log (agn.LV_ERROR, 'doit', 'Failed to remove file %s: %s' % (src, str (e)))
pd = Pickdist() while not term: time.sleep(1) agn.mark(agn.LV_INFO, "loop", 180) if pd.scanForData() == 0: delay = 30 agn.log(agn.LV_VERBOSE, "loop", "No ready to send data file found") else: delay = 0 while not term and pd.hasData(): queue = pd.queueIsFree() if queue is None: agn.log(agn.LV_INFO, "loop", "Queue is already filled up") delay = 180 break blk = pd.getNextBlock() if blk.unpack(queue): blk.moveTo(agn.mkArchiveDirectory(pd.archive)) else: blk.moveTo(pd.recover) while not term and delay > 0: if agn.iswin and agn.winstop(): term = True break time.sleep(1) delay -= 1 # agn.log(agn.LV_INFO, "main", "Going down") agn.unlock()
pd = Pickdist() while not term: time.sleep(1) agn.mark(agn.LV_INFO, 'loop', 180) if pd.scanForData() == 0: delay = 30 agn.log(agn.LV_VERBOSE, 'loop', 'No ready to send data file found') else: delay = 0 while not term and pd.hasData(): queue = pd.queueIsFree() if queue is None: agn.log(agn.LV_INFO, 'loop', 'Queue is already filled up') delay = 180 break blk = pd.getNextBlock() if blk.unpack(queue): blk.moveTo(agn.mkArchiveDirectory(pd.archive)) else: blk.moveTo(pd.recover) while not term and delay > 0: if agn.iswin and agn.winstop(): term = True break time.sleep(1) delay -= 1 # agn.log(agn.LV_INFO, 'main', 'Going down') agn.unlock()