diff --git a/refscrub/refscrub.py b/refscrub/refscrub.py index 9a1da488f3b5285957d2250bda78390e02a0786a..a05d4ea1d6271f76414943ba124c0f3d8cea9dc5 100644 --- a/refscrub/refscrub.py +++ b/refscrub/refscrub.py @@ -13,13 +13,22 @@ August 2018 Updates to work on both Python 2 & 3. Code cleanup to match PEP 8. Cleanup global vars. + +Maeva Pourpoint +August 2020 +Updates to work under Python 3. +Unit tests to ensure basic functionality. +Code cleanup to conform to the PEP8 style guide. +Directory cleanup (remove unused files introduced by Cookiecutter). +Packaged with conda. """ -import sys + import argparse import struct +import sys from os.path import basename, getsize, isfile -PROG_VERSION = '2018.228' +PROG_VERSION = '2020.216' VERBOSE = False EXTRACT = False SUMMARY_FILE = 'scrubsum.txt' @@ -74,9 +83,11 @@ class SNseen(dict): class RTPacket: RTstruct = struct.Struct('2c1B1B2B6B2B2B') - # Define the packet types as byte literals, since that is what the above structure will cause the type field - # do be decoded as. Without this, they will not match below. - packet_types = (b'AD', b'CD', b'DS', b'DT', b'EH', b'ET', b'OM', b'SH', b'SC') + # Define the packet types as byte literals, since that is what the above + # structure will cause the type field do be decoded as. Without this, they + # will not match below. + packet_types = (b'AD', b'CD', b'DS', b'DT', + b'EH', b'ET', b'OM', b'SH', b'SC') seen = SNseen() goodpkts = 0 IOErrorCount = 0 @@ -111,11 +122,13 @@ class RTPacket: print(e) def settimestring(self): - self.timestring = "%(year)0.2d:%(day)0.3d:%(hour)0.2d:%(min)0.2d:%(sec)0.2d.%(millisec)0.3d" % self.__dict__ + self.timestring = ("%(year)0.2d:%(day)0.3d:%(hour)0.2d:%(min)0.2d:" + "%(sec)0.2d.%(millisec)0.3d" % self.__dict__) def isvalid(self): """ - Returns True if a valid reftek packet (headers parse well and are valid) + Returns True if a valid reftek packet (headers parse well and are + valid) Also populates the objects attributes SN, time, etc. """ @@ -128,11 +141,12 @@ class RTPacket: self.expnum = int("%0.2X" % tup[2]) self.year = int("%0.2X" % tup[3]) self.sn = "%0.2X%0.2X" % (tup[4], tup[5]) - assert '9001' <= self.sn, "BAD SN" + assert self.sn >= '9001', "BAD SN" assert self.sn <= 'FFFF', "BAD SN" time = "%0.2X%0.2X%0.2X%0.2X%0.2X%0.2X" % tup[6:12] self.day, self.hour, self.min, self.sec, self.millisec = \ - int(time[:3]), int(time[3:5]), int(time[5:7]), int(time[7:9]), int(time[9:]) + int(time[:3]), int(time[3:5]), int( + time[5:7]), int(time[7:9]), int(time[9:]) assert self.day <= 366, "BAD TIME" assert self.hour <= 24, "BAD TIME" assert self.min <= 60, "BAD TIME" @@ -199,8 +213,9 @@ def readfile(infile): infile.seek(-1023, 1) print(summary(infile)) - # commented out as when run with many files as input like a cf dir the closed fh's need to be written to and isn't - # smart enough to be opened RTPacket.seen.close_fhs() + # commented out as when run with many files as input like a cf dir the + # closed fh's need to be written to and isn't smart enough to be opened + # RTPacket.seen.close_fhs() def summary(infile): @@ -208,7 +223,8 @@ def summary(infile): offstring = "%6s: %12d\n" s = offstring % ("OFFSET", infile.tell()) s += offstring % ("OF", FILESIZE) - s += "Good packets: %d = %8.2fMB\n" % (RTPacket.goodpkts, RTPacket.goodpkts / 1024.0) + s += "Good packets: %d = %8.2fMB\n" % ( + RTPacket.goodpkts, RTPacket.goodpkts / 1024.0) s += "IOErrors: %d\n" % RTPacket.IOErrorCount s += str(RTPacket.seen) + '\n' return s @@ -259,13 +275,13 @@ def main(): PREFIX = basename(infilename) print("Using prefix %s" % PREFIX) FILESIZE = getsize(infilename) - # Must open the file in binary mode or else we will have unicode issues when reading. + # Must open the file in binary mode or else we will have unicode issues + # when reading. with open(infilename, "rb") as infile: readfile(infile) if args.SUMMARY: summaryfh.write(infilename + ', ' + PREFIX + '\n') summaryfh.write(summary(infile)) - print("----------------------------------------") if isfile(SUMMARY_FILE): summaryfh.close() diff --git a/setup.py b/setup.py index 1dbc630f0fd2fbd36748db864703f0472bac75f1..7487aa2f8421d02ffdbaeddfd3e3dcf76f58c054 100644 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ setup( ], }, install_requires=[], - setup_requires = [], + setup_requires=[], extras_require={ 'dev': [ 'pip',