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

Side by Side Diff: ensure_dependencies.py

Issue 5195278835515392: Issue 2451 - Update adblockplus dependency to revision 538501c0421a (Closed)
Patch Set: Created May 4, 2015, 8:10 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « dependencies ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 import re 11 import re
12 import io 12 import io
13 import errno 13 import errno
14 import logging 14 import logging
15 import subprocess 15 import subprocess
16 import urlparse 16 import urlparse
17 import argparse
17 18
18 from collections import OrderedDict 19 from collections import OrderedDict
19 from ConfigParser import RawConfigParser 20 from ConfigParser import RawConfigParser
20 21
21 USAGE = """ 22 USAGE = """
22 A dependencies file should look like this: 23 A dependencies file should look like this:
23 24
24 # VCS-specific root URLs for the repositories 25 # VCS-specific root URLs for the repositories
25 _root = hg:https://hg.adblockplus.org/ git:https://github.com/adblockplus/ 26 _root = hg:https://hg.adblockplus.org/ git:https://github.com/adblockplus/
26 # File to update this script from (optional) 27 # File to update this script from (optional)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 if not config.has_section("ui"): 72 if not config.has_section("ui"):
72 config.add_section("ui") 73 config.add_section("ui")
73 74
74 config.set("ui", "ignore.dependencies", ignore_path) 75 config.set("ui", "ignore.dependencies", ignore_path)
75 with open(config_path, "w") as stream: 76 with open(config_path, "w") as stream:
76 config.write(stream) 77 config.write(stream)
77 78
78 module = os.path.relpath(target, repo) 79 module = os.path.relpath(target, repo)
79 _ensure_line_exists(ignore_path, module) 80 _ensure_line_exists(ignore_path, module)
80 81
82 def postprocess_url(self, url):
83 return url
84
81 class Git(): 85 class Git():
82 def istype(self, repodir): 86 def istype(self, repodir):
83 return os.path.exists(os.path.join(repodir, ".git")) 87 return os.path.exists(os.path.join(repodir, ".git"))
84 88
85 def clone(self, source, target): 89 def clone(self, source, target):
86 source = source.rstrip("/") 90 source = source.rstrip("/")
87 if not source.endswith(".git"): 91 if not source.endswith(".git"):
88 source += ".git" 92 source += ".git"
89 subprocess.check_call(["git", "clone", "--quiet", source, target]) 93 subprocess.check_call(["git", "clone", "--quiet", source, target])
90 94
91 def get_revision_id(self, repo, rev="HEAD"): 95 def get_revision_id(self, repo, rev="HEAD"):
92 command = ["git", "rev-parse", "--revs-only", rev + '^{commit}'] 96 command = ["git", "rev-parse", "--revs-only", rev + '^{commit}']
93 return subprocess.check_output(command, cwd=repo).strip() 97 return subprocess.check_output(command, cwd=repo).strip()
94 98
95 def pull(self, repo): 99 def pull(self, repo):
96 subprocess.check_call(["git", "fetch", "--quiet", "--all", "--tags"], cwd=re po) 100 subprocess.check_call(["git", "fetch", "--quiet", "--all", "--tags"], cwd=re po)
97 101
98 def update(self, repo, rev): 102 def update(self, repo, rev):
99 subprocess.check_call(["git", "checkout", "--quiet", rev], cwd=repo) 103 subprocess.check_call(["git", "checkout", "--quiet", rev], cwd=repo)
100 104
101 def ignore(self, target, repo): 105 def ignore(self, target, repo):
102 module = os.path.relpath(target, repo) 106 module = os.path.relpath(target, repo)
103 exclude_file = os.path.join(repo, ".git", "info", "exclude") 107 exclude_file = os.path.join(repo, ".git", "info", "exclude")
104 _ensure_line_exists(exclude_file, module) 108 _ensure_line_exists(exclude_file, module)
105 109
110 def postprocess_url(self, url):
111 # Handle alternative syntax of SSH URLS
112 if "@" in url and ":" in url and not urlparse.urlsplit(url).scheme:
113 return "ssh://" + url.replace(":", "/", 1)
114 return url
115
106 repo_types = OrderedDict(( 116 repo_types = OrderedDict((
107 ("hg", Mercurial()), 117 ("hg", Mercurial()),
108 ("git", Git()), 118 ("git", Git()),
109 )) 119 ))
110 120
111 def parse_spec(path, line): 121 def parse_spec(path, line):
112 if "=" not in line: 122 if "=" not in line:
113 logging.warning("Invalid line in file %s: %s" % (path, line)) 123 logging.warning("Invalid line in file %s: %s" % (path, line))
114 return None, None 124 return None, None
115 125
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 return 189 return
180 190
181 parenttype = get_repo_type(parentrepo) 191 parenttype = get_repo_type(parentrepo)
182 type = None 192 type = None
183 for key in roots: 193 for key in roots:
184 if key == parenttype or (key in repo_types and type is None): 194 if key == parenttype or (key in repo_types and type is None):
185 type = key 195 type = key
186 if type is None: 196 if type is None:
187 raise Exception("No valid source found to create %s" % target) 197 raise Exception("No valid source found to create %s" % target)
188 198
189 url = urlparse.urljoin(roots[type], sourcename) 199 postprocess_url = repo_types[type].postprocess_url
200 root = postprocess_url(roots[type])
201 sourcename = postprocess_url(sourcename)
202
203 if os.path.exists(root):
204 url = os.path.join(root, sourcename)
205 else:
206 url = urlparse.urljoin(root, sourcename)
207
190 logging.info("Cloning repository %s into %s" % (url, target)) 208 logging.info("Cloning repository %s into %s" % (url, target))
191 repo_types[type].clone(url, target) 209 repo_types[type].clone(url, target)
192 210
193 for repo in repo_types.itervalues(): 211 for repo in repo_types.itervalues():
194 if repo.istype(parentrepo): 212 if repo.istype(parentrepo):
195 repo.ignore(target, parentrepo) 213 repo.ignore(target, parentrepo)
196 214
197 def update_repo(target, revisions): 215 def update_repo(target, revisions):
198 type = get_repo_type(target) 216 type = get_repo_type(target)
199 if type is None: 217 if type is None:
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 file_content = [l.strip() for l in f.readlines()] 289 file_content = [l.strip() for l in f.readlines()]
272 if not pattern in file_content: 290 if not pattern in file_content:
273 file_content.append(pattern) 291 file_content.append(pattern)
274 f.seek(0, os.SEEK_SET) 292 f.seek(0, os.SEEK_SET)
275 f.truncate() 293 f.truncate()
276 for l in file_content: 294 for l in file_content:
277 print >>f, l 295 print >>f, l
278 296
279 if __name__ == "__main__": 297 if __name__ == "__main__":
280 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO) 298 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
281 repos = sys.argv[1:] 299
300 parser = argparse.ArgumentParser(description="Verify dependencies for a set of repositories, by default the repository of this script.")
301 parser.add_argument("repos", metavar="repository", type=str, nargs="*", help=" Repository path")
302 parser.add_argument("-q", "--quiet", action="store_true", help="Suppress infor mational output")
303 args = parser.parse_args()
304
305 if args.quiet:
306 logging.disable(logging.INFO)
307
308 repos = args.repos
282 if not len(repos): 309 if not len(repos):
283 repos = [os.getcwd()] 310 repos = [os.path.dirname(__file__)]
284 for repo in repos: 311 for repo in repos:
285 resolve_deps(repo) 312 resolve_deps(repo)
OLDNEW
« no previous file with comments | « dependencies ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld