From 84c66d30672cc99c9e627f69eacf35e4f074554d Mon Sep 17 00:00:00 2001 From: Yuxin Wang Date: Wed, 26 Sep 2018 17:52:02 -0400 Subject: [PATCH] Print tabulate instead of pure objects. --- p2pfs/ui/terminal.py | 15 ++++++++++++--- setup.py | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/p2pfs/ui/terminal.py b/p2pfs/ui/terminal.py index de48500..70e93ab 100644 --- a/p2pfs/ui/terminal.py +++ b/p2pfs/ui/terminal.py @@ -1,4 +1,5 @@ -import cmd, sys +import cmd +from tabulate import tabulate from p2pfs.core.tracker import Tracker from p2pfs.core.peer import Peer @@ -13,10 +14,18 @@ class TrackerTerminal(cmd.Cmd): self._tracker = tracker def do_list_files(self, arg): - print(self._tracker.file_list()) + file_list_dict = self._tracker.file_list() + file_list = [] + headers = ['Filename'] + for filename, fileinfo in file_list_dict.items(): + if len(headers) == 1: + headers.extend(tuple(map(lambda x: x.capitalize(), tuple(fileinfo.keys())))) + file_list.append((filename, ) + tuple(fileinfo.values())) + + print(tabulate(file_list, headers=headers)) def do_list_peers(self, arg): - print(self._tracker.peers()) + print(tabulate(self._tracker.peers(), headers=['UUID', 'IP/Port'])) def do_list_chunkinfo(self, arg): print(self._tracker.chunkinfo()) diff --git a/setup.py b/setup.py index 3b9b91d..2cbb175 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ setup( ], keywords='P2P, Networking', packages=find_packages(exclude=['tests']), - install_requires=['pybase64', 'coloredlogs'], + install_requires=['pybase64', 'coloredlogs', 'tabulate'], entry_points={ 'console_scripts': [ 'p2pfs=p2pfs.__main__:main',