Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # coding: utf-8 | 2 # coding: utf-8 |
3 | 3 |
4 # This file is part of the Adblock Plus build tools, | 4 # This file is part of the Adblock Plus build tools, |
5 # Copyright (C) 2006-2014 Eyeo GmbH | 5 # Copyright (C) 2006-2014 Eyeo GmbH |
6 # | 6 # |
7 # Adblock Plus is free software: you can redistribute it and/or modify | 7 # Adblock Plus is free software: you can redistribute it and/or modify |
8 # it under the terms of the GNU General Public License version 3 as | 8 # it under the terms of the GNU General Public License version 3 as |
9 # published by the Free Software Foundation. | 9 # published by the Free Software Foundation. |
10 # | 10 # |
(...skipping 26 matching lines...) Expand all Loading... | |
37 # File to update this script from (optional) | 37 # File to update this script from (optional) |
38 _self = buildtools/ensure_dependencies.py | 38 _self = buildtools/ensure_dependencies.py |
39 # Check out elemhidehelper repository into extensions/elemhidehelper directory | 39 # Check out elemhidehelper repository into extensions/elemhidehelper directory |
40 # at tag "1.2". | 40 # at tag "1.2". |
41 extensions/elemhidehelper = elemhidehelper 1.2 | 41 extensions/elemhidehelper = elemhidehelper 1.2 |
42 # Check out buildtools repository into buildtools directory at VCS-specific | 42 # Check out buildtools repository into buildtools directory at VCS-specific |
43 # revision IDs. | 43 # revision IDs. |
44 buildtools = buildtools hg:016d16f7137b git:f3f8692f82e5 | 44 buildtools = buildtools hg:016d16f7137b git:f3f8692f82e5 |
45 """ | 45 """ |
46 | 46 |
47 class SCM(object): | 47 class Mercurial(): |
48 def _ensure_line_exists(self, ignore_file, pattern): | |
Wladimir Palant
2014/10/08 21:40:30
The parameter should be called path, not ignore_fi
| |
49 with open(ignore_file, 'a+') as f: | |
50 file_content = [l.strip() for l in f.readlines()] | |
51 if not pattern in file_content: | |
52 file_content.append(pattern) | |
53 f.seek(0, os.SEEK_SET) | |
54 for l in file_content: | |
55 print >>f, l | |
56 f.truncate() | |
57 | |
58 class Mercurial(SCM): | |
59 def istype(self, repodir): | 48 def istype(self, repodir): |
60 return os.path.exists(os.path.join(repodir, ".hg")) | 49 return os.path.exists(os.path.join(repodir, ".hg")) |
61 | 50 |
62 def clone(self, source, target): | 51 def clone(self, source, target): |
63 if not source.endswith("/"): | 52 if not source.endswith("/"): |
64 source += "/" | 53 source += "/" |
65 subprocess.check_call(["hg", "clone", "--quiet", "--noupdate", source, targe t]) | 54 subprocess.check_call(["hg", "clone", "--quiet", "--noupdate", source, targe t]) |
66 | 55 |
67 def get_revision_id(self, repo, rev=None): | 56 def get_revision_id(self, repo, rev=None): |
68 command = ["hg", "id", "--repository", repo, "--id"] | 57 command = ["hg", "id", "--repository", repo, "--id"] |
(...skipping 22 matching lines...) Expand all Loading... | |
91 config.read(config_path) | 80 config.read(config_path) |
92 | 81 |
93 if not config.has_section("ui"): | 82 if not config.has_section("ui"): |
94 config.add_section("ui") | 83 config.add_section("ui") |
95 | 84 |
96 config.set("ui", "ignore.dependencies", ignore_path) | 85 config.set("ui", "ignore.dependencies", ignore_path) |
97 with open(config_path, "w") as stream: | 86 with open(config_path, "w") as stream: |
98 config.write(stream) | 87 config.write(stream) |
99 | 88 |
100 module = os.path.relpath(target, repo) | 89 module = os.path.relpath(target, repo) |
101 self._ensure_line_exists(ignore_path, module) | 90 _ensure_line_exists(ignore_path, module) |
102 | 91 |
103 class Git(SCM): | 92 class Git(): |
104 def istype(self, repodir): | 93 def istype(self, repodir): |
105 return os.path.exists(os.path.join(repodir, ".git")) | 94 return os.path.exists(os.path.join(repodir, ".git")) |
106 | 95 |
107 def clone(self, source, target): | 96 def clone(self, source, target): |
108 source = source.rstrip("/") | 97 source = source.rstrip("/") |
109 if not source.endswith(".git"): | 98 if not source.endswith(".git"): |
110 source += ".git" | 99 source += ".git" |
111 subprocess.check_call(["git", "clone", "--quiet", source, target]) | 100 subprocess.check_call(["git", "clone", "--quiet", source, target]) |
112 | 101 |
113 def get_revision_id(self, repo, rev="HEAD"): | 102 def get_revision_id(self, repo, rev="HEAD"): |
114 command = ["git", "rev-parse", "--revs-only", rev] | 103 command = ["git", "rev-parse", "--revs-only", rev] |
115 return subprocess.check_output(command, cwd=repo).strip() | 104 return subprocess.check_output(command, cwd=repo).strip() |
116 | 105 |
117 def pull(self, repo): | 106 def pull(self, repo): |
118 subprocess.check_call(["git", "fetch", "--quiet", "--all", "--tags"], cwd=re po) | 107 subprocess.check_call(["git", "fetch", "--quiet", "--all", "--tags"], cwd=re po) |
119 | 108 |
120 def update(self, repo, rev): | 109 def update(self, repo, rev): |
121 subprocess.check_call(["git", "checkout", "--quiet", rev], cwd=repo) | 110 subprocess.check_call(["git", "checkout", "--quiet", rev], cwd=repo) |
122 | 111 |
123 def ignore(self, target, repo): | 112 def ignore(self, target, repo): |
124 module = os.path.relpath(target, repo) | 113 module = os.path.relpath(target, repo) |
125 exclude_file = os.path.join(repo, ".git", "info", "exclude") | 114 exclude_file = os.path.join(repo, ".git", "info", "exclude") |
126 self._ensure_line_exists(exclude_file, module) | 115 _ensure_line_exists(exclude_file, module) |
127 | 116 |
128 repo_types = OrderedDict(( | 117 repo_types = OrderedDict(( |
129 ("hg", Mercurial()), | 118 ("hg", Mercurial()), |
130 ("git", Git()), | 119 ("git", Git()), |
131 )) | 120 )) |
132 | 121 |
133 def parse_spec(path, line): | 122 def parse_spec(path, line): |
134 if "=" not in line: | 123 if "=" not in line: |
135 logging.warning("Invalid line in file %s: %s" % (path, line)) | 124 logging.warning("Invalid line in file %s: %s" % (path, line)) |
136 return None, None | 125 return None, None |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 for key in roots: | 194 for key in roots: |
206 if key == parenttype or (key in repo_types and type is None): | 195 if key == parenttype or (key in repo_types and type is None): |
207 type = key | 196 type = key |
208 if type is None: | 197 if type is None: |
209 raise Exception("No valid source found to create %s" % target) | 198 raise Exception("No valid source found to create %s" % target) |
210 | 199 |
211 url = urlparse.urljoin(roots[type], sourcename) | 200 url = urlparse.urljoin(roots[type], sourcename) |
212 logging.info("Cloning repository %s into %s" % (url, target)) | 201 logging.info("Cloning repository %s into %s" % (url, target)) |
213 repo_types[type].clone(url, target) | 202 repo_types[type].clone(url, target) |
214 | 203 |
204 for repo in repo_types.itervalues(): | |
205 if repo.istype(parentrepo): | |
206 repo.ignore(target, parentrepo) | |
207 | |
215 def update_repo(target, revisions): | 208 def update_repo(target, revisions): |
216 type = get_repo_type(target) | 209 type = get_repo_type(target) |
217 if type is None: | 210 if type is None: |
218 logging.warning("Type of repository %s unknown, skipping update" % target) | 211 logging.warning("Type of repository %s unknown, skipping update" % target) |
219 return | 212 return |
220 | 213 |
221 if type in revisions: | 214 if type in revisions: |
222 revision = revisions[type] | 215 revision = revisions[type] |
223 elif "*" in revisions: | 216 elif "*" in revisions: |
224 revision = revisions["*"] | 217 revision = revisions["*"] |
(...skipping 24 matching lines...) Expand all Loading... | |
249 logging.warning("Too much subrepository nesting, ignoring %s" % repo) | 242 logging.warning("Too much subrepository nesting, ignoring %s" % repo) |
250 | 243 |
251 if overrideroots is not None: | 244 if overrideroots is not None: |
252 config["_root"] = overrideroots | 245 config["_root"] = overrideroots |
253 | 246 |
254 for dir, revisions in config.iteritems(): | 247 for dir, revisions in config.iteritems(): |
255 if dir.startswith("_") or revisions["_source"] in skipdependencies: | 248 if dir.startswith("_") or revisions["_source"] in skipdependencies: |
256 continue | 249 continue |
257 target = safe_join(repodir, dir) | 250 target = safe_join(repodir, dir) |
258 ensure_repo(repodir, target, config.get("_root", {}), revisions["_source"]) | 251 ensure_repo(repodir, target, config.get("_root", {}), revisions["_source"]) |
259 for repo in repo_types.itervalues(): | |
260 if repo.istype(repodir): | |
261 repo.ignore(target, repodir) | |
Wladimir Palant
2014/10/08 21:40:30
Why was this code moved again? As noted before, it
| |
262 update_repo(target, revisions) | 252 update_repo(target, revisions) |
263 resolve_deps(target, level + 1, self_update=False, overrideroots=overrideroo ts, skipdependencies=skipdependencies) | 253 resolve_deps(target, level + 1, self_update=False, overrideroots=overrideroo ts, skipdependencies=skipdependencies) |
264 | 254 |
265 if self_update and "_self" in config and "*" in config["_self"]: | 255 if self_update and "_self" in config and "*" in config["_self"]: |
266 source = safe_join(repodir, config["_self"]["*"]) | 256 source = safe_join(repodir, config["_self"]["*"]) |
267 try: | 257 try: |
268 with io.open(source, "rb") as handle: | 258 with io.open(source, "rb") as handle: |
269 sourcedata = handle.read() | 259 sourcedata = handle.read() |
270 except IOError, e: | 260 except IOError, e: |
271 if e.errno != errno.ENOENT: | 261 if e.errno != errno.ENOENT: |
272 raise | 262 raise |
273 logging.warning("File %s doesn't exist, skipping self-update" % source) | 263 logging.warning("File %s doesn't exist, skipping self-update" % source) |
274 return | 264 return |
275 | 265 |
276 target = __file__ | 266 target = __file__ |
277 with io.open(target, "rb") as handle: | 267 with io.open(target, "rb") as handle: |
278 targetdata = handle.read() | 268 targetdata = handle.read() |
279 | 269 |
280 if sourcedata != targetdata: | 270 if sourcedata != targetdata: |
281 logging.info("Updating %s from %s, don't forget to commit" % (source, targ et)) | 271 logging.info("Updating %s from %s, don't forget to commit" % (source, targ et)) |
282 with io.open(target, "wb") as handle: | 272 with io.open(target, "wb") as handle: |
283 handle.write(sourcedata) | 273 handle.write(sourcedata) |
284 if __name__ == "__main__": | 274 if __name__ == "__main__": |
285 logging.info("Restarting %s" % target) | 275 logging.info("Restarting %s" % target) |
286 os.execv(sys.executable, [sys.executable, target] + sys.argv[1:]) | 276 os.execv(sys.executable, [sys.executable, target] + sys.argv[1:]) |
287 else: | 277 else: |
288 logging.warning("Cannot restart %s automatically, please rerun" % target ) | 278 logging.warning("Cannot restart %s automatically, please rerun" % target ) |
289 | 279 |
280 def _ensure_line_exists(path, pattern): | |
281 with open(path, 'a+') as f: | |
282 file_content = [l.strip() for l in f.readlines()] | |
283 if not pattern in file_content: | |
284 file_content.append(pattern) | |
285 f.seek(0, os.SEEK_SET) | |
286 f.truncate() | |
287 for l in file_content: | |
288 print >>f, l | |
289 | |
290 if __name__ == "__main__": | 290 if __name__ == "__main__": |
291 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO) | 291 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO) |
292 repos = sys.argv[1:] | 292 repos = sys.argv[1:] |
293 if not len(repos): | 293 if not len(repos): |
294 repos = [os.getcwd()] | 294 repos = [os.getcwd()] |
295 for repo in repos: | 295 for repo in repos: |
296 resolve_deps(repo) | 296 resolve_deps(repo) |
LEFT | RIGHT |