# HG changeset patch # User Jeff Hammel # Date 1428945467 25200 # Node ID 8a1fe454c98aaa13324a008f8888a75a8cb2442c # Parent dcedbe63d2c6f1f671d4861876a960449893df48 STUB diff -r dcedbe63d2c6 -r 8a1fe454c98a numerics/cleanse.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/numerics/cleanse.py Mon Apr 13 10:17:47 2015 -0700 @@ -0,0 +1,81 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +cleans up outliers +""" + +# imports +import argparse +import os +import subprocess +import sys +import time + +# python requirements +# (key, value) = (module, PyPI name) +requirements = () +for module, package in requirements: + try: + globals()[module] = __import__(module) + except ImportError: + # install requirement and try again + subprocess.check_call(['pip', 'install', package]) + args = [sys.executable] + sys.argv + os.execl(sys.executable, *args) + +# 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 + + +class Parser(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() + + diff -r dcedbe63d2c6 -r 8a1fe454c98a setup.py --- a/setup.py Sun Apr 12 19:27:23 2015 -0700 +++ b/setup.py Mon Apr 13 10:17:47 2015 -0700 @@ -23,6 +23,7 @@ [console_scripts] bar-chart = numerics.bar:main cat-columns = numerics.cat_columns:main + cleanse = numerics.clean:main display-fraction = numerics.text_display:main histogram = numerics.histogram:main interpolate = numerics.interpolation:main @@ -36,7 +37,6 @@ types = numerics.convert:main """ # TODO: -# cleanse = numerics.clean:main # cleans up outliers # fold = numerics.fold:main # fold data through functions (reduce) kw['install_requires'] = dependencies except ImportError: