1#!/usr/bin/env python3 2# Copyright (C) 2022 The Android Open Source Project 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 16import argparse 17import sys 18import urllib.request 19from os import path 20 21 22def get_artifact_url(run, name): 23 return f'https://storage.googleapis.com/perfetto-ci-artifacts/{run}/ui-test-artifacts/{name}' 24 25 26def main(): 27 parser = argparse.ArgumentParser() 28 parser.add_argument('run', metavar='RUN', help='CI run identifier') 29 args = parser.parse_args() 30 31 with urllib.request.urlopen(get_artifact_url(args.run, 'report.txt')) as resp: 32 handle_report(resp.read().decode('utf-8'), args.run) 33 34 35def handle_report(report: str, run: str): 36 for line in report.split('\n'): 37 if len(line) == 0: 38 continue 39 40 parts = line.split(';') 41 if len(parts) != 2: 42 print('Erroneous report line!') 43 sys.exit(1) 44 45 screenshot_name = parts[0] 46 url = get_artifact_url(run, screenshot_name) 47 output_path = path.join('test', 'data', 'ui-screenshots', screenshot_name) 48 print(f'Downloading {url}') 49 urllib.request.urlretrieve(url, output_path) 50 print('Done. Now run:') 51 print('./tools/test_data upload') 52 53 54if __name__ == "__main__": 55 main() 56