1 # -*- coding: utf-8 -*-
3 # COPYRIGHT NOTICE STARTS HERE
5 # Copyright 2019 © Samsung Electronics Co., Ltd.
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
19 # COPYRIGHT NOTICE ENDS HERE
24 from distutils.spawn import find_executable
26 from downloader import AbstractDownloader
28 log = logging.getLogger(__name__)
31 class CommandDownloader(AbstractDownloader, ABC):
32 def __init__(self, list_type, cli_tool, *list_args):
33 super().__init__(list_type, *list_args)
34 if not find_executable(cli_tool):
35 raise FileNotFoundError(cli_tool)
39 Download items from list
41 if not self._initial_log():
43 items_left = len(self._missing)
44 error_occurred = False
45 for item, dst_dir in self._data_list.items():
47 self._download_item((item, dst_dir))
48 except subprocess.CalledProcessError as err:
49 log.exception(err.output.decode())
52 log.info('{} {} left to download.'.format(items_left, self._list_type))
54 log.error('{} {} were not downloaded.'.format(items_left, self._list_type))
55 raise RuntimeError('One or more errors occurred')
57 def _download_item(self, item):