lsbmu
ΒΆ
A script to compute diff between two bmu files.
#!/usr/bin/env python
''' A script to compute diff between two bmu files.
'''
import os
import sys
import logging
logging.basicConfig()
logger = logging.getLogger("diffbmu")
from optparse import OptionParser
import datetime
import Sadppac
from irfpy.util import utc
def lsbmu(file, **kwds):
'''
'''
loader = kwds.get('loader', 'CENA')
logger.debug("Loader = %s" % loader)
fullmd5 = kwds.get('fullmd5', False)
if fullmd5:
col = -1
else:
col = 10
logger.debug('file = %s' % file)
if loader == "CENA":
reader1 = Sadppac.CenaBmuReader()
elif loader == "SWIM":
reader1 = Sadppac.SwimBmuReader()
else:
raise RuntimeError("Loader %s not supported." % (loader))
# Read data
reader1.readFile(file)
packets1 = reader1.getArray()
npac1 = packets1.size()
logger.debug('Number of packet: %d' % (npac1))
print('# File: %s' % file)
print('# Npacket: %d' % npac1)
# You cannot assume ascending or descending array order.
pacArr1 = [packets1.getPacket(i) for i in range(npac1)]
for pac in pacArr1:
showpac(pac, colmd5=col)
return pacArr1
def showpac(pac, **kwds):
colmd5 = kwds.get('colmd5', 10)
print(' ' * 5, end=' ') # Indent
print('%4d ' % pac.getPacketCounter(), end=' ')
t = utc.convert(pac.getUtc(), datetime.datetime)
print('%s.%06d ' % (t.strftime('%FT%T'), t.microsecond), end=' ')
h = pac.hash() + ' '
print('%s' % (h[:colmd5]), end=' ')
print('%7d ' % pac.getSize(), end=' ')
print('')
def main(*argv, **kwds):
usage = "Usage: %prog [options] bmufile1.bmu"
parser = OptionParser(usage)
parser.add_option("-v", action="store_true", dest="verbose",
default=False, help="Verbose mode")
parser.add_option("-s", action="store_true", dest="useswim",
default=False, help="Use SWIM BMU loader (default CENA)")
parser.add_option("-f", action="store_true", dest="fullmd5",
default=False, help="Show full md5 value.")
(options, args) = parser.parse_args(*argv[1:])
if options.verbose:
logger.setLevel(logging.DEBUG)
logger.debug("Set verbose mode")
loader="CENA"
if options.useswim:
loader="SWIM"
logger.debug("Loader = %s" % loader)
for f in args:
lsbmu(f, loader=loader, fullmd5=options.fullmd5)
if __name__ == '__main__':
main(sys.argv)