Pin pip to 20.3.3 and disable tmpfs in DIB
[ta/build-tools.git] / mock2rpmbuild_config.py
1 #!/usr/bin/env python
2 # Copyright 2019 Nokia
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 import re
17 import sys
18 import argparse
19
20
21 def parse(args):
22     p = argparse.ArgumentParser(
23         description='Parse RPM macro definitions from mock '
24                     'config and write a file for "rpmbuild" to process')
25     p.add_argument('--mock-config', required=True)
26     p.add_argument('--output-file-path', required=True)
27     args = p.parse_args(args)
28     return args
29
30
31 def main(input_args):
32     args = parse(input_args)
33     with open(args.mock_config, 'r') as f:
34         data = f.read()
35     with open(args.output_file_path, 'w') as f:
36         for macro, expr in re.findall(
37                 r'^\s*config_opts\[[\'"]macros[\'"]\]\[[\'"](.*)[\'"]\]\s*=\s*[\'"](.*)[\'"]\s*$',
38                 data, re.MULTILINE):
39             f.write('{} {}\n'.format(macro, expr))
40     print('Wrote ' + args.output_file_path)
41
42
43 if __name__ == "__main__":
44     main(sys.argv[1:])