diff options
| author | Daniel Santos <dfsantosbu@unal.edu.co> | 2019-10-30 12:50:33 +0100 |
|---|---|---|
| committer | Daniel Santos <dfsantosbu@unal.edu.co> | 2019-10-30 12:52:43 +0100 |
| commit | 19b3d875fddc4e9d4e94741dc9a5b98c76dc9087 (patch) | |
| tree | 96c06100883dbb6b4bbdb6103b240f40ca847ec4 /src/tablib | |
| parent | 34fe72305e0a21c40f03cc718bb5346e87e328f2 (diff) | |
| download | tablib-19b3d875fddc4e9d4e94741dc9a5b98c76dc9087.tar.gz | |
Implement feature new format: Cli. Generate adapter for tabulate. This close issue #340
Write respective tests.
Diffstat (limited to 'src/tablib')
| -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 | 16 |
3 files changed, 26 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..e00d4db --- /dev/null +++ b/src/tablib/formats/_cli.py @@ -0,0 +1,16 @@ +""" 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) + |
