diff --git a/paddle_hub/commands/install.py b/paddle_hub/commands/install.py index 5fd536cfbc9ae67837afac5ca415b60c83038289..51e62e0c164631d44410de09e358f15a71abcb94 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 7d5e39d4d23b820a302d0c3aa03d299f10c19f9d..b31bd35c83d35491b201e1090c6cae1e7e23068f 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 82bfbe2a5c04fac23c59eb702df9aceffbf6f041..602ef58dc332048c8c7a251d8b7a400f9ff74cb7 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()