diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6524a3fd7cb85e8093c49e99c381fdbc7c0230c9..1bc87f19a75ebeec1b0f4efc381c15a59272730c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -20,17 +20,26 @@ stages: before_script: - pip install -e .[dev] +python3.6: + image: python:3.6 + tags: + - passoft + stage: test + script: + - python -m unittest -python2: - image: python:2.7 +python3.7: + image: python:3.7 tags: - passoft stage: test - script: tox -e py27 + script: + - python -m unittest -python3: - image: python:3.6 +python3.8: + image: python:3.8 tags: - passoft stage: test - script: tox -e py36 + script: + - python -m unittest diff --git a/docs/conf.py b/docs/conf.py index 3971c64f6a7c8b50ac5b1c4c892c2c8957e83fb9..6e27d97916ea9e851ebd5c9189f1a03534a6cfaa 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -47,9 +47,9 @@ source_suffix = '.rst' master_doc = 'index' # General information about the project. -project = u'refscrub' -copyright = u"2018, IRIS PASSCAL" -author = u"IRIS PASSCAL" +project = 'refscrub' +copyright = "2018, IRIS PASSCAL" +author = "IRIS PASSCAL" # The version info for the project you're documenting, acts as replacement # for |version| and |release|, also used in various other places throughout @@ -129,8 +129,8 @@ latex_elements = { # [howto, manual, or own class]). latex_documents = [ (master_doc, 'refscrub.tex', - u'refscrub Documentation', - u'IRIS PASSCAL', 'manual'), + 'refscrub Documentation', + 'IRIS PASSCAL', 'manual'), ] @@ -140,7 +140,7 @@ latex_documents = [ # (source start file, name, description, authors, manual section). man_pages = [ (master_doc, 'refscrub', - u'refscrub Documentation', + 'refscrub Documentation', [author], 1) ] @@ -152,7 +152,7 @@ man_pages = [ # dir menu entry, description, category) texinfo_documents = [ (master_doc, 'refscrub', - u'refscrub Documentation', + 'refscrub Documentation', author, 'refscrub', 'One line description of project.', diff --git a/refscrub/refscrub.py b/refscrub/refscrub.py index ae66381824d1118f8bea58d5b22d881dc4375399..9a1da488f3b5285957d2250bda78390e02a0786a 100644 --- a/refscrub/refscrub.py +++ b/refscrub/refscrub.py @@ -14,12 +14,11 @@ 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 import sys +import argparse import struct +from os.path import basename, getsize, isfile -USAGE = 'usage: %prog [options] infile1 [ infile2 ... infileN]' PROG_VERSION = '2018.228' VERBOSE = False EXTRACT = False @@ -63,12 +62,12 @@ class SNseen(dict): ret.look(year, day, hour) def close_fhs(self): - for sn in self.values(): + for sn in list(self.values()): sn.close_fh() def __str__(self): s = " SN: YR:DAY:HR -- YR:DAY:HR : %12s\n" % 'Good Packets' - for sn in self.values(): + for sn in list(self.values()): s += str(sn) return s @@ -221,26 +220,40 @@ def main(): global PREFIX global FILESIZE summaryfh = None - from optparse import OptionParser - parser = OptionParser(USAGE, version="%prog " + PROG_VERSION) - parser.description = "infile can be a REFTEK file or a raw disk (/dev/disk1) of a CF card." - parser.add_option('-v', '--verbose', dest="VERBOSE", action='store_true', default=False, - help="Prints info about each packet, good or bad. This will increase runtime.") - parser.add_option('-e', '--extract', dest='EXTRACT', action='store_true', default=False, - help='Writes good packets to files named infile.SNXX.scrub.ref OR PREFIX.SNXX.scrub.ref, ' - ' if given, for each Serial Number found. If output file exists it will append. Be careful ' - 'not to duplicate data by running more than once on the same file in the same dir.') - parser.add_option('-p', '--prefix', dest='PREFIX', - help='Prefix of output filename. Defaults to inputfilename') - parser.add_option('-s', '--savesum', dest='SUMMARY', action='store_true', default=False, - help='Appends summary to %s' % SUMMARY_FILE) - options, args = parser.parse_args() - VERBOSE = options.VERBOSE - EXTRACT = options.EXTRACT - PREFIX = options.PREFIX - if options.SUMMARY: + parser = argparse.ArgumentParser(prog="refscrub", + usage="%(prog)s [options] infile1 " + "[ infile2 ... infileN]") + parser.add_argument('infile', nargs='*', metavar='infile', + help="infile can be a REFTEK file or a raw disk " + "(/dev/disk1) of a CF card.") + parser.add_argument('--version', action='version', + version="%(prog)s " + PROG_VERSION) + parser.add_argument('-v', '--verbose', dest="VERBOSE", action='store_true', + default=False, help="Prints info about each packet, " + "good or bad. This will increase runtime.") + parser.add_argument('-e', '--extract', dest='EXTRACT', action='store_true', + default=False, help="Writes good packets to files " + "named infile.SNXX.scrub.ref OR " + "PREFIX.SNXX.scrub.ref, if given, for each Serial " + "Number found. If output file exists it will append. " + "Be careful not to duplicate data by running more " + "than once on the same file in the same dir.") + parser.add_argument('-p', '--prefix', dest='PREFIX', + help="Prefix of output filename. Defaults to input" + "filename") + parser.add_argument('-s', '--savesum', dest='SUMMARY', action='store_true', + default=False, help='Appends summary to %s' + % SUMMARY_FILE) + args = parser.parse_args() + if not args.infile: + parser.print_help() + sys.exit(1) + VERBOSE = args.VERBOSE + EXTRACT = args.EXTRACT + PREFIX = args.PREFIX + if args.SUMMARY: summaryfh = open(SUMMARY_FILE, 'a') - for infilename in args: + for infilename in args.infile: print("Processing: %s" % infilename) if not PREFIX: PREFIX = basename(infilename) @@ -249,11 +262,13 @@ def main(): # 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 options.SUMMARY: + if args.SUMMARY: summaryfh.write(infilename + ', ' + PREFIX + '\n') summaryfh.write(summary(infile)) print("----------------------------------------") + if isfile(SUMMARY_FILE): + summaryfh.close() if __name__ == '__main__': diff --git a/setup.py b/setup.py index 288cc8fc627f0e09fb47381efc903de58d87ed87..1dbc630f0fd2fbd36748db864703f0472bac75f1 100644 --- a/setup.py +++ b/setup.py @@ -5,10 +5,10 @@ from setuptools import setup, find_packages -with open('README.rst') as readme_file: +with open('README.rst', 'rt') as readme_file: readme = readme_file.read() -with open('HISTORY.rst') as history_file: +with open('HISTORY.rst', 'rt') as history_file: history = history_file.read() @@ -21,6 +21,8 @@ setup( 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', 'Natural Language :: English', 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', ], description="Remove select packets from RT130 data", entry_points={ diff --git a/tests/test_refscrub.py b/tests/test_refscrub.py index 6af0b2dc456bbf8658c58d60118d4d3fa777b326..56529bb82f365b4239220491f8367b26e92d322d 100644 --- a/tests/test_refscrub.py +++ b/tests/test_refscrub.py @@ -21,8 +21,4 @@ class TestRefscrub(unittest.TestCase): """Tear down test fixtures, if any.""" def test_import(self): - if 'refscrub' in sys.modules: - self.assert_(True, "refscrub loaded") - else: - self.fail() - + self.assertTrue('refscrub' in sys.modules, "Refscrub import failed!") diff --git a/tox.ini b/tox.ini index 3e04f0d91f5323f3904fb517bf5b8922dbd42e0d..bf6c0725b91a09d47ebc02bcfec374415d4ecfc9 100644 --- a/tox.ini +++ b/tox.ini @@ -1,19 +1,5 @@ [tox] -envlist = py27, py36 flake8 - -[travis] -python = - 2.7: py27 - 3.6: py36 - -[testenv:flake8] -basepython = python -deps = flake8 -commands = flake8 refscrub +envlist = py36, py37, py38 [testenv] -setenv = - PYTHONPATH = {toxinidir} -commands=python setup.py test - - +commands = python -m unittest