Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(414)

Side by Side Diff: tools/blink_rename_merge_helper/run.py

Issue 2802743003: blink_rename_merge_helper: Implement run.py loader stub (Closed)
Patch Set: . Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/blink_rename_merge_helper/pylib/blink_rename_merge_helper/driver.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2017 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5 """Tool to help developers rebase branches across the Blink rename."""
6
7 import json
8 import os
9 import subprocess
10 import shutil
11 import sys
12 import tempfile
13
14
15 class _DepotToolsNotFoundException(Exception):
16 pass
17
18
19 def _whereis(name):
20 """Find and return the first entry in $PATH containing a file named |name|.
21
22 Returns the path if found; otherwise returns nothing.
23 """
24 for path in os.environ['PATH'].split(os.pathsep):
25 if os.path.exists(os.path.join(path, name)):
26 return path
27
28
29 def _find_depot_tools():
30 """Attempts to configure and return a wrapper for invoking depot tool helpers.
31
32 Returns:
33 A helper object for invoking depot tool utils."""
danakj 2017/04/05 22:38:59 Do you need to say what exceptions it can throw? #
dcheng 2017/04/05 22:44:57 It should... I was being lazy. Fixed.
34
35 class DepotToolsWrapper(object):
36
37 def __init__(self, path):
38 self.__download_from_google_storage = os.path.join(
39 path, 'download_from_google_storage.py')
40 self.__gsutil = os.path.join(path, 'gsutil.py')
41
42 def call_download_from_google_storage(self, *args):
43 """Runs download_from_google_storage with the given args."""
44 subprocess.check_call(['python', self.__download_from_google_storage] +
45 list(args))
46
47 def call_gsutil(self, *args):
48 """Runs gsutil with the given args."""
49 subprocess.check_call(['python', self.__gsutil] + list(args))
50
51 # Attempt to find download_from_google_storage.py from depot_tools
52 path = _whereis('download_from_google_storage.py')
53 if not path:
54 raise _DepotToolsNotFoundException(
55 'download_from_google_storage.py not found. Make sure depot_tools is '
56 'in $PATH.'
57 )
58
59 # Make sure gsutil.py is in the same location
60 path2 = _whereis('download_from_google_storage.py')
61 if not path:
danakj 2017/04/05 22:38:59 if not path2
dcheng 2017/04/05 22:44:57 Done.
62 raise _DepotToolsNotFoundException(
63 'gsutil.py not found. Make sure depot_tools is in $PATH.')
64
65 if path != path2:
66 raise _DepotToolsNotFoundException(
67 'download_from_google_storage.py found in %s but gsutil.py found in %s.'
68 % (path, path2))
69
70 return DepotToolsWrapper(path)
71
72
73 class Bootstrapper(object):
74 """Helper class for bootstrapping startup of the rebase helper.
75
76 Performs update checks and stages any required binaries."""
77
78 def __init__(self, depot_tools):
79 """Bootstrapper constructor.
80
81 Args:
82 depot_tools: a wrapper for invoking depot_tools.
83 """
84 self.__depot_tools = depot_tools
85 self.__tmpdir = None
86
87 def __enter__(self):
88 self.__tmpdir = tempfile.mkdtemp()
89 return self
90
91 def __exit__(self, exc_type, exc_value, traceback):
92 shutil.rmtree(self.__tmpdir, ignore_errors=True)
93
94 def update(self):
95 """Performs an update check for various components."""
96 components = self._get_latest_components()
97 for name, sha1_hash in components.iteritems():
98 args = [
99 '--no_auth', '--no_resume', '-b', 'chromium-blink-rename',
100 '--extract', sha1_hash
101 ]
102 if '-' in name:
103 name, platform = name.split('-', 1)
104 args.append('-p')
105 args.append(platform)
106 args.append('-o')
107 args.append(os.path.join('staging', '%s.tar.gz' % name))
108 self.__depot_tools.call_download_from_google_storage(*args)
109
110 def _get_latest_components(self):
111 """Fetches info about the latest components from google storage.
112
113 The return value should be a dict of component names to SHA1 hashes."""
114 hashes_path = os.path.join(self.__tmpdir, 'COMPONENTS')
115 self.__depot_tools.call_gsutil(
116 'cp', 'gs://chromium-blink-rename/COMPONENTS', hashes_path)
117 with open(hashes_path) as f:
118 return json.loads(f.read())
119
120
121 def main():
122 script_dir = os.path.dirname(os.path.realpath(__file__))
123 os.chdir(script_dir)
124
125 try:
126 depot_tools = _find_depot_tools()
127 except _DepotToolsNotFoundException:
128 return 1
danakj 2017/04/05 22:38:59 does this need to print the exception's text or do
dcheng 2017/04/05 22:44:57 Doh, done. (I wasn't using exceptions originally,
129
130 print 'Checking for updates...'
131 with Bootstrapper(depot_tools) as bootstrapper:
132 bootstrapper.update()
133
134 # Import stage 2 and launch it.
135 tool_pylib = os.path.abspath(os.path.join(script_dir, 'staging/pylib'))
136 sys.path.insert(0, tool_pylib)
137 from blink_rename_merge_helper import driver
138 driver.run()
139
140
141 if __name__ == '__main__':
142 sys.exit(main())
OLDNEW
« no previous file with comments | « tools/blink_rename_merge_helper/pylib/blink_rename_merge_helper/driver.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698