1#!/usr/bin/python3 2# Copyright 2021 Google LLC 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"""Script for writing from project.yaml to .labels file.""" 16 17import os 18import json 19import sys 20 21 22def main(): 23 """Writes labels.""" 24 if len(sys.argv) != 3: 25 print('Usage: write_labels.py labels_json out_dir', file=sys.stderr) 26 sys.exit(1) 27 28 labels_by_target = json.loads(sys.argv[1]) 29 out = sys.argv[2] 30 31 for target_name, labels in labels_by_target.items(): 32 with open(os.path.join(out, target_name + '.labels'), 'w') as file_handle: 33 file_handle.write('\n'.join(labels)) 34 35 36if __name__ == '__main__': 37 main() 38