Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The LUCI Authors. All rights reserved. | 1 # Copyright 2015 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 ast | 5 import ast |
| 6 import collections | 6 import collections |
| 7 import contextlib | 7 import contextlib |
| 8 import copy | 8 import copy |
| 9 import difflib | 9 import difflib |
| 10 import functools | 10 import functools |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 """Returns the root of this repository.""" | 159 """Returns the root of this repository.""" |
| 160 raise NotImplementedError() | 160 raise NotImplementedError() |
| 161 | 161 |
| 162 def __eq__(self, other): | 162 def __eq__(self, other): |
| 163 raise NotImplementedError() | 163 raise NotImplementedError() |
| 164 | 164 |
| 165 def __ne__(self, other): | 165 def __ne__(self, other): |
| 166 return not (self == other) | 166 return not (self == other) |
| 167 | 167 |
| 168 def proto_file(self, context): | 168 def proto_file(self, context): |
| 169 """Returns the ProtoFile of the recipes config file in this repository. | 169 """Returns the ProtoFile of the recipes config file in this repository. |
| 170 Requires a good checkout.""" | 170 Requires a good checkout.""" |
| 171 return ProtoFile(InfraRepoConfig().to_recipes_cfg(self.repo_root(context))) | 171 return ProtoFile(InfraRepoConfig().to_recipes_cfg(self.repo_root(context))) |
| 172 | 172 |
| 173 | 173 |
| 174 class GitRepoSpec(RepoSpec): | 174 class GitRepoSpec(RepoSpec): |
| 175 def __init__(self, project_id, repo, branch, revision, path, backend): | 175 def __init__(self, project_id, repo, branch, revision, path, backend): |
| 176 self.project_id = project_id | 176 self.project_id = project_id |
| 177 self.repo = repo | 177 self.repo = repo |
| 178 self.branch = branch | 178 self.branch = branch |
| 179 self.revision = revision | 179 self.revision = revision |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 def __str__(self): | 309 def __str__(self): |
| 310 return 'PathRepoSpec{path="%(path)s"}' % self.__dict__ | 310 return 'PathRepoSpec{path="%(path)s"}' % self.__dict__ |
| 311 | 311 |
| 312 def checkout(self, context): | 312 def checkout(self, context): |
| 313 pass | 313 pass |
| 314 | 314 |
| 315 def repo_root(self, _context): | 315 def repo_root(self, _context): |
| 316 return self.path | 316 return self.path |
| 317 | 317 |
| 318 def proto_file(self, context): | 318 def proto_file(self, context): |
| 319 """Returns the ProtoFile of the recipes config file in this repository. | 319 """Returns the ProtoFile of the recipes config file in this repository. |
| 320 Requires a good checkout.""" | 320 Requires a good checkout.""" |
| 321 return ProtoFile(InfraRepoConfig().to_recipes_cfg(self.path)) | 321 return ProtoFile(InfraRepoConfig().to_recipes_cfg(self.path)) |
| 322 | 322 |
| 323 def __eq__(self, other): | 323 def __eq__(self, other): |
| 324 if not isinstance(other, type(self)): | 324 if not isinstance(other, type(self)): |
| 325 return False | 325 return False |
| 326 return self.path == other.path | 326 return self.path == other.path |
| 327 | 327 |
| 328 | 328 |
| 329 class RootRepoSpec(RepoSpec): | 329 class RootRepoSpec(RepoSpec): |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 buf = proto_file.read() | 502 buf = proto_file.read() |
| 503 assert buf.api_version == cls.API_VERSION | 503 assert buf.api_version == cls.API_VERSION |
| 504 | 504 |
| 505 deps = { str(dep.project_id): cls.spec_for_dep(dep) | 505 deps = { str(dep.project_id): cls.spec_for_dep(dep) |
| 506 for dep in buf.deps } | 506 for dep in buf.deps } |
| 507 return cls(str(buf.project_id), str(buf.recipes_path), deps) | 507 return cls(str(buf.project_id), str(buf.recipes_path), deps) |
| 508 | 508 |
| 509 @classmethod | 509 @classmethod |
| 510 def spec_for_dep(cls, dep): | 510 def spec_for_dep(cls, dep): |
| 511 """Returns a RepoSpec for the given dependency protobuf.""" | 511 """Returns a RepoSpec for the given dependency protobuf.""" |
| 512 url = str(dep.url) | |
| 513 if url.startswith("file://"): | |
| 514 return PathRepoSpec(url[7:]) | |
|
martiniss
2017/02/02 23:44:56
nit: change this to
return PathRepoSpec(url[len(
iannucci
2017/02/02 23:58:08
Done.
| |
| 512 | 515 |
| 513 if dep.repo_type in (package_pb2.DepSpec.GIT, package_pb2.DepSpec.GITILES): | 516 if dep.repo_type in (package_pb2.DepSpec.GIT, package_pb2.DepSpec.GITILES): |
| 514 if dep.repo_type == package_pb2.DepSpec.GIT: | 517 if dep.repo_type == package_pb2.DepSpec.GIT: |
| 515 backend = fetch.GitBackend() | 518 backend = fetch.GitBackend() |
| 516 elif dep.repo_type == package_pb2.DepSpec.GITILES: | 519 elif dep.repo_type == package_pb2.DepSpec.GITILES: |
| 517 backend = fetch.GitilesBackend() | 520 backend = fetch.GitilesBackend() |
| 518 return GitRepoSpec(str(dep.project_id), | 521 return GitRepoSpec(str(dep.project_id), |
| 519 str(dep.url), | 522 url, |
| 520 str(dep.branch), | 523 str(dep.branch), |
| 521 str(dep.revision), | 524 str(dep.revision), |
| 522 str(dep.path_override), | 525 str(dep.path_override), |
| 523 backend) | 526 backend) |
| 524 | 527 |
| 525 assert False, 'Unexpected repo type: %s' % dep | 528 assert False, 'Unexpected repo type: %s' % dep |
| 526 | 529 |
| 527 @property | 530 @property |
| 528 def project_id(self): | 531 def project_id(self): |
| 529 return self._project_id | 532 return self._project_id |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 675 >>> d = { 'x': 1, 'y': 2 } | 678 >>> d = { 'x': 1, 'y': 2 } |
| 676 >>> sorted(_updated(d, { 'y': 3, 'z': 4 }).items()) | 679 >>> sorted(_updated(d, { 'y': 3, 'z': 4 }).items()) |
| 677 [('x', 1), ('y', 3), ('z', 4)] | 680 [('x', 1), ('y', 3), ('z', 4)] |
| 678 >>> sorted(d.items()) | 681 >>> sorted(d.items()) |
| 679 [('x', 1), ('y', 2)] | 682 [('x', 1), ('y', 2)] |
| 680 """ | 683 """ |
| 681 | 684 |
| 682 d = copy.copy(d) | 685 d = copy.copy(d) |
| 683 d.update(updates) | 686 d.update(updates) |
| 684 return d | 687 return d |
| OLD | NEW |