diff options
| author | Kenneth Reitz <me@kennethreitz.com> | 2010-07-13 13:42:44 -0400 |
|---|---|---|
| committer | Kenneth Reitz <me@kennethreitz.com> | 2010-07-13 13:42:44 -0400 |
| commit | dcff226fc09e3b25f2b0a9143dcefc3389ac5e8a (patch) | |
| tree | 2baa045ca49d08290053fe886947fb02be56560d /tabbed/cli.py | |
| parent | deeefc0063f439ffd9144a8c7a20501be6a80ee1 (diff) | |
| download | tablib-dcff226fc09e3b25f2b0a9143dcefc3389ac5e8a.tar.gz | |
cli | paing coming along
Diffstat (limited to 'tabbed/cli.py')
| -rw-r--r-- | tabbed/cli.py | 77 |
1 files changed, 68 insertions, 9 deletions
diff --git a/tabbed/cli.py b/tabbed/cli.py index be44ea0..dc8a03e 100644 --- a/tabbed/cli.py +++ b/tabbed/cli.py @@ -1,23 +1,82 @@ #!/usr/bin/env python # encoding: utf-8 +import io +import sys from helpers import * -# from core import Parse +import tabbed.core + from packages import opster +opts = [('v', 'version', False, 'Report tabbed version')] + +formats = ('json', 'yaml', 'xls', 'csv', 'html') -opts = ( - ('v', 'version', False, 'Report tabbed version'), - ('', 'to', False, 'Output format') -) +for format in formats: + opts.append(('', format, False, 'Output to %s' % (format.upper()))) -@opster.command(options=opts, usage='[FILE] [--to] [FILE]') -def start(**opts): +@opster.command(options=opts, usage='[FILE] [--FORMAT | FILE]') +def start(in_file=None, out_file=None, **opts): """ Converts dataset formats """ - print opts + opts = Object(**opts) + + if opts.version: + print('Tabbed, Ver. %s' % tabbed.core.__version__) + exit(0) + + stdin = piped() + + if stdin: + print stdin + + elif in_file: + + in_file = io.open(in_file, 'r') + + print in_file.read() + try: + in_file = io.open(in_file) + except Exception, e: + print(' %s cannot be read.' % in_file) + exit(65) + + + file_ext = in_file.name.split('.')[-1] + + if file_ext.lower() in formats: + setattr(opts, file_ext, True) + else: + print('Import format not supported.') + exit(65) + else: + print('Please provide input.') + + + + _formats_sum = sum(opts[f] for f in formats) + + # Multiple output formats given + if _formats_sum > 1: + print('Please specify a single output format.') + exit(64) + + # No output formats given + elif _formats_sum < 1: + print('Please specify an output format.') + exit(64) + + + # fetch options.formats list + # if sum(()) > 1 + # log only one data format please + # if sum of formats == 0, specity format + + # look for filename - opts = Object(**opts)
\ No newline at end of file + print opts.__dict__ + print in_file + print out_file
\ No newline at end of file |
