diff --git a/remotezip.py b/remotezip.py index a0a994c..a45f69a 100755 --- a/remotezip.py +++ b/remotezip.py @@ -5,7 +5,6 @@ from itertools import tee import requests -from tabulate import tabulate __all__ = ['RemoteIOError', 'RemoteZip'] @@ -259,12 +258,27 @@ def _list_files(url, support_suffix_range, filenames): with RemoteZip(url, headers={'User-Agent': 'remotezip'}, support_suffix_range=support_suffix_range) as zip: if len(filenames) == 0: filenames = zip.namelist() - data = [('Length', 'DateTime', 'Name')] + data = [] for fname in filenames: zinfo = zip.getinfo(fname) dt = datetime(*zinfo.date_time) data.append((zinfo.file_size, dt.strftime('%Y-%m-%d %H:%M:%S'), zinfo.filename)) - print(tabulate(data, headers='firstrow')) + _printTable(data, ('Length', 'DateTime', 'Name'), '><<') + + +def _printTable(data, header, align): + # get max col width & prepare formatting string + col_w = [len(col) for col in header] + for row in data: + col_w = [max(w, len(str(x))) for w, x in zip(col_w, row)] + fmt = ' '.join('{{:{}{}}}'.format(a, w) + for w, a in zip(col_w, align + '<' * 99)) + # print table + print(fmt.format(*header).rstrip()) + print(fmt.format(*['-' * w for w in col_w])) + for row in data: + print(fmt.format(*row).rstrip()) + print() def _extract_files(url, support_suffix_range, filenames, path): diff --git a/setup.py b/setup.py index 9cf96ac..65c94d4 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name='remotezip', - version='0.12.2', + version='0.12.3', author='Giuseppe Tribulato', author_email='gtsystem@gmail.com', py_modules=['remotezip'], @@ -14,7 +14,7 @@ description='Access zip file content hosted remotely without downloading the full file.', long_description=description, long_description_content_type="text/markdown", - install_requires=["requests", "tabulate"], + install_requires=["requests"], extras_require={ "test": ["requests_mock"], },