From 216de5fa8252700cd2721b3850a1f386f0a331f3 Mon Sep 17 00:00:00 2001
From: Hal Simpson <hasimpson@usgs.gov>
Date: Tue, 31 Mar 2015 11:05:05 -0600
Subject: [PATCH] moved I/O & algorithm specific parser arguments to their
 individual Factory's/Algorithms.

---
 bin/geomag.py                        | 51 +++++-----------------------
 geomagio/XYZAlgorithm.py             | 13 +++++++
 geomagio/edge/EdgeFactory.py         | 13 +++++++
 geomagio/iaga2002/IAGA2002Factory.py | 36 ++++++++++++++++++++
 4 files changed, 71 insertions(+), 42 deletions(-)

diff --git a/bin/geomag.py b/bin/geomag.py
index 5bcaa2baa..a63c87fbb 100755
--- a/bin/geomag.py
+++ b/bin/geomag.py
@@ -17,6 +17,9 @@ from geomagio.Algorithm import Algorithm
 from geomagio.XYZAlgorithm import XYZAlgorithm
 from geomagio.Controller import Controller
 from geomagio.iaga2002.IAGA2002Factory import IAGA_FILE_PATTERN
+from geomagio.iaga2002.IAGA2002Factory import iaga_add_parse_arguments
+from geomagio.XYZAlgorithm import XYZAlgorithm_add_parse_arguments
+from geomagio.edge.EdgeFactory import edge_add_parse_arguments
 from obspy.core.utcdatetime import UTCDateTime
 
 
@@ -137,48 +140,12 @@ def parse_args():
     parser.add_argument('--interval', default='minute',
             choices=['minute', 'second'])
 
-    parser.add_argument('--algorithm', choices='xyz')
-
-    # xyz algorithm arguments
-    parser.add_argument('--xyz-informat',
-            choices=['geo', 'mag', 'obs', 'obsd'])
-    parser.add_argument('--xyz-outformat',
-            choices=['geo', 'mag', 'obs', 'obsd'])
-
-    # iaga2002 input arguments
-    parser.add_argument('--input-iaga-file',
-            help='Iaga2002 filename')
-    parser.add_argument('--input-iaga-magweb',
-            action="store_true", default=False,
-            help='Indicates iaga2002 files will be read from \
-            http://magweb.cr.usgs.gov/data/magnetometer/')
-    parser.add_argument('--input-iaga-stdin',
-            action="store_true", default=False,
-            help='Indicates file will be redirected from stdin')
-    parser.add_argument('--input-iaga-url',
-            help='Url or Directory where Iaga2002 files can be read from')
-    parser.add_argument('--input-iaga-urltemplate',
-            help='Template for directory matching')
-    parser.add_argument('--input-iaga-filetemplate',
-            help='Template for iaga filenames')
-
-    parser.add_argument('--output-iaga-url',
-            help='Url or Directory where IAGA2002 files should be written to')
-    parser.add_argument('--output-iaga-stdout',
-            action="store_true", default=False,
-            help='Indicates file will be directed to stdout')
-    parser.add_argument('--output-iaga-urltemplate',
-            help='Template for subdirectories')
-    parser.add_argument('--output-iaga-filetemplate',
-            help='Template for iaga filenames')
-    parser.add_argument('--output-iaga-file',
-            help='Output file name for single iaga file.')
-
-    # Edge input arguments
-    parser.add_argument('--input-edge-host',
-            help='ip address of the edge input server')
-    parser.add_argument('--input-edge-port', type=int,
-            help='port number of the edge input server')
+    parser.add_argument('--algorithm', choices=['xyz', ])
+
+    # Add I/O and Algorithm specific arguments
+    iaga_add_parse_arguments(parser)
+    edge_add_parse_arguments(parser)
+    XYZAlgorithm_add_parse_arguments(parser)
 
     return parser.parse_args()
 
diff --git a/geomagio/XYZAlgorithm.py b/geomagio/XYZAlgorithm.py
index 60e175a70..bf06b300d 100644
--- a/geomagio/XYZAlgorithm.py
+++ b/geomagio/XYZAlgorithm.py
@@ -19,6 +19,19 @@ CHANNELS = {
 }
 
 
+def XYZAlgorithm_add_parse_arguments(parser):
+    """add XYZ specific arguments to parser
+
+    Parameters
+    ----------
+    parser: argparse.ArgumentParser
+    """
+    parser.add_argument('--xyz-informat',
+            choices=['geo', 'mag', 'obs', 'obsd'])
+    parser.add_argument('--xyz-outformat',
+            choices=['geo', 'mag', 'obs', 'obsd'])
+
+
 class XYZAlgorithm(Algorithm):
     """Algorithm for converting data,  probably inapproprately named XYZ.
 
diff --git a/geomagio/edge/EdgeFactory.py b/geomagio/edge/EdgeFactory.py
index 9ce07c5b6..12a86af0e 100644
--- a/geomagio/edge/EdgeFactory.py
+++ b/geomagio/edge/EdgeFactory.py
@@ -17,6 +17,19 @@ from obspy import earthworm
 from ObservatoryMetadata import ObservatoryMetadata
 
 
+def edge_add_parse_arguments(parser):
+    """add edge specific arguments to parser
+
+    Parameters
+    ----------
+    parser: argparse.ArgumentParser
+    """
+    parser.add_argument('--input-edge-host',
+            help='ip address of the edge input server')
+    parser.add_argument('--input-edge-port', type=int,
+            help='port number of the edge input server')
+
+
 class EdgeFactory(TimeseriesFactory):
     """TimeseriesFactory for Edge related data.
 
diff --git a/geomagio/iaga2002/IAGA2002Factory.py b/geomagio/iaga2002/IAGA2002Factory.py
index c5be4f1bd..493bdd08a 100644
--- a/geomagio/iaga2002/IAGA2002Factory.py
+++ b/geomagio/iaga2002/IAGA2002Factory.py
@@ -43,6 +43,42 @@ def read_url(url):
     return content
 
 
+def iaga_add_parse_arguments(parser):
+    """add iaga2002 specific arguments to parser
+
+    Parameters
+    ----------
+    parser: argparse.ArgumentParser
+    """
+    parser.add_argument('--input-iaga-file',
+            help='Iaga2002 filename')
+    parser.add_argument('--input-iaga-magweb',
+            action="store_true", default=False,
+            help='Indicates iaga2002 files will be read from \
+            http://magweb.cr.usgs.gov/data/magnetometer/')
+    parser.add_argument('--input-iaga-stdin',
+            action="store_true", default=False,
+            help='Indicates file will be redirected from stdin')
+    parser.add_argument('--input-iaga-url',
+            help='Url or Directory where Iaga2002 files can be read from')
+    parser.add_argument('--input-iaga-urltemplate',
+            help='Template for directory matching')
+    parser.add_argument('--input-iaga-filetemplate',
+            help='Template for iaga filenames')
+
+    parser.add_argument('--output-iaga-url',
+            help='Url or Directory where IAGA2002 files should be written to')
+    parser.add_argument('--output-iaga-stdout',
+            action="store_true", default=False,
+            help='Indicates file will be directed to stdout')
+    parser.add_argument('--output-iaga-urltemplate',
+            help='Template for subdirectories')
+    parser.add_argument('--output-iaga-filetemplate',
+            help='Template for iaga filenames')
+    parser.add_argument('--output-iaga-file',
+            help='Output file name for single iaga file.')
+
+
 class IAGA2002Factory(TimeseriesFactory):
     """TimeseriesFactory for IAGA 2002 formatted files.
 
-- 
GitLab