| OLD | NEW |
| 1 # Copyright 2016 The LUCI Authors. All rights reserved. | 1 # Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import base64 | 5 import base64 |
| 6 import httplib | 6 import httplib |
| 7 import json | 7 import json |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import re | 10 import re |
| 11 import shutil | 11 import shutil |
| 12 import sys | 12 import sys |
| 13 import tarfile | 13 import tarfile |
| 14 import tempfile | 14 import tempfile |
| 15 | 15 |
| 16 # Add third party paths. | 16 # Add third party paths. |
| 17 from . import env | 17 from . import env |
| 18 from . import requests_ssl | 18 from . import requests_ssl |
| 19 from . import util | 19 from . import util |
| 20 from . import types | 20 from . import types |
| 21 from .requests_ssl import requests | 21 from .requests_ssl import requests |
| 22 | 22 |
| 23 import subprocess42 | 23 import subprocess42 |
| 24 from google.protobuf import text_format | 24 from google.protobuf import json_format |
| 25 | 25 |
| 26 from . import package_pb2 | 26 from . import package_pb2 |
| 27 | 27 |
| 28 | 28 |
| 29 class FetchError(Exception): | 29 class FetchError(Exception): |
| 30 pass | 30 pass |
| 31 | 31 |
| 32 | 32 |
| 33 class FetchNotAllowedError(FetchError): | 33 class FetchNotAllowedError(FetchError): |
| 34 pass | 34 pass |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 253 |
| 254 revision = self._resolve_revision(repo, revision) | 254 revision = self._resolve_revision(repo, revision) |
| 255 | 255 |
| 256 shutil.rmtree(checkout_dir, ignore_errors=True) | 256 shutil.rmtree(checkout_dir, ignore_errors=True) |
| 257 | 257 |
| 258 recipes_cfg_url = '%s/+/%s/infra/config/recipes.cfg?format=TEXT' % ( | 258 recipes_cfg_url = '%s/+/%s/infra/config/recipes.cfg?format=TEXT' % ( |
| 259 repo, requests.utils.quote(revision)) | 259 repo, requests.utils.quote(revision)) |
| 260 recipes_cfg_text = base64.b64decode( | 260 recipes_cfg_text = base64.b64decode( |
| 261 self._fetch_gitiles(recipes_cfg_url).text) | 261 self._fetch_gitiles(recipes_cfg_url).text) |
| 262 recipes_cfg_proto = package_pb2.Package() | 262 recipes_cfg_proto = package_pb2.Package() |
| 263 text_format.Merge(recipes_cfg_text, recipes_cfg_proto) | 263 json_format.Parse(recipes_cfg_text, recipes_cfg_proto, |
| 264 ignore_unknown_fields=True) |
| 264 recipes_path_rel = recipes_cfg_proto.recipes_path | 265 recipes_path_rel = recipes_cfg_proto.recipes_path |
| 265 | 266 |
| 266 # Re-create recipes.cfg in |checkout_dir| so that the repo's recipes.py | 267 # Re-create recipes.cfg in |checkout_dir| so that the repo's recipes.py |
| 267 # can look it up. | 268 # can look it up. |
| 268 recipes_cfg_path = os.path.join( | 269 recipes_cfg_path = os.path.join( |
| 269 checkout_dir, 'infra', 'config', 'recipes.cfg') | 270 checkout_dir, 'infra', 'config', 'recipes.cfg') |
| 270 os.makedirs(os.path.dirname(recipes_cfg_path)) | 271 os.makedirs(os.path.dirname(recipes_cfg_path)) |
| 271 with open(recipes_cfg_path, 'w') as f: | 272 with open(recipes_cfg_path, 'w') as f: |
| 272 f.write(recipes_cfg_text) | 273 f.write(recipes_cfg_text) |
| 273 | 274 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 logging.info('fetching %s', url) | 359 logging.info('fetching %s', url) |
| 359 | 360 |
| 360 resp = requests.get(url) | 361 resp = requests.get(url) |
| 361 if resp.status_code != httplib.OK: | 362 if resp.status_code != httplib.OK: |
| 362 raise GitilesFetchError(resp.status_code, resp.text) | 363 raise GitilesFetchError(resp.status_code, resp.text) |
| 363 | 364 |
| 364 if not resp.text.startswith(cls._GERRIT_XSRF_HEADER): | 365 if not resp.text.startswith(cls._GERRIT_XSRF_HEADER): |
| 365 raise GitilesFetchError(resp.status_code, 'Missing XSRF header') | 366 raise GitilesFetchError(resp.status_code, 'Missing XSRF header') |
| 366 | 367 |
| 367 return json.loads(resp.text[len(cls._GERRIT_XSRF_HEADER):]) | 368 return json.loads(resp.text[len(cls._GERRIT_XSRF_HEADER):]) |
| OLD | NEW |