def _handle(self, *args, **options): pcap_dir = args[0] pcaps = os.listdir(pcap_dir) for pcap_file in pcaps: print "current file: ", pcap_dir+ pcap_file pcap = PacketReader(pcap_dir+pcap_file) for packet in pcap: p = Packet(**packet) p.save() transaction.commit()
def _handle(self, *args, **options): pcap_file = args[0] print 'Parsing %s' %pcap_file pcap = PacketReader(pcap_file) try: for packet in pcap: p = Packet(**packet) p.save() transaction.commit() print '%s parsed successfully.' %pcap_file except IntegrityError: transaction.rollback() sys.stderr.write('ERROR: %s was already parsed.\n' %pcap_file) finally: print