From 37a07337c124ade23453e99c860b1002649b8c6c Mon Sep 17 00:00:00 2001 From: Michael Love <mlove@passcal.nmt.edu> Date: Thu, 16 Aug 2018 16:52:25 -0600 Subject: [PATCH] Clean up global variables. --- HISTORY.rst | 2 +- refscrub/__init__.py | 2 +- refscrub/refscrub.py | 31 +++++++++++++------------------ setup.cfg | 2 +- setup.py | 2 +- 5 files changed, 17 insertions(+), 22 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index ffd258c..e3a5348 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -17,7 +17,7 @@ History * Minor fixes of global variables -2018.227 (2018-09-16) +2018.228 (2018-09-17) ------------------ * Python 2.7 & 3.6 compatiblity. diff --git a/refscrub/__init__.py b/refscrub/__init__.py index efb2f2d..41aa9e9 100644 --- a/refscrub/__init__.py +++ b/refscrub/__init__.py @@ -4,4 +4,4 @@ __author__ = """IRIS PASSCAL""" __email__ = 'software-support@passcal.nmt.edu' -__version__ = '2018.227' +__version__ = '2018.228' diff --git a/refscrub/refscrub.py b/refscrub/refscrub.py index 3d0d7b1..6e0ff37 100644 --- a/refscrub/refscrub.py +++ b/refscrub/refscrub.py @@ -12,6 +12,7 @@ Michael Love August 2018 Updates to work on both Python 2 & 3. Code cleanup to match PEP 8. +Cleanup global vars. """ from __future__ import (print_function, with_statement) from os.path import join, basename, getsize @@ -19,12 +20,11 @@ import sys import struct USAGE = 'usage: %prog [options] infile1 [ infile2 ... infileN]' -PROG_VERSION = '2018.227' +PROG_VERSION = '2018.228' VERBOSE = False EXTRACT = False SUMMARY_FILE = 'scrubsum.txt' PREFIX = "" -INFILE = "" FILESIZE = 0 TABS = "\t\t\t\t" @@ -181,18 +181,18 @@ class RTPacket: return True -def readfile(filename): +def readfile(infile): ticker = 1 # speedup local vars global VERBOSE global EXTRACT - tell = filename.tell - read = filename.read - seek = filename.seek + tell = infile.tell + read = infile.read + seek = infile.seek while True: ticker += 1 if VERBOSE is False and ticker == 10000: - print(summary()) + print(summary(infile)) ticker = 1 if VERBOSE: print("OFFSET: %12d" % tell()) @@ -226,16 +226,15 @@ def readfile(filename): print(TABS + ">>>>>>>>") seek(-1023, 1) - print(summary()) + 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() -def summary(): - global INFILE +def summary(infile): global FILESIZE offstring = "%6s: %12d\n" - s = offstring % ("OFFSET", INFILE.tell()) + s = offstring % ("OFFSET", infile.tell()) s += offstring % ("OF", FILESIZE) s += "Good packets: %d = %8.2fMB\n" % (RTPacket.goodpkts, RTPacket.goodpkts / 1024.0) s += "IOErrors: %d\n" % RTPacket.IOErrorCount @@ -247,7 +246,6 @@ def main(): global VERBOSE global EXTRACT global PREFIX - global INFILE global FILESIZE summaryfh = None from optparse import OptionParser @@ -275,14 +273,11 @@ def main(): PREFIX = basename(infilename) print("Using prefix %s" % PREFIX) FILESIZE = getsize(infilename) - with open(infilename) as filename: - # with open( filename.name + 'scrub.ref')) as outfile: - # import profile - # profile.run('readfile(filename)') - readfile(filename) + with open(infilename) as infile: + readfile(infile) if options.SUMMARY: summaryfh.write(infilename + ', ' + PREFIX + '\n') - summaryfh.write(summary()) + summaryfh.write(summary(infile)) print("----------------------------------------") diff --git a/setup.cfg b/setup.cfg index 5e7c599..371beb7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2018.227 +current_version = 2018.228 commit = True tag = True diff --git a/setup.py b/setup.py index 29be5b2..288cc8f 100644 --- a/setup.py +++ b/setup.py @@ -51,6 +51,6 @@ setup( packages=find_packages(include=['refscrub']), test_suite='tests', url='https://git.passcal.nmt.edu/passoft/refscrub', - version='2018.227', + version='2018.228', zip_safe=False, ) -- GitLab