diff options
| author | Daniel Santos <dfsantosbu@unal.edu.co> | 2019-10-30 14:13:39 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-30 14:13:39 +0100 |
| commit | c26159d48f60e737ba6e308b3ed88858cd115cc7 (patch) | |
| tree | 96b2578b56df29915234c457f69ce07dfc849009 /src | |
| parent | 34fe72305e0a21c40f03cc718bb5346e87e328f2 (diff) | |
| download | tablib-c26159d48f60e737ba6e308b3ed88858cd115cc7.tar.gz | |
Implement feature new format: Cli. Generate adapter for tabulate. This close issue #340
* Implement feature new format: Cli. Generate adapter for tabulate. This close issue #340
* Write respective tests.
* Correct name Clase Base Test
* Implement missing class method to export cli.
* Remove property headers in method export book Cli.
* Remove cli from list to test Iterable data books.
Diffstat (limited to 'src')
| -rw-r--r-- | src/tablib/core.py | 8 | ||||
| -rw-r--r-- | src/tablib/formats/__init__.py | 3 | ||||
| -rw-r--r-- | src/tablib/formats/_cli.py | 20 |
3 files changed, 30 insertions, 1 deletions
diff --git a/src/tablib/core.py b/src/tablib/core.py index 17d9621..e0c4327 100644 --- a/src/tablib/core.py +++ b/src/tablib/core.py @@ -622,6 +622,14 @@ class Dataset: pass @property + def cli(): + """A CLI table representation of the :class:`Dataset` object. + + .. note:: This method can be used for export only. + """ + pass + + @property def jira(): """A Jira table representation of the :class:`Dataset` object. diff --git a/src/tablib/formats/__init__.py b/src/tablib/formats/__init__.py index 12f2610..b0afeec 100644 --- a/src/tablib/formats/__init__.py +++ b/src/tablib/formats/__init__.py @@ -14,6 +14,7 @@ from . import _tsv as tsv from . import _xls as xls from . import _xlsx as xlsx from . import _yaml as yaml +from . import _cli as cli # xlsx before as xls (xlrd) can also read xlsx -available = (json, xlsx, xls, yaml, csv, dbf, tsv, html, jira, latex, ods, df, rst) +available = (json, xlsx, xls, yaml, csv, dbf, tsv, html, jira, latex, ods, df, rst, cli) diff --git a/src/tablib/formats/_cli.py b/src/tablib/formats/_cli.py new file mode 100644 index 0000000..5441e2f --- /dev/null +++ b/src/tablib/formats/_cli.py @@ -0,0 +1,20 @@ +""" Tablib - CLI Support +""" +from tabulate import tabulate + +title = 'cli' +extensions = ('txt',) + +DEFAULT_FORMAT = 'plain' + +def export_set(dataset, **kwargs): + """Returns CLI representation of Dataset.""" + if( dataset.headers is not None ): + kwargs.setdefault('headers', dataset.headers) + kwargs.setdefault('tablefmt', DEFAULT_FORMAT) + return tabulate( dataset, **kwargs) + +def export_book(dataset, **kwargs): + """Returns CLI representation of Dataset.""" + kwargs.setdefault('tablefmt', DEFAULT_FORMAT) + return tabulate( dataset, **kwargs) |
