# HG changeset patch # User Jeff Hammel # Date 1426559509 25200 # Node ID d255058333b2dcf583ae2fb69aa1a498015ff545 # Parent 84baf80a52023ab08b69967c3f60024e5d316a6f putzing diff -r 84baf80a5202 -r d255058333b2 numerics/manipulate.py --- a/numerics/manipulate.py Mon Mar 16 19:17:46 2015 -0700 +++ b/numerics/manipulate.py Mon Mar 16 19:31:49 2015 -0700 @@ -14,7 +14,7 @@ from .read import CSVParser # module globals -__all__ = ['ManipulationParser', 'main'] +__all__ = ['ManipulationParser', 'FloatParser', 'main'] class ManipulationParser(CSVParser): @@ -35,6 +35,11 @@ return transpose(self.typed_data()) +class FloatParser(ManipulationParser): + """manipulation parser convenience just for floats""" + types = (float,) + + def main(args=sys.argv[1:]): """CLI""" diff -r 84baf80a5202 -r d255058333b2 numerics/mean.py --- a/numerics/mean.py Mon Mar 16 19:17:46 2015 -0700 +++ b/numerics/mean.py Mon Mar 16 19:31:49 2015 -0700 @@ -8,16 +8,17 @@ # imports import sys from .filters import mean -from .manipulate import ManipulationParser +from .manipulate import FloatParser from .write import CSVWriter +__all__ = ['main'] + def main(args=sys.argv[1:]): """CLI""" # parse command line options - parser = ManipulationParser() - parser.types = (float,) + parser = FloatParser() options = parser.parse_args(args) # read data diff -r 84baf80a5202 -r d255058333b2 numerics/reduce.py --- a/numerics/reduce.py Mon Mar 16 19:17:46 2015 -0700 +++ b/numerics/reduce.py Mon Mar 16 19:31:49 2015 -0700 @@ -6,64 +6,22 @@ """ # imports -import argparse -import os -import subprocess import sys -import time +from .filters import mean +from .manipulate import FloatParser +from .write import CSVWriter # module globals -__all__ = ['main', 'Parser'] -here = os.path.dirname(os.path.realpath(__file__)) -string = (str, unicode) - -def ensure_dir(directory): - """ensure a directory exists""" - if os.path.exists(directory): - if not os.path.isdir(directory): - raise OSError("Not a directory: '{}'".format(directory)) - return directory - os.makedirs(directory) - return directory +__all__ = ['ReduceParser'] -class Parser(argparse.ArgumentParser): +class ReduceParser(argparse.ArgumentParser): """CLI option parser""" def __init__(self, **kwargs): kwargs.setdefault('formatter_class', argparse.RawTextHelpFormatter) kwargs.setdefault('description', __doc__) argparse.ArgumentParser.__init__(self, **kwargs) - self.add_argument('--monitor', dest='monitor', - type=float, metavar='SLEEP', - help="run in monitor mode") self.options = None - def parse_args(self, *args, **kw): - options = argparse.ArgumentParser.parse_args(self, *args, **kw) - self.validate(options) - self.options = options - return options - - def validate(self, options): - """validate options""" - -def main(args=sys.argv[1:]): - """CLI""" - - # parse command line options - parser = Parser() - options = parser.parse_args(args) - - try: - while True: - if options.monitor: - time.sleep(options.monitor) - else: - break - except KeyboardInterrupt: - pass - -if __name__ == '__main__': - main()