57
|
1 #!/usr/bin/env python
|
|
2 # -*- coding: utf-8 -*-
|
|
3
|
|
4 """
|
|
5 manipulate CSV data
|
|
6 """
|
|
7
|
|
8 # imports
|
|
9 import argparse
|
|
10 import os
|
|
11 import subprocess
|
|
12 import sys
|
|
13
|
|
14 # module globals
|
|
15 __all__ = ['main', 'Parser']
|
|
16 here = os.path.dirname(os.path.realpath(__file__))
|
|
17 string = (str, unicode)
|
|
18
|
|
19 class Parser(argparse.ArgumentParser):
|
|
20 """CLI option parser"""
|
|
21 def __init__(self, **kwargs):
|
|
22 kwargs.setdefault('formatter_class', argparse.RawTextHelpFormatter)
|
|
23 kwargs.setdefault('description', __doc__)
|
|
24 argparse.ArgumentParser.__init__(self, **kwargs)
|
|
25 self.options = None
|
|
26
|
|
27 def parse_args(self, *args, **kw):
|
|
28 options = argparse.ArgumentParser.parse_args(self, *args, **kw)
|
|
29 self.validate(options)
|
|
30 self.options = options
|
|
31 return options
|
|
32
|
|
33 def validate(self, options):
|
|
34 """validate options"""
|
|
35
|
|
36 def main(args=sys.argv[1:]):
|
|
37 """CLI"""
|
|
38
|
|
39 # parse command line options
|
|
40 parser = Parser()
|
|
41 options = parser.parse_args(args)
|
|
42
|
|
43 if __name__ == '__main__':
|
|
44 main()
|
|
45
|