summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.mkd1
-rw-r--r--tabbed/__init__.py5
-rw-r--r--tabbed/cli.py77
-rw-r--r--tabbed/core.py7
-rw-r--r--tabbed/helpers.py10
5 files changed, 85 insertions, 15 deletions
diff --git a/README.mkd b/README.mkd
index a838f53..1520e40 100644
--- a/README.mkd
+++ b/README.mkd
@@ -17,7 +17,6 @@ Formats supported:
- YAML
- Excel
- CSV
- - CDL
- HTML
Please note that tabbed _purposefully_ excludes XML support. It always will.
diff --git a/tabbed/__init__.py b/tabbed/__init__.py
index d5b8469..5d20240 100644
--- a/tabbed/__init__.py
+++ b/tabbed/__init__.py
@@ -1,4 +1 @@
-__version__ = '0.0.1'
-__author__ = 'Kenneth Reitz'
-__license__ = 'MIT'
-__copyright__ = 'Copyright 2010 Kenneth Reitz'
+from core import * \ No newline at end of file
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
diff --git a/tabbed/core.py b/tabbed/core.py
index dd3d378..4df9ae1 100644
--- a/tabbed/core.py
+++ b/tabbed/core.py
@@ -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'
diff --git a/tabbed/helpers.py b/tabbed/helpers.py
index a5ea86c..a80b574 100644
--- a/tabbed/helpers.py
+++ b/tabbed/helpers.py
@@ -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