annotate kplot/main.py @ 1:2c37f81bf3a7

remove
author Jeff Hammel <k0scist@gmail.com>
date Thu, 14 Aug 2014 16:27:21 -0700
parents 48d0f28311a3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 """
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 personal experiments in plotting
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6 """
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 # imports
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 import argparse
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10 import os
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11 import subprocess
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12 import sys
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14 # module globals
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15 __all__ = ['main', 'Parser']
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 here = os.path.dirname(os.path.realpath(__file__))
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17 string = (str, unicode)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 def ensure_dir(directory):
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20 """ensure a directory exists"""
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
21 if os.path.exists(directory):
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
22 assert os.path.isdir(directory)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
23 return directory
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
24 os.makedirs(directory)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
25 return directory
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
26
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
27
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
28 class Parser(argparse.ArgumentParser):
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
29 """CLI option parser"""
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
30 def __init__(self, **kwargs):
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
31 kwargs.setdefault('description', __doc__)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
32 argparse.ArgumentParser.__init__(self, **kwargs)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
33 self.options = None
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
34
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
35 def parse_args(self, *args, **kw):
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
36 options = argparse.ArgumentParser.parse_args(self, *args, **kw)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
37 self.validate(options)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
38 self.options = options
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
39 return options
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
40
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
41 def validate(self, options):
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
42 """validate options"""
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
43
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
44 def main(args=sys.argv[1:]):
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
45 """CLI"""
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
46
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
47 # parse command line options
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
48 parser = Parser()
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
49 options = parser.parse_args(args)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
50
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
51 if __name__ == '__main__':
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
52 main()
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
53