Add initial code
[ta/build-tools.git] / tools / script / read_package_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 argparse
17 import sys
18
19 from tools.package import PackageConfigReader
20
21
22 def parse(args):
23     p = argparse.ArgumentParser(
24         description='Read package configuration',
25         formatter_class=argparse.ArgumentDefaultsHelpFormatter)
26     p.add_argument('--config', required=False, help='Package YAML config file path')
27     p.add_argument('--separator', required=False, default=' ',
28                    help='Separator for the resulting stdout list')
29     p.add_argument('package_operation_type', choices=['install', 'uninstall'],
30                    help='list packages by operation type')
31     args = p.parse_args(args)
32     return args
33
34
35 def main(input_args):
36     args = parse(input_args)
37     kwargs = {}
38     if args.config is not None:
39         kwargs['config_file'] = args.config
40     print(args.separator.join(PackageConfigReader(**kwargs).get(args.package_operation_type)))
41
42
43 if __name__ == "__main__":
44     main(sys.argv[1:])