Skip to content
Snippets Groups Projects
Commit 37a07337 authored by Michael Love's avatar Michael Love
Browse files

Clean up global variables.

parent 40c461f5
No related branches found
No related tags found
1 merge request!2Resolve "Python 3"
...@@ -17,7 +17,7 @@ History ...@@ -17,7 +17,7 @@ History
* Minor fixes of global variables * Minor fixes of global variables
2018.227 (2018-09-16) 2018.228 (2018-09-17)
------------------ ------------------
* Python 2.7 & 3.6 compatiblity. * Python 2.7 & 3.6 compatiblity.
......
...@@ -4,4 +4,4 @@ ...@@ -4,4 +4,4 @@
__author__ = """IRIS PASSCAL""" __author__ = """IRIS PASSCAL"""
__email__ = 'software-support@passcal.nmt.edu' __email__ = 'software-support@passcal.nmt.edu'
__version__ = '2018.227' __version__ = '2018.228'
...@@ -12,6 +12,7 @@ Michael Love ...@@ -12,6 +12,7 @@ Michael Love
August 2018 August 2018
Updates to work on both Python 2 & 3. Updates to work on both Python 2 & 3.
Code cleanup to match PEP 8. Code cleanup to match PEP 8.
Cleanup global vars.
""" """
from __future__ import (print_function, with_statement) from __future__ import (print_function, with_statement)
from os.path import join, basename, getsize from os.path import join, basename, getsize
...@@ -19,12 +20,11 @@ import sys ...@@ -19,12 +20,11 @@ import sys
import struct import struct
USAGE = 'usage: %prog [options] infile1 [ infile2 ... infileN]' USAGE = 'usage: %prog [options] infile1 [ infile2 ... infileN]'
PROG_VERSION = '2018.227' PROG_VERSION = '2018.228'
VERBOSE = False VERBOSE = False
EXTRACT = False EXTRACT = False
SUMMARY_FILE = 'scrubsum.txt' SUMMARY_FILE = 'scrubsum.txt'
PREFIX = "" PREFIX = ""
INFILE = ""
FILESIZE = 0 FILESIZE = 0
TABS = "\t\t\t\t" TABS = "\t\t\t\t"
...@@ -181,18 +181,18 @@ class RTPacket: ...@@ -181,18 +181,18 @@ class RTPacket:
return True return True
def readfile(filename): def readfile(infile):
ticker = 1 ticker = 1
# speedup local vars # speedup local vars
global VERBOSE global VERBOSE
global EXTRACT global EXTRACT
tell = filename.tell tell = infile.tell
read = filename.read read = infile.read
seek = filename.seek seek = infile.seek
while True: while True:
ticker += 1 ticker += 1
if VERBOSE is False and ticker == 10000: if VERBOSE is False and ticker == 10000:
print(summary()) print(summary(infile))
ticker = 1 ticker = 1
if VERBOSE: if VERBOSE:
print("OFFSET: %12d" % tell()) print("OFFSET: %12d" % tell())
...@@ -226,16 +226,15 @@ def readfile(filename): ...@@ -226,16 +226,15 @@ def readfile(filename):
print(TABS + ">>>>>>>>") print(TABS + ">>>>>>>>")
seek(-1023, 1) 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 # 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() # smart enough to be opened RTPacket.seen.close_fhs()
def summary(): def summary(infile):
global INFILE
global FILESIZE global FILESIZE
offstring = "%6s: %12d\n" offstring = "%6s: %12d\n"
s = offstring % ("OFFSET", INFILE.tell()) s = offstring % ("OFFSET", infile.tell())
s += offstring % ("OF", FILESIZE) 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 += "IOErrors: %d\n" % RTPacket.IOErrorCount
...@@ -247,7 +246,6 @@ def main(): ...@@ -247,7 +246,6 @@ def main():
global VERBOSE global VERBOSE
global EXTRACT global EXTRACT
global PREFIX global PREFIX
global INFILE
global FILESIZE global FILESIZE
summaryfh = None summaryfh = None
from optparse import OptionParser from optparse import OptionParser
...@@ -275,14 +273,11 @@ def main(): ...@@ -275,14 +273,11 @@ def main():
PREFIX = basename(infilename) PREFIX = basename(infilename)
print("Using prefix %s" % PREFIX) print("Using prefix %s" % PREFIX)
FILESIZE = getsize(infilename) FILESIZE = getsize(infilename)
with open(infilename) as filename: with open(infilename) as infile:
# with open( filename.name + 'scrub.ref')) as outfile: readfile(infile)
# import profile
# profile.run('readfile(filename)')
readfile(filename)
if options.SUMMARY: if options.SUMMARY:
summaryfh.write(infilename + ', ' + PREFIX + '\n') summaryfh.write(infilename + ', ' + PREFIX + '\n')
summaryfh.write(summary()) summaryfh.write(summary(infile))
print("----------------------------------------") print("----------------------------------------")
......
[bumpversion] [bumpversion]
current_version = 2018.227 current_version = 2018.228
commit = True commit = True
tag = True tag = True
......
...@@ -51,6 +51,6 @@ setup( ...@@ -51,6 +51,6 @@ setup(
packages=find_packages(include=['refscrub']), packages=find_packages(include=['refscrub']),
test_suite='tests', test_suite='tests',
url='https://git.passcal.nmt.edu/passoft/refscrub', url='https://git.passcal.nmt.edu/passoft/refscrub',
version='2018.227', version='2018.228',
zip_safe=False, zip_safe=False,
) )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment