mirror of
https://github.com/kennethreitz/tablib.git
synced 2026-06-05 23:10:17 +00:00
cli | paing coming along
This commit is contained in:
@@ -17,7 +17,6 @@ Formats supported:
|
||||
- YAML
|
||||
- Excel
|
||||
- CSV
|
||||
- CDL
|
||||
- HTML
|
||||
|
||||
Please note that tabbed _purposefully_ excludes XML support. It always will.
|
||||
|
||||
+1
-4
@@ -1,4 +1 @@
|
||||
__version__ = '0.0.1'
|
||||
__author__ = 'Kenneth Reitz'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright 2010 Kenneth Reitz'
|
||||
from core import *
|
||||
+68
-9
@@ -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')]
|
||||
|
||||
opts = (
|
||||
('v', 'version', False, 'Report tabbed version'),
|
||||
('', 'to', False, 'Output format')
|
||||
)
|
||||
formats = ('json', 'yaml', 'xls', 'csv', 'html')
|
||||
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
print opts.__dict__
|
||||
print in_file
|
||||
print out_file
|
||||
+6
-1
@@ -1,7 +1,12 @@
|
||||
from tabbed.core import *
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# _____ ______ ______ _________
|
||||
# __ /_______ ____ /_ ___ /_ _____ ______ /
|
||||
# _ __/_ __ `/__ __ \__ __ \_ _ \_ __ /
|
||||
# / /_ / /_/ / _ /_/ /_ /_/ // __// /_/ /
|
||||
# \__/ \__,_/ /_.___/ /_.___/ \___/ \__,_/
|
||||
|
||||
__version__ = '0.0.1'
|
||||
__author__ = 'Kenneth Reitz'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright 2010 Kenneth Reitz'
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
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"""
|
||||
|
||||
with sys.stdin as stdin:
|
||||
return stdin.read() if not stdin.isatty() else None
|
||||
|
||||
Reference in New Issue
Block a user