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 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 if not config.has_section("ui"): | 72 if not config.has_section("ui"): |
73 config.add_section("ui") | 73 config.add_section("ui") |
74 | 74 |
75 config.set("ui", "ignore.dependencies", ignore_path) | 75 config.set("ui", "ignore.dependencies", ignore_path) |
76 with open(config_path, "w") as stream: | 76 with open(config_path, "w") as stream: |
77 config.write(stream) | 77 config.write(stream) |
78 | 78 |
79 module = os.path.relpath(target, repo) | 79 module = os.path.relpath(target, repo) |
80 _ensure_line_exists(ignore_path, module) | 80 _ensure_line_exists(ignore_path, module) |
81 | 81 |
82 def postprocess_url(self, url): | |
83 return url | |
84 | |
82 class Git(): | 85 class Git(): |
83 def istype(self, repodir): | 86 def istype(self, repodir): |
84 return os.path.exists(os.path.join(repodir, ".git")) | 87 return os.path.exists(os.path.join(repodir, ".git")) |
85 | 88 |
86 def clone(self, source, target): | 89 def clone(self, source, target): |
87 source = source.rstrip("/") | 90 source = source.rstrip("/") |
88 if not source.endswith(".git"): | 91 if not source.endswith(".git"): |
89 source += ".git" | 92 source += ".git" |
90 subprocess.check_call(["git", "clone", "--quiet", source, target]) | 93 subprocess.check_call(["git", "clone", "--quiet", source, target]) |
91 | 94 |
92 def get_revision_id(self, repo, rev="HEAD"): | 95 def get_revision_id(self, repo, rev="HEAD"): |
93 command = ["git", "rev-parse", "--revs-only", rev + '^{commit}'] | 96 command = ["git", "rev-parse", "--revs-only", rev + '^{commit}'] |
94 return subprocess.check_output(command, cwd=repo).strip() | 97 return subprocess.check_output(command, cwd=repo).strip() |
95 | 98 |
96 def pull(self, repo): | 99 def pull(self, repo): |
97 subprocess.check_call(["git", "fetch", "--quiet", "--all", "--tags"], cwd=re po) | 100 subprocess.check_call(["git", "fetch", "--quiet", "--all", "--tags"], cwd=re po) |
98 | 101 |
99 def update(self, repo, rev): | 102 def update(self, repo, rev): |
100 subprocess.check_call(["git", "checkout", "--quiet", rev], cwd=repo) | 103 subprocess.check_call(["git", "checkout", "--quiet", rev], cwd=repo) |
101 | 104 |
102 def ignore(self, target, repo): | 105 def ignore(self, target, repo): |
103 module = os.path.relpath(target, repo) | 106 module = os.path.relpath(target, repo) |
104 exclude_file = os.path.join(repo, ".git", "info", "exclude") | 107 exclude_file = os.path.join(repo, ".git", "info", "exclude") |
105 _ensure_line_exists(exclude_file, module) | 108 _ensure_line_exists(exclude_file, module) |
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 | |
106 | 115 |
107 repo_types = OrderedDict(( | 116 repo_types = OrderedDict(( |
108 ("hg", Mercurial()), | 117 ("hg", Mercurial()), |
109 ("git", Git()), | 118 ("git", Git()), |
110 )) | 119 )) |
111 | 120 |
112 def parse_spec(path, line): | 121 def parse_spec(path, line): |
113 if "=" not in line: | 122 if "=" not in line: |
114 logging.warning("Invalid line in file %s: %s" % (path, line)) | 123 logging.warning("Invalid line in file %s: %s" % (path, line)) |
115 return None, None | 124 return None, None |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 if normpath == posixpath.pardir or normpath.startswith(posixpath.pardir + posi xpath.sep): | 177 if normpath == posixpath.pardir or normpath.startswith(posixpath.pardir + posi xpath.sep): |
169 raise Exception("Dependency path %s has to be inside the repository" % subpa th) | 178 raise Exception("Dependency path %s has to be inside the repository" % subpa th) |
170 return os.path.join(path, *normpath.split(posixpath.sep)) | 179 return os.path.join(path, *normpath.split(posixpath.sep)) |
171 | 180 |
172 def get_repo_type(repo): | 181 def get_repo_type(repo): |
173 for name, repotype in repo_types.iteritems(): | 182 for name, repotype in repo_types.iteritems(): |
174 if repotype.istype(repo): | 183 if repotype.istype(repo): |
175 return name | 184 return name |
176 return None | 185 return None |
177 | 186 |
178 def postprocess_url(url, type): | |
179 # Handle alternative syntax of Git SSH URLS | |
180 if (type == "git" and "@" in url and ":" in url and not urlparse.urlsplit(url) .scheme): | |
Sebastian Noack
2015/04/30 13:08:28
No explicit VCS switches please. We already have a
kzar
2015/04/30 13:27:12
Done.
| |
181 return "ssh://" + url.replace(":", "/", 1) | |
182 return url | |
183 | |
184 def ensure_repo(parentrepo, target, roots, sourcename): | 187 def ensure_repo(parentrepo, target, roots, sourcename): |
185 if os.path.exists(target): | 188 if os.path.exists(target): |
186 return | 189 return |
187 | 190 |
188 parenttype = get_repo_type(parentrepo) | 191 parenttype = get_repo_type(parentrepo) |
189 type = None | 192 type = None |
190 for key in roots: | 193 for key in roots: |
191 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): |
192 type = key | 195 type = key |
193 if type is None: | 196 if type is None: |
194 raise Exception("No valid source found to create %s" % target) | 197 raise Exception("No valid source found to create %s" % target) |
195 | 198 |
196 root = postprocess_url(roots[type], type) | 199 postprocess_url = repo_types[type].postprocess_url |
197 sourcename = postprocess_url(sourcename, type) | 200 root = postprocess_url(roots[type]) |
201 sourcename = postprocess_url(sourcename) | |
198 | 202 |
199 if os.path.exists(root): | 203 if os.path.exists(root): |
200 url = os.path.join(root, sourcename) | 204 url = os.path.join(root, sourcename) |
201 else: | 205 else: |
202 url = urlparse.urljoin(root, sourcename) | 206 url = urlparse.urljoin(root, sourcename) |
203 | 207 |
204 logging.info("Cloning repository %s into %s" % (url, target)) | 208 logging.info("Cloning repository %s into %s" % (url, target)) |
205 repo_types[type].clone(url, target) | 209 repo_types[type].clone(url, target) |
206 | 210 |
207 for repo in repo_types.itervalues(): | 211 for repo in repo_types.itervalues(): |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 args = parser.parse_args() | 303 args = parser.parse_args() |
300 | 304 |
301 if args.quiet: | 305 if args.quiet: |
302 logging.disable(logging.INFO) | 306 logging.disable(logging.INFO) |
303 | 307 |
304 repos = args.repos | 308 repos = args.repos |
305 if not len(repos): | 309 if not len(repos): |
306 repos = [os.path.dirname(__file__)] | 310 repos = [os.path.dirname(__file__)] |
307 for repo in repos: | 311 for repo in repos: |
308 resolve_deps(repo) | 312 resolve_deps(repo) |
LEFT | RIGHT |