+ parser.error('One of --docker, --npm, --http, --rpm, --git or --pypi must be specified')
+
+
+def log_start(item_type):
+ """
+ Log starting message
+ :param item_type: type of resources
+ :return:
+ """
+ log.info('Starting download of {}.'.format(item_type))
+
+
+def handle_download(downloader, check_mode, errorred_lists, start_time):
+ """
+ Handle download of resources
+ :param downloader: downloader to use
+ :param check_mode: run in check mode (boolean)
+ :param errorred_lists: list of data types of failed lists
+ :param start_time: timeit.default_timer() right before download
+ :return: timeit.default_timer() at the end of download
+ """
+ if check_mode:
+ print(downloader.check_table)
+ else:
+ log_start(downloader.list_type)
+ try:
+ downloader.download()
+ except RuntimeError:
+ errorred_lists.append(downloader.list_type)
+ return log_time_interval(start_time, downloader.list_type)
+
+
+def handle_command_download(downloader_class, check_mode, errorred_lists, start_time, *args):
+ """
+ Handle download of resources where shell command is used
+ :param downloader_class: Class of command_downloader.CommandDownloader to use
+ :param check_mode: run in check mode (boolean)
+ :param errorred_lists: list of data types of failed lists
+ :param start_time: timeit.default_timer() right before download
+ :param args: arguments for downloader class initialization
+ :return: timeit.default_timer() at the end of download
+ """
+ try:
+ downloader = downloader_class(*args)
+ return handle_download(downloader, check_mode, errorred_lists, start_time)
+ except FileNotFoundError as err:
+ classname = type(downloader_class).__name__
+ log.exception('Error initializing: {}: {}'.format(classname, err))
+ return timeit.default_timer()
+
+
+def log_time_interval(start, resource_type=''):
+ """
+ Log how long the download took
+ :param start: timeit.default_timer() when interval started
+ :param resource_type: type of data that was downloaded. (empty string for whole download)
+ :return: timeit.default_timer() after logging
+ """
+ e_time = datetime.timedelta(seconds=timeit.default_timer() - start)
+ if resource_type:
+ msg = 'Download of {} took {}\n'.format(resource_type, e_time)
+ else:
+ msg = 'Execution ended. Total elapsed time {}'.format(e_time)
+ log.info(msg)
+ return timeit.default_timer()