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