Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: ensure_dependencies.py

Issue 5652679430766592: Issue 2443 - Honour SKIP_DEPENDENCY_UPDATES environment variable (Closed)
Left Patch Set: Only warn if revision is wrong Created May 7, 2015, 1 p.m.
Right Patch Set: Addressed further feedback from Sebastian Created May 7, 2015, 2:17 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # coding: utf-8 2 # coding: utf-8
3 3
4 # This Source Code Form is subject to the terms of the Mozilla Public 4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this 5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 7
8 import sys 8 import sys
9 import os 9 import os
10 import posixpath 10 import posixpath
(...skipping 15 matching lines...) Expand all
26 _root = hg:https://hg.adblockplus.org/ git:https://github.com/adblockplus/ 26 _root = hg:https://hg.adblockplus.org/ git:https://github.com/adblockplus/
27 # File to update this script from (optional) 27 # File to update this script from (optional)
28 _self = buildtools/ensure_dependencies.py 28 _self = buildtools/ensure_dependencies.py
29 # Check out elemhidehelper repository into extensions/elemhidehelper directory 29 # Check out elemhidehelper repository into extensions/elemhidehelper directory
30 # at tag "1.2". 30 # at tag "1.2".
31 extensions/elemhidehelper = elemhidehelper 1.2 31 extensions/elemhidehelper = elemhidehelper 1.2
32 # Check out buildtools repository into buildtools directory at VCS-specific 32 # Check out buildtools repository into buildtools directory at VCS-specific
33 # revision IDs. 33 # revision IDs.
34 buildtools = buildtools hg:016d16f7137b git:f3f8692f82e5 34 buildtools = buildtools hg:016d16f7137b git:f3f8692f82e5
35 """ 35 """
36
37 SKIP_DEPENDENCY_UPDATES = os.environ.get(
38 "SKIP_DEPENDENCY_UPDATES", ""
39 ).lower() not in ("", "0", "false")
36 40
37 class Mercurial(): 41 class Mercurial():
38 def istype(self, repodir): 42 def istype(self, repodir):
39 return os.path.exists(os.path.join(repodir, ".hg")) 43 return os.path.exists(os.path.join(repodir, ".hg"))
40 44
41 def clone(self, source, target): 45 def clone(self, source, target):
42 if not source.endswith("/"): 46 if not source.endswith("/"):
43 source += "/" 47 source += "/"
44 subprocess.check_call(["hg", "clone", "--quiet", "--noupdate", source, targe t]) 48 subprocess.check_call(["hg", "clone", "--quiet", "--noupdate", source, targe t])
45 49
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 def get_repo_type(repo): 198 def get_repo_type(repo):
195 for name, repotype in repo_types.iteritems(): 199 for name, repotype in repo_types.iteritems():
196 if repotype.istype(repo): 200 if repotype.istype(repo):
197 return name 201 return name
198 return None 202 return None
199 203
200 def ensure_repo(parentrepo, target, roots, sourcename): 204 def ensure_repo(parentrepo, target, roots, sourcename):
201 if os.path.exists(target): 205 if os.path.exists(target):
202 return 206 return
203 207
208 if SKIP_DEPENDENCY_UPDATES:
209 logging.warning("SKIP_DEPENDENCY_UPDATES environment variable set, "
210 "%s not cloned", target)
211 return
212
204 parenttype = get_repo_type(parentrepo) 213 parenttype = get_repo_type(parentrepo)
205 type = None 214 type = None
206 for key in roots: 215 for key in roots:
207 if key == parenttype or (key in repo_types and type is None): 216 if key == parenttype or (key in repo_types and type is None):
208 type = key 217 type = key
209 if type is None: 218 if type is None:
210 raise Exception("No valid source found to create %s" % target) 219 raise Exception("No valid source found to create %s" % target)
211 220
212 postprocess_url = repo_types[type].postprocess_url 221 postprocess_url = repo_types[type].postprocess_url
213 root = postprocess_url(roots[type]) 222 root = postprocess_url(roots[type])
(...skipping 21 matching lines...) Expand all
235 revision = revisions[type] 244 revision = revisions[type]
236 elif "*" in revisions: 245 elif "*" in revisions:
237 revision = revisions["*"] 246 revision = revisions["*"]
238 else: 247 else:
239 logging.warning("No revision specified for repository %s (type %s), skipping update" % (target, type)) 248 logging.warning("No revision specified for repository %s (type %s), skipping update" % (target, type))
240 return 249 return
241 250
242 resolved_revision = repo_types[type].get_revision_id(target, revision) 251 resolved_revision = repo_types[type].get_revision_id(target, revision)
243 current_revision = repo_types[type].get_revision_id(target) 252 current_revision = repo_types[type].get_revision_id(target)
244 253
245 if (resolved_revision != current_revision and 254 if resolved_revision != current_revision:
Sebastian Noack 2015/05/07 13:17:19 I think the code structure below below can be simp
kzar 2015/05/07 13:44:29 Done.
246 os.environ.get("SKIP_ENSURE_DEPENDENCIES", "").lower() not in ("", "0", "f alse")): 255 if SKIP_DEPENDENCY_UPDATES:
Sebastian Noack 2015/05/07 13:17:19 We agreed on SKIP_DEPENDENCY_UPDATES rather than S
kzar 2015/05/07 13:44:29 Done.
247 logging.warning("SKIP_ENSURE_DEPENDENCIES environment variable set, " 256 logging.warning("SKIP_DEPENDENCY_UPDATES environment variable set, "
248 "%s not checked out to %s" % (target, revision)) 257 "%s not checked out to %s", target, revision)
249 return 258 return
250 259
251 if not resolved_revision:
252 logging.info("Revision %s is unknown, downloading remote changes" % revision )
253 repo_types[type].pull(target)
254 resolved_revision = repo_types[type].get_revision_id(target, revision)
255 if not resolved_revision: 260 if not resolved_revision:
256 raise Exception("Failed to resolve revision %s" % revision) 261 logging.info("Revision %s is unknown, downloading remote changes" % revisi on)
257 262 repo_types[type].pull(target)
258 if resolved_revision != current_revision: 263 resolved_revision = repo_types[type].get_revision_id(target, revision)
264 if not resolved_revision:
265 raise Exception("Failed to resolve revision %s" % revision)
266
259 logging.info("Updating repository %s to revision %s" % (target, resolved_rev ision)) 267 logging.info("Updating repository %s to revision %s" % (target, resolved_rev ision))
260 repo_types[type].update(target, resolved_revision) 268 repo_types[type].update(target, resolved_revision)
261 269
262 def resolve_deps(repodir, level=0, self_update=True, overrideroots=None, skipdep endencies=set()): 270 def resolve_deps(repodir, level=0, self_update=True, overrideroots=None, skipdep endencies=set()):
263 config = read_deps(repodir) 271 config = read_deps(repodir)
264 if config is None: 272 if config is None:
265 if level == 0: 273 if level == 0:
266 logging.warning("No dependencies file in directory %s, nothing to do...\n% s" % (repodir, USAGE)) 274 logging.warning("No dependencies file in directory %s, nothing to do...\n% s" % (repodir, USAGE))
267 return 275 return
268 if level >= 10: 276 if level >= 10:
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 args = parser.parse_args() 332 args = parser.parse_args()
325 333
326 if args.quiet: 334 if args.quiet:
327 logging.disable(logging.INFO) 335 logging.disable(logging.INFO)
328 336
329 repos = args.repos 337 repos = args.repos
330 if not len(repos): 338 if not len(repos):
331 repos = [os.path.dirname(__file__)] 339 repos = [os.path.dirname(__file__)]
332 for repo in repos: 340 for repo in repos:
333 resolve_deps(repo) 341 resolve_deps(repo)
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld