diff --git a/paddlehub/common/downloader.py b/paddlehub/common/downloader.py index 28b42732c5d70133e503559306e466f5ff537d96..129cda0ceabcf931aea9b71bb9d1b6efb510518c 100644 --- a/paddlehub/common/downloader.py +++ b/paddlehub/common/downloader.py @@ -29,7 +29,7 @@ import tarfile from paddlehub.common import utils from paddlehub.common.logger import logger -__all__ = ['Downloader'] +__all__ = ['Downloader', 'progress'] FLUSH_INTERVAL = 0.1 lasttime = time.time() diff --git a/paddlehub/module/module.py b/paddlehub/module/module.py index f6e62f97b38f606032089370b7259715c5b05973..948d8337310c3a7725ec5c17c488214b04008572 100644 --- a/paddlehub/module/module.py +++ b/paddlehub/module/module.py @@ -37,6 +37,7 @@ from paddlehub.common.lock import lock from paddlehub.common.logger import logger from paddlehub.common.hub_server import CacheUpdater from paddlehub.common import tmp_dir +from paddlehub.common.downloader import progress from paddlehub.module import module_desc_pb2 from paddlehub.module.manager import default_module_manager from paddlehub.module.checker import ModuleChecker @@ -99,10 +100,22 @@ def create_module(directory, name, author, email, module_type, summary, _cwd = os.getcwd() os.chdir(base_dir) - for dirname, _, files in os.walk(module_dir): - for file in files: - tar.add(os.path.join(dirname, file).replace(base_dir, ".")) - + module_dir = module_dir.replace(base_dir, ".") + tar.add(module_dir, recursive=False) + files = [] + for dirname, _, subfiles in os.walk(module_dir): + for file in subfiles: + files.append(os.path.join(dirname, file)) + + total_length = len(files) + print("Create Module {}-{}".format(name, version)) + for index, file in enumerate(files): + done = int(float(index) / total_length * 50) + progress("[%-50s] %.2f%%" % ('=' * done, + float(index / total_length * 100))) + tar.add(file) + progress("[%-50s] %.2f%%" % ('=' * 50, 100), end=True) + print("Module package saved as {}".format(save_file)) os.chdir(_cwd)