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 # |
11 # Adblock Plus is distributed in the hope that it will be useful, | 11 # Adblock Plus is distributed in the hope that it will be useful, |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 # GNU General Public License for more details. | 14 # GNU General Public License for more details. |
15 # | 15 # |
16 # You should have received a copy of the GNU General Public License | 16 # You should have received a copy of the GNU General Public License |
17 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 17 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
18 | 18 |
19 import sys | 19 import sys |
20 import os | 20 import os |
21 import posixpath | 21 import posixpath |
22 import re | 22 import re |
23 import io | 23 import io |
24 import errno | 24 import errno |
25 import logging | 25 import logging |
26 import subprocess | 26 import subprocess |
27 import urlparse | 27 import urlparse |
28 from collections import OrderedDict | 28 from collections import OrderedDict |
29 | 29 |
30 usage = """ | 30 USAGE = """ |
Felix Dahlke
2014/09/06 20:48:32
Nit: I'd argue that this is a "constant", so I thi
Wladimir Palant
2014/09/09 15:47:36
Done.
| |
31 A dependencies file should look like this: | 31 A dependencies file should look like this: |
32 | 32 |
33 # VCS-specific root URLs for the repositories | 33 # VCS-specific root URLs for the repositories |
34 _root = hg:https://hg.adblockplus.org/ git:https://github.com/adblockplus/ | 34 _root = hg:https://hg.adblockplus.org/ git:https://github.com/adblockplus/ |
35 # File to update this script from (optional) | 35 # File to update this script from (optional) |
36 _self = buildtools/ensure_dependencies.py | 36 _self = buildtools/ensure_dependencies.py |
37 # Check out elemhidehelper repository into extensions/elemhidehelper directory | 37 # Check out elemhidehelper repository into extensions/elemhidehelper directory |
38 # at tag "1.2". | 38 # at tag "1.2". |
39 extensions/elemhidehelper = elemhidehelper 1.2 | 39 extensions/elemhidehelper = elemhidehelper 1.2 |
40 # Check out buildtools repository into buildtools directory at VCS-specific | 40 # Check out buildtools repository into buildtools directory at VCS-specific |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 if spec: | 134 if spec: |
135 result[key] = spec | 135 result[key] = spec |
136 return result | 136 return result |
137 except IOError, e: | 137 except IOError, e: |
138 if e.errno != errno.ENOENT: | 138 if e.errno != errno.ENOENT: |
139 raise | 139 raise |
140 return None | 140 return None |
141 | 141 |
142 def safe_join(path, subpath): | 142 def safe_join(path, subpath): |
143 # This has been inspired by Flask's safe_join() function | 143 # This has been inspired by Flask's safe_join() function |
144 forbidden = set([os.sep, os.altsep]) - set([posixpath.sep, None]) | |
145 if any(sep in subpath for sep in forbidden): | |
146 raise Exception("Illegal directory separator in dependency path %s" % subpat h) | |
147 | |
144 normpath = posixpath.normpath(subpath) | 148 normpath = posixpath.normpath(subpath) |
145 forbidden = set([os.sep, os.altsep]) - set([posixpath.sep, None]) | |
146 if any(sep in normpath for sep in forbidden): | |
Felix Dahlke
2014/09/06 20:48:32
I think we should do this check on subpath, before
Wladimir Palant
2014/09/09 15:47:36
Done.
| |
147 raise Exception("Illegal directory separator in dependency path %s" % subpat h) | |
148 if posixpath.isabs(normpath): | 149 if posixpath.isabs(normpath): |
149 raise Exception("Dependency path %s cannot be absolute" % subpath) | 150 raise Exception("Dependency path %s cannot be absolute" % subpath) |
150 if normpath == posixpath.pardir or normpath.startswith(posixpath.pardir + posi xpath.sep): | 151 if normpath == posixpath.pardir or normpath.startswith(posixpath.pardir + posi xpath.sep): |
151 raise Exception("Dependency path %s has to be inside the repository" % subpa th) | 152 raise Exception("Dependency path %s has to be inside the repository" % subpa th) |
152 return os.path.join(path, *normpath.split(posixpath.sep)) | 153 return os.path.join(path, *normpath.split(posixpath.sep)) |
153 | 154 |
154 def get_repo_type(repo): | 155 def get_repo_type(repo): |
155 for name, repotype in repo_types.iteritems(): | 156 for name, repotype in repo_types.iteritems(): |
156 if repotype.istype(repo): | 157 if repotype.istype(repo): |
157 return name | 158 return name |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 | 198 |
198 current_revision = repo_types[type].get_revision_id(target) | 199 current_revision = repo_types[type].get_revision_id(target) |
199 if resolved_revision != current_revision: | 200 if resolved_revision != current_revision: |
200 logging.info("Updating repository %s to revision %s" % (target, resolved_rev ision)) | 201 logging.info("Updating repository %s to revision %s" % (target, resolved_rev ision)) |
201 repo_types[type].update(target, resolved_revision) | 202 repo_types[type].update(target, resolved_revision) |
202 | 203 |
203 def resolve_deps(repodir, level=0, self_update=True, overrideroots=None, skipdep endencies=set()): | 204 def resolve_deps(repodir, level=0, self_update=True, overrideroots=None, skipdep endencies=set()): |
204 config = read_deps(repodir) | 205 config = read_deps(repodir) |
205 if config is None: | 206 if config is None: |
206 if level == 0: | 207 if level == 0: |
207 logging.warning("No dependencies file in directory %s, nothing to do...\n% s" % (repodir, usage)) | 208 logging.warning("No dependencies file in directory %s, nothing to do...\n% s" % (repodir, USAGE)) |
208 return | 209 return |
209 if level >= 10: | 210 if level >= 10: |
210 logging.warning("Too much subrepository nesting, ignoring %s" % repo) | 211 logging.warning("Too much subrepository nesting, ignoring %s" % repo) |
211 | 212 |
212 if overrideroots is not None: | 213 if overrideroots is not None: |
213 config["_root"] = overrideroots | 214 config["_root"] = overrideroots |
214 | 215 |
215 for dir, revisions in config.iteritems(): | 216 for dir, revisions in config.iteritems(): |
216 if dir.startswith("_") or revisions["_source"] in skipdependencies: | 217 if dir.startswith("_") or revisions["_source"] in skipdependencies: |
217 continue | 218 continue |
(...skipping 27 matching lines...) Expand all Loading... | |
245 else: | 246 else: |
246 logging.warning("Cannot restart %s automatically, please rerun" % target ) | 247 logging.warning("Cannot restart %s automatically, please rerun" % target ) |
247 | 248 |
248 if __name__ == "__main__": | 249 if __name__ == "__main__": |
249 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO) | 250 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO) |
250 repos = sys.argv[1:] | 251 repos = sys.argv[1:] |
251 if not len(repos): | 252 if not len(repos): |
252 repos = [os.getcwd()] | 253 repos = [os.getcwd()] |
253 for repo in repos: | 254 for repo in repos: |
254 resolve_deps(repo) | 255 resolve_deps(repo) |
LEFT | RIGHT |