Mercurial > hg > numerics
comparison numerics/manipulate.py @ 60:e3c3ee7b5ccf
stubbing manipulate data
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Thu, 22 Jan 2015 13:33:56 -0800 |
parents | 537fba7c9def |
children | 82a18c9337c3 |
comparison
equal
deleted
inserted
replaced
59:3781174542bb | 60:e3c3ee7b5ccf |
---|---|
6 """ | 6 """ |
7 | 7 |
8 # imports | 8 # imports |
9 import argparse | 9 import argparse |
10 import os | 10 import os |
11 import subprocess | |
12 import sys | 11 import sys |
12 from .convert import cast_columns | |
13 from .read import CSVParser | |
13 | 14 |
14 # module globals | 15 # module globals |
15 __all__ = ['main', 'Parser'] | 16 __all__ = ['main', 'ManipulationParser'] |
16 here = os.path.dirname(os.path.realpath(__file__)) | 17 here = os.path.dirname(os.path.realpath(__file__)) |
17 string = (str, unicode) | 18 string = (str, unicode) |
18 | 19 |
19 class Parser(argparse.ArgumentParser): | 20 class ManipulationParser(CSVParser): |
20 """CLI option parser""" | 21 """CLI option parser for data manipulation""" |
22 | |
21 def __init__(self, **kwargs): | 23 def __init__(self, **kwargs): |
22 kwargs.setdefault('formatter_class', argparse.RawTextHelpFormatter) | |
23 kwargs.setdefault('description', __doc__) | 24 kwargs.setdefault('description', __doc__) |
24 argparse.ArgumentParser.__init__(self, **kwargs) | 25 CSVParser.__init__(self, **kwargs) |
26 self.add_argument('--list', '--entries', '--list-entries', | |
27 dest='list_entries', nargs='?', const=0, type=int, | |
28 help="list all entries for this column") | |
25 self.options = None | 29 self.options = None |
26 | 30 |
27 def parse_args(self, *args, **kw): | 31 def typed_data(self): |
28 options = argparse.ArgumentParser.parse_args(self, *args, **kw) | 32 raise NotImplementedError('TODO') # -> record TODO items |
29 self.validate(options) | |
30 self.options = options | |
31 return options | |
32 | |
33 def validate(self, options): | |
34 """validate options""" | |
35 | 33 |
36 def main(args=sys.argv[1:]): | 34 def main(args=sys.argv[1:]): |
37 """CLI""" | 35 """CLI""" |
38 | 36 |
39 # parse command line options | 37 # parse command line options |
40 parser = Parser() | 38 parser = Parser() |
41 options = parser.parse_args(args) | 39 options = parser.parse_args(args) |
42 | 40 |
41 if options.list_entries: | |
42 raise NotImplementedError('TODO') # -> record TODO items | |
43 | |
43 if __name__ == '__main__': | 44 if __name__ == '__main__': |
44 main() | 45 main() |
45 | 46 |