diff --git a/tablib/__init__.py b/tablib/__init__.py index e9bdf69..3f23850 100644 --- a/tablib/__init__.py +++ b/tablib/__init__.py @@ -2,7 +2,7 @@ """ from tablib.core import ( - Databook, Dataset, detect, InvalidDatasetType, - InvalidDimensions, UnsupportedFormat + Databook, Dataset, detect, import_set, + InvalidDatasetType, InvalidDimensions, UnsupportedFormat ) diff --git a/tablib/cli.py b/tablib/cli.py index 4e46eae..f182049 100644 --- a/tablib/cli.py +++ b/tablib/cli.py @@ -14,7 +14,7 @@ from helpers import Struct, piped -FORMATS = ('json', 'yaml', 'xls', 'csv') +FORMATS = [fmt.title for fmt in tablib.formats.FORMATS] opts = [] @@ -32,13 +32,16 @@ def start(in_file=None, out_file=None, **opts): opts = Struct(**opts) if opts.version: - print('Tabbed, Ver. %s' % tabbed.core.__version__) - sys.sys.exit(0) + print('Tabbed, Ver. %s' % tablib.core.__version__) + sys.exit(0) stdin = piped() if stdin: - print stdin + data = tablib.import_set(stdin) + print data.json + # test = tablib.Dataset() + # print test.yaml elif in_file: @@ -81,6 +84,6 @@ def start(in_file=None, out_file=None, **opts): # look for filename - print opts.__dict__ - print in_file - print out_file \ No newline at end of file + # print opts.__dict__ + # print in_file + # print out_file \ No newline at end of file diff --git a/tablib/core.py b/tablib/core.py index 93ca725..5632e69 100644 --- a/tablib/core.py +++ b/tablib/core.py @@ -277,7 +277,20 @@ def detect(stream): except AttributeError: pass return (None, stream) + + +def import_set(stream): + """Return dataset of given stream.""" + (format, stream) = detect(stream) + + try: + data = Dataset() + format.import_set(data, stream) + return data + except AttributeError, e: + return None + class InvalidDatasetType(Exception): "Only Datasets can be added to a DataBook" diff --git a/test_tablib.py b/test_tablib.py index df9f7bd..9e50e6f 100755 --- a/test_tablib.py +++ b/test_tablib.py @@ -314,7 +314,6 @@ class TablibTestCase(unittest.TestCase): self.assertEqual(tablib.detect(_bunk)[0], None) - def test_wipe(self): """Purge a dataset."""