X-Git-Url: https://gerrit.akraino.org/r/gitweb?p=ta%2Fbuild-tools.git;a=blobdiff_plain;f=mock2rpmbuild_config.py;fp=mock2rpmbuild_config.py;h=101b8d14d6aa713e74a8609d691a862fc5b8800d;hp=0000000000000000000000000000000000000000;hb=900738828f48bade06f69c1e3a8f6fb988b97950;hpb=c9329b7df4c8a39f97f0c16fc2b14b3ca25d9896 diff --git a/mock2rpmbuild_config.py b/mock2rpmbuild_config.py new file mode 100755 index 0000000..101b8d1 --- /dev/null +++ b/mock2rpmbuild_config.py @@ -0,0 +1,44 @@ +#!/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:])