summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Reitz <me@kennethreitz.com>2010-09-25 18:35:10 -0400
committerKenneth Reitz <me@kennethreitz.com>2010-09-25 18:35:10 -0400
commita310ab7a09e2444d146877d27e0bba6872866b8b (patch)
tree90cf74ffb080959c634ab066297ee4d295bc0954
parent7f2f925ddb7d47192b79204ccf80e8a9c42f1601 (diff)
downloadtablib-a310ab7a09e2444d146877d27e0bba6872866b8b.tar.gz
Added tablib.import_set() and tested accordingly.
-rw-r--r--tablib/__init__.py4
-rw-r--r--tablib/cli.py17
-rw-r--r--tablib/core.py13
-rwxr-xr-xtest_tablib.py1
4 files changed, 25 insertions, 10 deletions
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."""