diff --git a/paddlehub/commands/cml_utils.py b/paddlehub/commands/cml_utils.py index 7d7c9a1f00bc8c94b6e6f92dea06f4aaf4e64553..5b2fb908ab4f12188698ce1ab18fc58c57a8ca15 100644 --- a/paddlehub/commands/cml_utils.py +++ b/paddlehub/commands/cml_utils.py @@ -16,7 +16,9 @@ from __future__ import absolute_import from __future__ import division from __future__ import print_function -color_dict = { +from paddlehub.common.utils import is_windows + +linux_color_dict = { "white": "\033[1;37m%s\033[0m", "black": "\033[30m%s\033[0m", "dark_gray": "\033[1;30m%s\033[0m", @@ -35,8 +37,17 @@ color_dict = { "yellow": "\033[1;33m%s\033[0m" } +windows_color_dict = {key: "%s" for key in linux_color_dict} + + +def get_color_dict(): + if is_windows(): + return windows_color_dict + return linux_color_dict + def colorful_text(color, text): + color_dict = get_color_dict() if color not in color_dict: color = color_dict['blue'] else: @@ -44,6 +55,12 @@ def colorful_text(color, text): return color % text +def get_ph_value(): + if is_windows(): + return 0 + return 11 + + class TablePrinter: def __init__(self, titles, @@ -76,7 +93,7 @@ class TablePrinter: for index, title in enumerate(self.titles): if self.title_colors[index]: title = colorful_text(self.title_colors[index], title) - _ph = 11 + _ph = get_ph_value() else: _ph = 0 title_text += ("{0:%s%d}|" % @@ -108,7 +125,7 @@ class TablePrinter: split_text = content[offset[index]:offset[index] + length] if colors[index] and split_text: split_text = colorful_text(colors[index], split_text) - _ph = 11 + _ph = get_ph_value() else: _ph = 0 diff --git a/paddlehub/commands/list.py b/paddlehub/commands/list.py index fc15ba25758b345689c38bab0663d513575a8a28..0c2ec37e3ab529c92890a9fb59102dc22cb3a38c 100644 --- a/paddlehub/commands/list.py +++ b/paddlehub/commands/list.py @@ -34,7 +34,12 @@ class ListCommand(BaseCommand): def exec(self, argv): all_modules = default_module_manager.all_modules() - tp = TablePrinter(titles=["ModuleName", "Path"], placeholders=[25, 50]) + if utils.is_windows(): + placeholders = [20, 40] + else: + placeholders = [25, 50] + tp = TablePrinter( + titles=["ModuleName", "Path"], placeholders=placeholders) for module_name, module_dir in all_modules.items(): tp.add_line(contents=[module_name, module_dir]) print(tp.get_text()) diff --git a/paddlehub/commands/search.py b/paddlehub/commands/search.py index 40a0b4003a0957ac05f01ec6c5c506453576ff79..be69fa4f21c063e499e731de21758d4e6a40b2ea 100644 --- a/paddlehub/commands/search.py +++ b/paddlehub/commands/search.py @@ -44,9 +44,13 @@ class SearchCommand(BaseCommand): resource_name = argv[0] resource_list = default_hub_server.search_resource(resource_name) + if utils.is_windows(): + placeholders = [20, 8, 8, 20] + else: + placeholders = [30, 8, 8, 25] tp = TablePrinter( titles=["ResourceName", "Type", "Version", "Summary"], - placeholders=[30, 8, 8, 25]) + placeholders=placeholders) for resource_name, resource_type, resource_version, resource_summary in resource_list: if resource_type == "Module": colors = ["yellow", None, None, None] diff --git a/paddlehub/commands/show.py b/paddlehub/commands/show.py index c9f2b7616b2587bf9d38b14be7ba971fb98ac5bd..9d53abd073f42a2820f808353d76f249705ed423 100644 --- a/paddlehub/commands/show.py +++ b/paddlehub/commands/show.py @@ -20,6 +20,7 @@ import os import argparse from paddlehub.common.logger import logger +from paddlehub.common import utils from paddlehub.commands.base_command import BaseCommand, ENTRY from paddlehub.commands.cml_utils import TablePrinter from paddlehub.module.manager import default_module_manager @@ -42,9 +43,13 @@ class ShowCommand(BaseCommand): def show_model_info(self, model_info_file): model_info = yaml_parser.parse(model_info_file) + if utils.is_windows(): + placeholders = [15, 40] + else: + placeholders = [15, 50] tp = TablePrinter( titles=["ModelName", model_info['name']], - placeholders=[15, 50], + placeholders=placeholders, title_colors=["yellow", None], title_aligns=["^", "<"]) tp.add_line( @@ -72,9 +77,13 @@ class ShowCommand(BaseCommand): def show_module_info(self, module_dir): module = Module(module_dir=module_dir) + if utils.is_windows(): + placeholders = [15, 40] + else: + placeholders = [15, 50] tp = TablePrinter( titles=["ModuleName", module.name], - placeholders=[15, 50], + placeholders=placeholders, title_colors=["light_red", None], title_aligns=["^", "<"]) tp.add_line( diff --git a/paddlehub/common/utils.py b/paddlehub/common/utils.py index 39e0ed5700e9af574fa48d65dddc86e877c841ec..92fd470bc589618d8ec71cdf83961469c4809bab 100644 --- a/paddlehub/common/utils.py +++ b/paddlehub/common/utils.py @@ -20,6 +20,7 @@ import os import time import multiprocessing import hashlib +import platform import paddle import paddle.fluid as fluid @@ -28,6 +29,14 @@ from paddlehub.module import module_desc_pb2 from paddlehub.common.logger import logger +def get_platform(): + return platform.platform() + + +def is_windows(): + return get_platform().lower().startswith("windows") + + def to_list(input): if not isinstance(input, list): if not isinstance(input, tuple):