From 8be25129330e169c7da2355b47c891b3c3576eb3 Mon Sep 17 00:00:00 2001
From: Derick Hess <dhess@passcal.nmt.edu>
Date: Mon, 23 Jul 2018 10:48:28 -0600
Subject: [PATCH] add conda recipe, update entrypoint

---
 .gitlab/issue_templates/Bug.md |  2 +-
 CONTRIBUTING.rst               |  8 ++--
 HISTORY.rst                    | 12 ++++-
 LICENSE                        |  2 +-
 README.rst                     |  2 +-
 conda.recipe/meta.yaml         | 24 ++++++++++
 docs/installation.rst          | 19 --------
 refscrub/__init__.py           |  2 +-
 refscrub/refscrub              | 24 ----------
 refscrub/refscrub.py           | 86 +++++++++++++++++++++-------------
 setup.cfg                      |  2 +-
 setup.py                       |  4 +-
 12 files changed, 100 insertions(+), 87 deletions(-)
 create mode 100644 conda.recipe/meta.yaml
 delete mode 100755 refscrub/refscrub

diff --git a/.gitlab/issue_templates/Bug.md b/.gitlab/issue_templates/Bug.md
index 0a15ec0..285e734 100644
--- a/.gitlab/issue_templates/Bug.md
+++ b/.gitlab/issue_templates/Bug.md
@@ -1,4 +1,4 @@
-* rt2ms version:
+* refscrub version:
 * Python version:
 * Operating System:
 
diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index c54a658..3f3c1fa 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -32,7 +32,7 @@ wanted" is open to whoever wants to implement it.
 Implement Features
 ~~~~~~~~~~~~~~~~~~
 
-Look through the GitHub issues for features. Anything tagged with "enhancement"
+Look through the GitLab issues for features. Anything tagged with "enhancement"
 and "help wanted" is open to whoever wants to implement it.
 
 Write Documentation
@@ -88,10 +88,10 @@ Ready to contribute? Here's how to set up `refscrub` for local development.
 Pull Request Guidelines
 -----------------------
 
-Before you submit a pull request, check that it meets these guidelines:
+Before you submit a merge request, check that it meets these guidelines:
 
-1. The pull request should include tests.
-2. If the pull request adds functionality, the docs should be updated. Put
+1. The merge request should include tests.
+2. If the merge request adds functionality, the docs should be updated. Put
    your new functionality into a function with a docstring, and add the
    feature to the list in README.rst.
 3. The pull request should work for Python 2.7
diff --git a/HISTORY.rst b/HISTORY.rst
index 26bb6d4..158c12c 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -2,7 +2,17 @@
 History
 =======
 
-2011.046 (2018-06-05)
+2011.046 (2018-06-07)
 ------------------
 
 * First release on new build system.
+
+2018.180 (2018-06-29)
+------------------
+
+* 2nd release on new build system.
+
+2018.204 (2018-07-23)
+------------------
+
+* Minor fixes of global variables
diff --git a/LICENSE b/LICENSE
index e674925..197ea95 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,7 +1,7 @@
 GNU GENERAL PUBLIC LICENSE
                       Version 3, 29 June 2007
 
-    Remove select packets from RT130 data.
+    Remove select packets from RT130 data
     Copyright (C) 2018  IRIS PASSCAL
 
     This program is free software: you can redistribute it and/or modify
diff --git a/README.rst b/README.rst
index a9817e2..198b6c6 100644
--- a/README.rst
+++ b/README.rst
@@ -3,7 +3,7 @@ refscrub
 ========
 
 
-Remove select packets from RT130 data.
+Remove select packets from RT130 data
 
 
 * Free software: GNU General Public License v3 (GPLv3)
diff --git a/conda.recipe/meta.yaml b/conda.recipe/meta.yaml
new file mode 100644
index 0000000..69ed63f
--- /dev/null
+++ b/conda.recipe/meta.yaml
@@ -0,0 +1,24 @@
+package:
+  name: refscrub
+  version: 2011.046
+
+source:
+  path: ..
+
+build:
+  # If the installation is complex, or different between Unix and Windows, use
+  # separate bld.bat and build.sh files instead of this key.  Add the line
+  # "skip: True  # [py<35]" (for example) to limit to Python 3.5 and newer, or
+  # "skip: True  # [not win]" to limit to Windows.
+  script: python setup.py install --single-version-externally-managed --record=record.txt
+
+requirements:
+  build:
+    - python
+    - setuptools
+  run:
+    - python
+
+about:
+  home: https://git.passcal.nmt.edu/passoft/refscrub
+  summary: Remove select packets from RT130 data
diff --git a/docs/installation.rst b/docs/installation.rst
index 8a4b8fe..7992882 100644
--- a/docs/installation.rst
+++ b/docs/installation.rst
@@ -4,25 +4,6 @@
 Installation
 ============
 
-
-Stable release
---------------
-
-To install refscrub, run this command in your terminal:
-
-.. code-block:: console
-
-    $ pip install refscrub
-
-This is the preferred method to install refscrub, as it will always install the most recent stable release.
-
-If you don't have `pip`_ installed, this `Python installation guide`_ can guide
-you through the process.
-
-.. _pip: https://pip.pypa.io
-.. _Python installation guide: http://docs.python-guide.org/en/latest/starting/installation/
-
-
 From sources
 ------------
 
diff --git a/refscrub/__init__.py b/refscrub/__init__.py
index 96b57e9..384ebd4 100644
--- a/refscrub/__init__.py
+++ b/refscrub/__init__.py
@@ -4,4 +4,4 @@
 
 __author__ = """IRIS PASSCAL"""
 __email__ = 'software-support@passcal.nmt.edu'
-__version__ = '2011.046'
+__version__ = '2018.204'
diff --git a/refscrub/refscrub b/refscrub/refscrub
deleted file mode 100755
index 7605a99..0000000
--- a/refscrub/refscrub
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env bash
-
-EXEC='neo'
-ARGS=$@
-
-if [ ! -z "${PASSCAL}" ]
-then
-		PYTHON=${PASSCAL}/other/bin/picpython
-		export PYTHON
-		set PYTHONPATH ${PASSCAL}/lib/python/${EXEC}
-        export PYTHONPATH
-else
-        echo "PASSCAL environment not set! Can not continue."
-		exit 1
-fi
-
-if [ ! -e "$PYTHON" ]
-then
-		echo "$PYTHON not found! PyPASSCAL is required. Make sure picpython is in your path variable"
-		exit
-fi
-
-
-${PYTHON} ${PASSCAL}/lib/python/${EXEC}/refscrub.py $ARGS
diff --git a/refscrub/refscrub.py b/refscrub/refscrub.py
index 2305927..ba46a85 100755
--- a/refscrub/refscrub.py
+++ b/refscrub/refscrub.py
@@ -3,12 +3,16 @@
 Lloyd Carothers
 February 2011
 Rewrite of original refscrub
+
+Derick Hess
+July 2018
+Minor fixes for new build system
 '''
 from __future__ import with_statement
 USAGE = 'usage: %prog [options] infile1 [ infile2 ... infileN]'
 #USAGE = '''Scans (default) or extracts good reftek packets from a REFTEK file or CF card.'''
 
-PROG_VERSION = '2011.046'
+PROG_VERSION = '2018.204'
 VERBOSE = False
 EXTRACT = False
 SUMMARY_FILE = 'scrubsum.txt'
@@ -21,6 +25,8 @@ import struct
 
 class SN():
     def __init__(self, SN):
+        global EXTRACT
+        global PREFIX
         self.SN = SN
         self.count = 0
         self.dates = list()
@@ -37,8 +43,8 @@ class SN():
     def __str__(self):
         self.dates = list(set(self.dates))
         self.dates.sort()
-        start = "%0.2d:%0.3d:%0.2d" % (self.dates[0]) 
-        end   = "%0.2d:%0.3d:%0.2d" % (self.dates[-1]) 
+        start = "%0.2d:%0.3d:%0.2d" % (self.dates[0])
+        end   = "%0.2d:%0.3d:%0.2d" % (self.dates[-1])
         return "%7s: %s -- %s : %12d\n" % (self.SN , start , end, self.count )
 
 class SNseen(dict):
@@ -53,7 +59,7 @@ class SNseen(dict):
         for sn in self.values():
             s += str(sn)
         return s
-        
+
 
 ##class SNseen(dict):
 ##    def __init__(self):
@@ -73,11 +79,11 @@ class SNseen(dict):
 ##        for sn in self.keys():
 ##            dates = self[sn]
 ##            dates.sort()
-##            start = "%0.2d:%0.3d:%0.2d" % (dates[0]) 
-##            end   = "%0.2d:%0.3d:%0.2d" % (dates[-1]) 
+##            start = "%0.2d:%0.3d:%0.2d" % (dates[0])
+##            end   = "%0.2d:%0.3d:%0.2d" % (dates[-1])
 ##            s += "%7s: %s -- %s\n" % (sn , start , end )
 ##        return s
-        
+
 class RTPacket:
     RTstruct = struct.Struct('2c1B1B2B6B2B2B')
     #packetHdrFmt = '2c1B1B2B6B2B2B'
@@ -107,6 +113,8 @@ class RTPacket:
         Returns True if a valid reftek packet (headers parse well and are valid)
         Also populates the objects attributes SN, time, etc.
         '''
+
+        global VERBOSE
         try:
             tup = RTPacket.RTstruct.unpack(self.data[:16])
             #tup = unpack( self.packetHdrFmt, self.data[:16])
@@ -142,10 +150,12 @@ class RTPacket:
             RTPacket.seen.look(self.sn, self.year, self.day, self.hour)
             RTPacket.goodpkts +=1
             return True
-    
+
 def readfile(infile):
     ticker = 1
     #speedup local vars
+    global VERBOSE
+    global EXTRACT
     tell = infile.tell
     read = infile.read
     seek = infile.seek
@@ -183,12 +193,14 @@ def readfile(infile):
                 print tabs + "NOT VALID"
                 print tabs + ">>>>>>>>"
             seek(-1023, 1)
-            
+
     print summary()
     #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
+    global FILESIZE
     OFFSTRING = "%6s: %12d\n"
     s =  OFFSTRING % ( "OFFSET", infile.tell())
     s += OFFSTRING % ( "OF", FILESIZE)
@@ -196,39 +208,49 @@ def summary():
     s+= "IOErrors: %d\n" % (RTPacket.IOErrorCount)
     s += str(RTPacket.seen) + '\n'
     return s
-    
 
-if __name__ == '__main__':
+def main():
+    global VERBOSE
+    global EXTRACT
+    global PREFIX
+    global infile
+    global FILESIZE
     from optparse import OptionParser
-    parser = OptionParser(USAGE, version = "%prog " + PROG_VERSION)
+    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)
+    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 
+    EXTRACT = options.EXTRACT
     PREFIX = options.PREFIX
     if options.SUMMARY:
-        summaryfh = open (SUMMARY_FILE, 'a')
+        summaryfh = open(SUMMARY_FILE, 'a')
     for infilename in args:
-        print "Processing: %s" % infilename
+        print
+        "Processing: %s" % infilename
         if not PREFIX:
             PREFIX = basename(infilename)
-        print "Using prefix %s" % PREFIX
+        print
+        "Using prefix %s" % PREFIX
         FILESIZE = getsize(infilename)
         with open(infilename) as infile:
-            #with open( infile.name + 'scrub.ref')) as outfile:
-                #import profile
-                #profile.run('readfile(infile)')
-            readfile(infile)                
+            # with open( infile.name + 'scrub.ref')) as outfile:
+            # import profile
+            # profile.run('readfile(infile)')
+            readfile(infile)
             if options.SUMMARY:
-                summaryfh.write(infilename + ', ' + PREFIX + '\n' )
+                summaryfh.write(infilename + ', ' + PREFIX + '\n')
                 summaryfh.write(summary())
-            
-        print "----------------------------------------"
\ No newline at end of file
+
+        print
+        "----------------------------------------"
+
+if __name__ == '__main__':
+    main()
diff --git a/setup.cfg b/setup.cfg
index 76c2845..01be888 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,5 +1,5 @@
 [bumpversion]
-current_version = 2011.046
+current_version = 2018.180
 commit = True
 tag = True
 
diff --git a/setup.py b/setup.py
index 9e1746b..194d54d 100644
--- a/setup.py
+++ b/setup.py
@@ -22,7 +22,7 @@ setup(
         'Natural Language :: English',
         'Programming Language :: Python :: 2.7',
     ],
-    description="Remove select packets from RT130 data.",
+    description="Remove select packets from RT130 data",
     entry_points={
         'console_scripts': [
             'refscrub=refscrub.refscrub:main',
@@ -51,6 +51,6 @@ setup(
     packages=find_packages(include=['refscrub']),
     test_suite='tests',
     url='https://git.passcal.nmt.edu/passoft/refscrub',
-    version='2011.046',
+    version='2018.204',
     zip_safe=False,
 )
-- 
GitLab