OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # |
| 3 # Copyright 2016 Google Inc. |
| 4 # |
| 5 # Use of this source code is governed by a BSD-style license that can be |
| 6 # found in the LICENSE file. |
| 7 |
| 8 |
| 9 """Create the SKP asset.""" |
| 10 |
| 11 |
| 12 import argparse |
| 13 import common |
| 14 import os |
| 15 import shutil |
| 16 import subprocess |
| 17 import utils |
| 18 |
| 19 |
| 20 SKIA_TOOLS = os.path.join(common.INFRA_BOTS_DIR, os.pardir, os.pardir, 'tools') |
| 21 |
| 22 |
| 23 def create_asset(chrome_src_path, browser_executable, target_dir): |
| 24 """Create the asset.""" |
| 25 browser_executable = os.path.realpath(browser_executable) |
| 26 chrome_src_path = os.path.realpath(chrome_src_path) |
| 27 target_dir = os.path.realpath(target_dir) |
| 28 |
| 29 if not os.path.exists(target_dir): |
| 30 os.makedirs(target_dir) |
| 31 |
| 32 with utils.tmp_dir(): |
| 33 if os.environ.get('CHROME_HEADLESS'): |
| 34 # Start Xvfb if running on a bot. |
| 35 try: |
| 36 subprocess.Popen(['sudo', 'Xvfb', ':0', '-screen', '0', '1280x1024x24']) |
| 37 except Exception: |
| 38 # It is ok if the above command fails, it just means that DISPLAY=:0 |
| 39 # is already up. |
| 40 pass |
| 41 |
| 42 webpages_playback_cmd = [ |
| 43 'python', os.path.join(SKIA_TOOLS, 'skp', 'webpages_playback.py'), |
| 44 '--page_sets', 'all', |
| 45 '--browser_executable', browser_executable, |
| 46 '--non-interactive', |
| 47 '--output_dir', os.getcwd(), |
| 48 '--chrome_src_path', chrome_src_path, |
| 49 ] |
| 50 try: |
| 51 subprocess.check_call(webpages_playback_cmd) |
| 52 finally: |
| 53 # Clean up any leftover browser instances. This can happen if there are |
| 54 # telemetry crashes, processes are not always cleaned up appropriately by |
| 55 # the webpagereplay and telemetry frameworks. |
| 56 procs = subprocess.check_output(['ps', 'ax']) |
| 57 for line in procs.splitlines(): |
| 58 if browser_executable in line: |
| 59 pid = line.strip().split(' ')[0] |
| 60 if pid != str(os.getpid()) and not 'python' in line: |
| 61 try: |
| 62 subprocess.check_call(['kill', '-9', pid]) |
| 63 except subprocess.CalledProcessError as e: |
| 64 print e |
| 65 else: |
| 66 print 'Refusing to kill self.' |
| 67 src = os.path.join(os.getcwd(), 'playback', 'skps') |
| 68 for f in os.listdir(src): |
| 69 if f.endswith('.skp'): |
| 70 shutil.copyfile(os.path.join(src, f), os.path.join(target_dir, f)) |
| 71 |
| 72 |
| 73 def main(): |
| 74 parser = argparse.ArgumentParser() |
| 75 parser.add_argument('--target_dir', '-t', required=True) |
| 76 parser.add_argument('--chrome_src_path', '-c', required=True) |
| 77 parser.add_argument('--browser_executable', '-e', required=True) |
| 78 args = parser.parse_args() |
| 79 create_asset(args.chrome_src_path, args.browser_executable, args.target_dir) |
| 80 |
| 81 |
| 82 if __name__ == '__main__': |
| 83 main() |
OLD | NEW |