This commit is contained in:
Kenneth Reitz
2010-07-13 15:15:37 -04:00
parent dcff226fc0
commit a1527325d5
3 changed files with 19 additions and 13 deletions
+15 -12
View File
@@ -1,26 +1,32 @@
#!/usr/bin/env python
# encoding: utf-8
""" Tabbed CLI Inteface Application
"""
import io
import sys
from helpers import *
import tabbed.core
from packages import opster
opts = [('v', 'version', False, 'Report tabbed version')]
formats = ('json', 'yaml', 'xls', 'csv', 'html')
FORMATS = ('json', 'yaml', 'xls', 'csv', 'html')
for format in formats:
opts = []
opts.append(('v', 'version', False, 'Report tabbed version'))
for format in FORMATS:
opts.append(('', format, False, 'Output to %s' % (format.upper())))
@opster.command(options=opts, usage='[FILE] [--FORMAT | FILE]')
def start(in_file=None, out_file=None, **opts):
""" Converts dataset formats """
"""Covertly convert dataset formats"""
opts = Object(**opts)
@@ -35,29 +41,26 @@ def start(in_file=None, out_file=None, **opts):
elif in_file:
in_file = io.open(in_file, 'r')
print in_file.read()
try:
in_file = io.open(in_file)
in_file = io.open(in_file, 'r')
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:
if file_ext.lower() in FORMATS:
setattr(opts, file_ext, True)
else:
print('Import format not supported.')
exit(65)
else:
print('Please provide input.')
exit(65)
_formats_sum = sum(opts[f] for f in formats)
_formats_sum = sum(opts[f] for f in FORMATS)
# Multiple output formats given
if _formats_sum > 1:
+1 -1
View File
@@ -6,7 +6,7 @@
# / /_ / /_/ / _ /_/ /_ /_/ // __// /_/ /
# \__/ \__,_/ /_.___/ /_.___/ \___/ \__,_/
__version__ = '0.0.1'
__version__ = '0.0.2'
__author__ = 'Kenneth Reitz'
__license__ = 'MIT'
__copyright__ = 'Copyright 2010 Kenneth Reitz'
+3
View File
@@ -2,13 +2,16 @@
import sys
class Object(object):
"""Your attributes are belong to us."""
def __init__(self, **entries):
self.__dict__.update(entries)
def __getitem__(self, key):
return getattr(self, key)
def piped():
"""Returns piped input via stdin, else False"""