summaryrefslogtreecommitdiff
path: root/tablib/cli.py
diff options
context:
space:
mode:
authorKenneth Reitz <me@kennethreitz.com>2010-09-25 17:26:53 -0400
committerKenneth Reitz <me@kennethreitz.com>2010-09-25 17:26:53 -0400
commit8feb6e8ddf7cecc26958654411b6bfc0aec08499 (patch)
tree07e22f978e01201ff3bc0a42dcecb9576e141462 /tablib/cli.py
parent9072b6ddae5cf6410ef86872e3b084321f2034ca (diff)
downloadtablib-8feb6e8ddf7cecc26958654411b6bfc0aec08499.tar.gz
Added legacy cli interface.
Diffstat (limited to 'tablib/cli.py')
-rw-r--r--tablib/cli.py86
1 files changed, 86 insertions, 0 deletions
diff --git a/tablib/cli.py b/tablib/cli.py
new file mode 100644
index 0000000..4e46eae
--- /dev/null
+++ b/tablib/cli.py
@@ -0,0 +1,86 @@
+#!/usr/bin/env python
+# encoding: utf-8
+
+""" Tabbed CLI Inteface Application
+"""
+
+import io
+import sys
+
+import argue
+
+import tablib
+from helpers import Struct, piped
+
+
+
+FORMATS = ('json', 'yaml', 'xls', 'csv')
+
+opts = []
+
+opts.append(('v', 'version', False, 'Report tabbed version'))
+
+for format in FORMATS:
+ opts.append(('', format, False, 'Output to %s' % (format.upper())))
+
+
+
+@argue.command(options=opts, usage='[FILE] [--FORMAT | FILE]')
+def start(in_file=None, out_file=None, **opts):
+ """Covertly convert dataset formats"""
+
+ opts = Struct(**opts)
+
+ if opts.version:
+ print('Tabbed, Ver. %s' % tabbed.core.__version__)
+ sys.sys.exit(0)
+
+ stdin = piped()
+
+ if stdin:
+ print stdin
+
+ elif in_file:
+
+ try:
+ in_file = io.open(in_file, 'r')
+ except Exception, e:
+ print(' %s cannot be read.' % in_file)
+ sys.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.')
+ sys.exit(65)
+ else:
+ print('Please provide input.')
+ sys.exit(65)
+
+
+
+ _formats_sum = sum(opts[f] for f in FORMATS)
+
+ # Multiple output formats given
+ if _formats_sum > 1:
+ print('Please specify a single output format.')
+ sys.exit(64)
+
+ # No output formats given
+ elif _formats_sum < 1:
+ print('Please specify an output format.')
+ sys.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
+
+ print opts.__dict__
+ print in_file
+ print out_file \ No newline at end of file