From 8c38f351674c99d00f4850329ab9589bed63340c Mon Sep 17 00:00:00 2001 From: Radovan Bast Date: Mon, 22 Jun 2015 09:24:39 +0200 Subject: [PATCH] fix for division by 0 problem for projects without any modules --- update.py | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/update.py b/update.py index 881cf9b..7f65884 100755 --- a/update.py +++ b/update.py @@ -194,31 +194,34 @@ def fetch_modules(config, module_directory): config.sections())) n = len(l) - i = 0 - print_progress_bar(text='- fetching modules:', done=0, total=n, width=30) list_of_modules = [] - for section in config.sections(): - if config.has_option(section, 'source'): - for src in config.get(section, 'source').split('\n'): - module_name = os.path.basename(src) - list_of_modules.append(module_name) - dst = os.path.join(module_directory, 'autocmake_%s' % module_name) - if 'http' in src: - fetch_url(src, dst) - else: - if os.path.exists(src): - shutil.copyfile(src, dst) + + if n > 0: # otherwise division by zero in print_progress_bar + i = 0 + print_progress_bar(text='- fetching modules:', done=0, total=n, width=30) + for section in config.sections(): + if config.has_option(section, 'source'): + for src in config.get(section, 'source').split('\n'): + module_name = os.path.basename(src) + list_of_modules.append(module_name) + dst = os.path.join(module_directory, 'autocmake_%s' % module_name) + if 'http' in src: + fetch_url(src, dst) else: - sys.stderr.write("ERROR: %s does not exist\n" % src) - sys.exit(-1) - i += 1 - print_progress_bar( - text='- fetching modules:', - done=i, - total=n, - width=30 - ) - print('') + if os.path.exists(src): + shutil.copyfile(src, dst) + else: + sys.stderr.write("ERROR: %s does not exist\n" % src) + sys.exit(-1) + i += 1 + print_progress_bar( + text='- fetching modules:', + done=i, + total=n, + width=30 + ) + print('') + return list_of_modules