| OLD | NEW |
| (Empty) |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import ast | |
| 6 import contextlib | |
| 7 import os | |
| 8 import platform | |
| 9 import shutil | |
| 10 import sys | |
| 11 import tempfile | |
| 12 | |
| 13 | |
| 14 ROOT = os.path.dirname(os.path.abspath(__file__)) | |
| 15 WHEELHOUSE = os.path.join(ROOT, 'wheelhouse') | |
| 16 | |
| 17 BUCKET = 'chrome-python-wheelhouse' | |
| 18 STORAGE_URL = 'https://www.googleapis.com/storage/v1/b/{}/o'.format(BUCKET) | |
| 19 OBJECT_URL = 'https://storage.googleapis.com/{}/{{}}#md5={{}}'.format(BUCKET) | |
| 20 LOCAL_OBJECT_URL = 'file://{}' | |
| 21 | |
| 22 LOCAL_STORAGE_PATH = os.path.join(ROOT, 'wheelhouse_cache') | |
| 23 | |
| 24 SOURCE_URL = 'gs://{}/sources/{{}}'.format(BUCKET) | |
| 25 WHEELS_URL = 'gs://{}/wheels/'.format(BUCKET) | |
| 26 | |
| 27 | |
| 28 class DepsConflictException(Exception): | |
| 29 def __init__(self, name): | |
| 30 super(DepsConflictException, self).__init__( | |
| 31 'Package \'%s\' is defined twice in deps.pyl' % name) | |
| 32 | |
| 33 | |
| 34 def platform_tag(): | |
| 35 if sys.platform.startswith('linux'): | |
| 36 return '_{0}_{1}'.format(*platform.linux_distribution()) | |
| 37 return '' | |
| 38 | |
| 39 | |
| 40 def print_deps(deps, indent=1, with_implicit=True): | |
| 41 for dep, entry in deps.iteritems(): | |
| 42 if not with_implicit and entry.get('implicit'): | |
| 43 continue | |
| 44 print ' ' * indent + '%s: %r' % (dep, entry) | |
| 45 print | |
| 46 | |
| 47 | |
| 48 @contextlib.contextmanager | |
| 49 def tempdir(*args, **kwargs): | |
| 50 tdir = None | |
| 51 try: | |
| 52 tdir = tempfile.mkdtemp(*args, **kwargs) | |
| 53 yield tdir | |
| 54 finally: | |
| 55 if tdir: | |
| 56 shutil.rmtree(tdir, ignore_errors=True) | |
| 57 | |
| 58 | |
| 59 @contextlib.contextmanager | |
| 60 def tempname(*args, **kwargs): | |
| 61 tmp = None | |
| 62 try: | |
| 63 tmp = tempfile.mktemp(*args, **kwargs) | |
| 64 yield tmp | |
| 65 finally: | |
| 66 if tmp: | |
| 67 try: | |
| 68 os.unlink(tmp) | |
| 69 except OSError: | |
| 70 pass | |
| 71 | |
| 72 | |
| 73 def read_deps(path): | |
| 74 if os.path.exists(path): | |
| 75 with open(path, 'rb') as f: | |
| 76 return ast.literal_eval(f.read()) | |
| 77 | |
| 78 | |
| 79 def merge_deps(paths): | |
| 80 deps = {} | |
| 81 for path in paths: | |
| 82 d = read_deps(path) | |
| 83 for key in d: | |
| 84 if key in deps: | |
| 85 raise DepsConflictException(key) | |
| 86 deps.update(d) | |
| 87 return deps | |
| OLD | NEW |