OLD | NEW |
---|---|
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import ast | 5 import ast |
6 import contextlib | 6 import contextlib |
7 import fnmatch | 7 import fnmatch |
8 import json | 8 import json |
9 import os | 9 import os |
10 import pipes | 10 import pipes |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 | 191 |
192 | 192 |
193 def ExtractAll(zip_path, path=None, no_clobber=True): | 193 def ExtractAll(zip_path, path=None, no_clobber=True): |
194 if path is None: | 194 if path is None: |
195 path = os.getcwd() | 195 path = os.getcwd() |
196 elif not os.path.exists(path): | 196 elif not os.path.exists(path): |
197 MakeDirectory(path) | 197 MakeDirectory(path) |
198 | 198 |
199 with zipfile.ZipFile(zip_path) as z: | 199 with zipfile.ZipFile(zip_path) as z: |
200 for name in z.namelist(): | 200 for name in z.namelist(): |
201 if name.endswith('/'): | |
202 continue | |
201 CheckZipPath(name) | 203 CheckZipPath(name) |
202 if no_clobber: | 204 if no_clobber: |
203 output_path = os.path.join(path, name) | 205 output_path = os.path.join(path, name) |
204 if os.path.exists(output_path): | 206 if os.path.exists(output_path): |
205 raise Exception( | 207 raise Exception( |
206 'Path already exists from zip: %s %s %s' | 208 'Path already exists from zip: %s %s %s' |
207 % (zip_path, name, output_path)) | 209 % (zip_path, name, output_path)) |
208 | 210 |
209 z.extractall(path=path) | 211 z.extractall(path=path) |
210 | 212 |
211 | 213 |
212 def DoZip(inputs, output, base_dir): | 214 def DoZip(inputs, output, base_dir): |
213 with zipfile.ZipFile(output, 'w') as outfile: | 215 with zipfile.ZipFile(output, 'w') as outfile: |
214 for f in inputs: | 216 for f in inputs: |
215 CheckZipPath(os.path.relpath(f, base_dir)) | 217 CheckZipPath(os.path.relpath(f, base_dir)) |
216 outfile.write(f, os.path.relpath(f, base_dir)) | 218 outfile.write(f, os.path.relpath(f, base_dir)) |
217 | 219 |
218 | 220 |
221 def ZipDir(output, base_dir): | |
222 with zipfile.ZipFile(output, 'w') as outfile: | |
223 for root, _, files in os.walk(base_dir): | |
224 for f in files: | |
225 path = os.path.join(root, f) | |
226 archive_path = os.path.relpath(path, base_dir) | |
227 CheckZipPath(archive_path) | |
228 outfile.write(path, archive_path) | |
229 | |
230 | |
219 def PrintWarning(message): | 231 def PrintWarning(message): |
220 print 'WARNING: ' + message | 232 print 'WARNING: ' + message |
221 | 233 |
222 | 234 |
223 def PrintBigWarning(message): | 235 def PrintBigWarning(message): |
224 print '***** ' * 8 | 236 print '***** ' * 8 |
225 PrintWarning(message) | 237 PrintWarning(message) |
226 print '***** ' * 8 | 238 print '***** ' * 8 |
227 | 239 |
228 | 240 |
241 def GetSortedTransitiveDependencies(top, deps_func): | |
newt (away)
2014/07/07 21:47:11
What the heck is a deps_func? This function and it
cjhopman
2014/07/08 00:16:27
Done.
| |
242 def Node(dep): | |
243 return (dep, deps_func(dep)) | |
244 | |
245 # First: find all deps | |
246 unchecked_deps = list(top) | |
247 all_deps = set(top) | |
248 while unchecked_deps: | |
249 dep = unchecked_deps.pop() | |
250 new_deps = deps_func(dep).difference(all_deps) | |
251 unchecked_deps.extend(new_deps) | |
252 all_deps = all_deps.union(new_deps) | |
253 | |
254 # Then: simple, slow topological sort. | |
255 sorted_deps = [] | |
256 unsorted_deps = dict(map(Node, all_deps)) | |
257 while unsorted_deps: | |
258 for library, dependencies in unsorted_deps.items(): | |
259 if not dependencies.intersection(unsorted_deps.keys()): | |
260 sorted_deps.append(library) | |
261 del unsorted_deps[library] | |
262 | |
263 return sorted_deps | |
264 | |
265 | |
229 def GetPythonDependencies(): | 266 def GetPythonDependencies(): |
230 """Gets the paths of imported non-system python modules. | 267 """Gets the paths of imported non-system python modules. |
231 | 268 |
232 A path is assumed to be a "system" import if it is outside of chromium's | 269 A path is assumed to be a "system" import if it is outside of chromium's |
233 src/. The paths will be relative to the current directory. | 270 src/. The paths will be relative to the current directory. |
234 """ | 271 """ |
235 module_paths = (m.__file__ for m in sys.modules.itervalues() | 272 module_paths = (m.__file__ for m in sys.modules.itervalues() |
236 if m is not None and hasattr(m, '__file__')) | 273 if m is not None and hasattr(m, '__file__')) |
237 | 274 |
238 abs_module_paths = map(os.path.abspath, module_paths) | 275 abs_module_paths = map(os.path.abspath, module_paths) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
296 if not file_path in file_jsons: | 333 if not file_path in file_jsons: |
297 file_jsons[file_path] = ReadJson(file_path) | 334 file_jsons[file_path] = ReadJson(file_path) |
298 | 335 |
299 expansion = file_jsons[file_path] | 336 expansion = file_jsons[file_path] |
300 for k in lookup_path[1:]: | 337 for k in lookup_path[1:]: |
301 expansion = expansion[k] | 338 expansion = expansion[k] |
302 | 339 |
303 new_args[i] = arg[:start] + str(expansion) + arg[end + 1:] | 340 new_args[i] = arg[:start] + str(expansion) + arg[end + 1:] |
304 return new_args | 341 return new_args |
305 | 342 |
OLD | NEW |