#!/usr/bin/env python # Copyright 2019 Nokia # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import re import sys import argparse def parse(args): p = argparse.ArgumentParser( description='Parse RPM macro definitions from mock ' 'config and write a file for "rpmbuild" to process') p.add_argument('--mock-config', required=True) p.add_argument('--output-file-path', required=True) args = p.parse_args(args) return args def main(input_args): args = parse(input_args) with open(args.mock_config, 'r') as f: data = f.read() with open(args.output_file_path, 'w') as f: for macro, expr in re.findall( r'^\s*config_opts\[[\'"]macros[\'"]\]\[[\'"](.*)[\'"]\]\s*=\s*[\'"](.*)[\'"]\s*$', data, re.MULTILINE): f.write('{} {}\n'.format(macro, expr)) print('Wrote ' + args.output_file_path) if __name__ == "__main__": main(sys.argv[1:])