view numerics/plot.py @ 34:dea01adf33dc

wip
author Jeff Hammel <k0scist@gmail.com>
date Tue, 04 Nov 2014 16:52:40 -0800
parents 276beb743a59
children cd9ec2784077
line wrap: on
line source

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
plot data

Usage::

  plot foo.csv

Generates plots of all columns of foo versus the first column.
The title is foo.csv unless overridden with ``--title``.
"""

# imports
import argparse
import os
import sys

# module globals
__all__ = ['main', 'PlotParser']
string = (str, unicode)

def ensure_dir(directory):
    """ensure a directory exists"""
    if os.path.exists(directory):
        assert os.path.isdir(directory)
        return directory
    os.makedirs(directory)
    return directory


class PlotParser(argparse.ArgumentParser):
    """CLI option parser"""

    def __init__(self, **kwargs):
        kwargs.setdefault('description', __doc__)
        argparse.ArgumentParser.__init__(self, **kwargs)
        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 = PlotParser()
    options = parser.parse_args(args)


if __name__ == '__main__':
    main()