1# Copyright (C) 2023 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15import sys 16import json 17 18 19def main(): 20 [_, channel_name, rev] = sys.argv 21 22 with open('channels.json', 'r') as f: 23 channels_json = json.load(f) 24 25 found = False 26 for channel in channels_json['channels']: 27 if channel['name'] == channel_name: 28 if channel['rev'] == rev: 29 print(f'Channel {channel_name} is already at {rev}!') 30 return 31 channel['rev'] = rev 32 found = True 33 break 34 35 if not found: 36 print(f'Failed to find channel {channel_name}!') 37 return 38 39 with open('channels.json', 'w') as f: 40 json.dump(channels_json, f, indent=2) 41 # Right now channels.json ends with two line breaks, 42 # keep it that way to minimise diffs. 43 f.write('\n\n') 44 45 46if __name__ == "__main__": 47 main() 48