Merge "Add prepare-docker-dind role"
[oom/offline-installer.git] / build / download / rpm_packages.py
1 #! /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
22 import argparse
23 import subprocess
24 import logging
25 import sys
26 import os
27
28 import base
29
30 log = logging.getLogger(name=__name__)
31
32
33 def download(rpm_list, dst_dir):
34     if not base.check_tool('yumdownloader'):
35         log.error('ERROR: yumdownloader is not installed')
36         return 1
37
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())
44         log.info('Downloaded')
45     except subprocess.CalledProcessError as err:
46         log.error(err.output)
47         return err.returncode
48
49
50
51 def run_cli():
52     parser = argparse.ArgumentParser(description='Download rpm packages from list')
53     parser.add_argument('rpm_list', metavar='rpm-list',
54                         help='File with list of npm packages to download.')
55     parser.add_argument('--output-dir', '-o', default=os.getcwd(),
56                         help='Download destination')
57
58     args = parser.parse_args()
59
60     logging.basicConfig(stream=sys.stdout, level=logging.INFO, format='%(message)s')
61
62     sys.exit(download(args.rpm_list, args.output_dir))
63
64
65 if __name__ == '__main__':
66     run_cli()