From d15bd206022c0b4afc3baabc8902f29eb30672a0 Mon Sep 17 00:00:00 2001 From: wuzewu Date: Thu, 21 Mar 2019 11:20:45 +0800 Subject: [PATCH] do not print tips in module manager --- paddle_hub/commands/install.py | 4 +++- paddle_hub/commands/uninstall.py | 5 ++++- paddle_hub/module/manager.py | 24 +++++++++++++++--------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/paddle_hub/commands/install.py b/paddle_hub/commands/install.py index 5fd536cf..51e62e0c 100644 --- a/paddle_hub/commands/install.py +++ b/paddle_hub/commands/install.py @@ -39,8 +39,10 @@ class InstallCommand(BaseCommand): "==")[1] module_name = module_name if "==" not in module_name else module_name.split( "==")[0] - default_module_manager.install_module( + result, tips, module_dir = default_module_manager.install_module( module_name=module_name, module_version=module_version) + print(tips) + return result command = InstallCommand.instance() diff --git a/paddle_hub/commands/uninstall.py b/paddle_hub/commands/uninstall.py index 7d5e39d4..b31bd35c 100644 --- a/paddle_hub/commands/uninstall.py +++ b/paddle_hub/commands/uninstall.py @@ -31,7 +31,10 @@ class UninstallCommand(BaseCommand): def exec(self, argv): module_name = argv[0] - default_module_manager.uninstall_module(module_name=module_name) + result, tips = default_module_manager.uninstall_module( + module_name=module_name) + print(tips) + return result command = UninstallCommand.instance() diff --git a/paddle_hub/module/manager.py b/paddle_hub/module/manager.py index 82bfbe2a..602ef58d 100644 --- a/paddle_hub/module/manager.py +++ b/paddle_hub/module/manager.py @@ -58,8 +58,8 @@ class LocalModuleManager: self.all_modules(update=True) if module_name in self.modules_dict: module_dir = self.modules_dict[module_name] - print("module %s already install in %s" % (module_name, module_dir)) - return + tips = "module %s already install in %s" % (module_name, module_dir) + return True, tips, module_dir url = hub.default_hub_server.get_module_url( module_name, version=module_version) #TODO(wuzewu): add compatibility check @@ -67,21 +67,27 @@ class LocalModuleManager: tips = "can't found module %s" % module_name if module_version: tips += " with version %s" % module_version - print(tips) - return + return False, tips, None - default_downloader.download_file_and_uncompress( + module_dir = default_downloader.download_file_and_uncompress( url=url, save_path=hub.MODULE_HOME, save_name=module_name) + if module_dir: + tips = "Successfully installed %s" % module_name + if module_version: + tips += "-%s" % module_version + return True, tips, module_dir + tips = "Download %s-%s failed" % (module_name, module_version) + return False, tips, module_dir def uninstall_module(self, module_name): self.all_modules(update=True) if not module_name in self.modules_dict: - print("%s is not installed" % module_name) - return - + tips = "%s is not installed" % module_name + return True, tips + tips = "Successfully uninstalled %s" % module_name module_dir = self.modules_dict[module_name] shutil.rmtree(module_dir) - print("Successfully uninstalled %s" % module_name) + return True, tips default_module_manager = LocalModuleManager() -- GitLab