blob: 732af0ea306c19469333002d8d3a99c89238d712 [file] [log] [blame]
Milan Verespeje0227c22019-05-17 14:14:21 +02001#! /usr/bin/env python
2# -*- coding: utf-8 -*-
3
4# COPYRIGHT NOTICE STARTS HERE
5
6# Copyright 2019 © Samsung Electronics Co., Ltd.
7#
8# Licensed under the Apache License, Version 2.0 (the "License");
9# you may not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS,
16# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19
20# COPYRIGHT NOTICE ENDS HERE
21
22import argparse
23import subprocess
24import logging
25import sys
26import os
27
28import base
29
30log = logging.getLogger(name=__name__)
31
32
33def download(rpm_list, dst_dir):
34 if not base.check_tool('yumdownloader'):
35 log.error('ERROR: yumdownloader is not installed')
Milan Verespej455be472019-05-23 14:21:19 +020036 raise RuntimeError('yumdownloader missing')
Milan Verespeje0227c22019-05-17 14:14:21 +020037
38 rpm_set = base.load_list(rpm_list)
39
40 command = 'yumdownloader --destdir={} {}'.format(dst_dir, ' '.join(rpm_set))
41 log.info('Running command: {}'.format(command))
42 try:
43 subprocess.check_call(command.split())
Milan Verespeje0227c22019-05-17 14:14:21 +020044 except subprocess.CalledProcessError as err:
Milan Verespej455be472019-05-23 14:21:19 +020045 log.exception(err.output)
46 raise err
47 log.info('Downloaded')
Milan Verespeje0227c22019-05-17 14:14:21 +020048
49
50def run_cli():
51 parser = argparse.ArgumentParser(description='Download rpm packages from list')
52 parser.add_argument('rpm_list', metavar='rpm-list',
53 help='File with list of npm packages to download.')
54 parser.add_argument('--output-dir', '-o', default=os.getcwd(),
55 help='Download destination')
56
57 args = parser.parse_args()
58
59 logging.basicConfig(stream=sys.stdout, level=logging.INFO, format='%(message)s')
60
Milan Verespej455be472019-05-23 14:21:19 +020061 try:
62 download(args.rpm_list, args.output_dir)
63 except (subprocess.CalledProcessError, RuntimeError):
64 sys.exit(1)
65
Milan Verespeje0227c22019-05-17 14:14:21 +020066
67
68if __name__ == '__main__':
69 run_cli()