1*8975f5c5SAndroid Build Coastguard Worker#!/usr/bin/env python3 2*8975f5c5SAndroid Build Coastguard Worker# Copyright 2021 The Chromium Authors 3*8975f5c5SAndroid Build Coastguard Worker# Use of this source code is governed by a BSD-style license that can be 4*8975f5c5SAndroid Build Coastguard Worker# found in the LICENSE file. 5*8975f5c5SAndroid Build Coastguard Worker"""Script to generate yaml file based on FILES.cfg.""" 6*8975f5c5SAndroid Build Coastguard Worker 7*8975f5c5SAndroid Build Coastguard Workerimport argparse 8*8975f5c5SAndroid Build Coastguard Workerimport os 9*8975f5c5SAndroid Build Coastguard Worker 10*8975f5c5SAndroid Build Coastguard Worker 11*8975f5c5SAndroid Build Coastguard Workerdef _ParseFilesCfg(files_file): 12*8975f5c5SAndroid Build Coastguard Worker """Return the dictionary of archive file info read from the given file.""" 13*8975f5c5SAndroid Build Coastguard Worker if not os.path.exists(files_file): 14*8975f5c5SAndroid Build Coastguard Worker raise IOError('Files list does not exist (%s).' % files_file) 15*8975f5c5SAndroid Build Coastguard Worker exec_globals = {'__builtins__': None} 16*8975f5c5SAndroid Build Coastguard Worker 17*8975f5c5SAndroid Build Coastguard Worker exec(open(files_file).read(), exec_globals) 18*8975f5c5SAndroid Build Coastguard Worker return exec_globals['FILES'] 19*8975f5c5SAndroid Build Coastguard Worker 20*8975f5c5SAndroid Build Coastguard Worker 21*8975f5c5SAndroid Build Coastguard Workerdef _Process(args): 22*8975f5c5SAndroid Build Coastguard Worker yaml_content = ('package: ' + args.package + '\ndescription: ' + 23*8975f5c5SAndroid Build Coastguard Worker args.description + '\ninstall_mode: ' + args.install_mode + 24*8975f5c5SAndroid Build Coastguard Worker '\ndata:\n') 25*8975f5c5SAndroid Build Coastguard Worker fileobj = _ParseFilesCfg(args.files_file) 26*8975f5c5SAndroid Build Coastguard Worker for item in fileobj: 27*8975f5c5SAndroid Build Coastguard Worker if 'buildtype' in item: 28*8975f5c5SAndroid Build Coastguard Worker if args.buildtype not in item['buildtype']: 29*8975f5c5SAndroid Build Coastguard Worker continue 30*8975f5c5SAndroid Build Coastguard Worker if 'arch' in item: 31*8975f5c5SAndroid Build Coastguard Worker if args.arch not in item['arch']: 32*8975f5c5SAndroid Build Coastguard Worker continue 33*8975f5c5SAndroid Build Coastguard Worker if 'type' in item and item['type'] == 'folder': 34*8975f5c5SAndroid Build Coastguard Worker yaml_content += ' - dir: ' + item['filename'] + '\n' 35*8975f5c5SAndroid Build Coastguard Worker else: 36*8975f5c5SAndroid Build Coastguard Worker yaml_content += ' - file: ' + item['filename'] + '\n' 37*8975f5c5SAndroid Build Coastguard Worker 38*8975f5c5SAndroid Build Coastguard Worker with open(args.output_yaml_file, 'w') as f: 39*8975f5c5SAndroid Build Coastguard Worker f.write(yaml_content) 40*8975f5c5SAndroid Build Coastguard Worker 41*8975f5c5SAndroid Build Coastguard Worker 42*8975f5c5SAndroid Build Coastguard Workerdef main(): 43*8975f5c5SAndroid Build Coastguard Worker parser = argparse.ArgumentParser() 44*8975f5c5SAndroid Build Coastguard Worker parser.add_argument('--output_yaml_file', help='File to create.') 45*8975f5c5SAndroid Build Coastguard Worker parser.add_argument( 46*8975f5c5SAndroid Build Coastguard Worker '--package', 47*8975f5c5SAndroid Build Coastguard Worker help='The path where the package will be located inside the CIPD\ 48*8975f5c5SAndroid Build Coastguard Worker repository.') 49*8975f5c5SAndroid Build Coastguard Worker parser.add_argument( 50*8975f5c5SAndroid Build Coastguard Worker '--description', 51*8975f5c5SAndroid Build Coastguard Worker help='Sets the "description" field in CIPD package definition.') 52*8975f5c5SAndroid Build Coastguard Worker parser.add_argument('--install_mode', 53*8975f5c5SAndroid Build Coastguard Worker help='String, should be either "symlink" or "copy".') 54*8975f5c5SAndroid Build Coastguard Worker parser.add_argument('--files_file', 55*8975f5c5SAndroid Build Coastguard Worker help='FILES.cfg describes what files to include.') 56*8975f5c5SAndroid Build Coastguard Worker parser.add_argument('--buildtype', help='buildtype for FILES.cfg.') 57*8975f5c5SAndroid Build Coastguard Worker parser.add_argument('--arch', help='arch for FILES.cfg') 58*8975f5c5SAndroid Build Coastguard Worker 59*8975f5c5SAndroid Build Coastguard Worker args = parser.parse_args() 60*8975f5c5SAndroid Build Coastguard Worker 61*8975f5c5SAndroid Build Coastguard Worker _Process(args) 62*8975f5c5SAndroid Build Coastguard Worker 63*8975f5c5SAndroid Build Coastguard Worker 64*8975f5c5SAndroid Build Coastguard Workerif __name__ == '__main__': 65*8975f5c5SAndroid Build Coastguard Worker main() 66