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

Side by Side Diff: ensure_dependencies.py

Issue 29329056: Issue 3194 - Allow multiple sources for a dependency (Closed)
Patch Set: Created Oct. 12, 2015, 3:46 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 | « no previous file | 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
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 type, value = item.split(":", 1) 156 type, value = item.split(":", 1)
157 else: 157 else:
158 type, value = ("*", item) 158 type, value = ("*", item)
159 if type in result: 159 if type in result:
160 logging.warning("Ignoring duplicate value for type %s (key %s in file %s)" % (type, key, path)) 160 logging.warning("Ignoring duplicate value for type %s (key %s in file %s)" % (type, key, path))
161 else: 161 else:
162 result[type] = value 162 result[type] = value
163 return key, result 163 return key, result
164 164
165 def read_deps(repodir): 165 def read_deps(repodir):
166 parenttype = get_repo_type(repodir)
166 result = {} 167 result = {}
167 deps_path = os.path.join(repodir, "dependencies") 168 deps_path = os.path.join(repodir, "dependencies")
168 try: 169 try:
169 with io.open(deps_path, "rt", encoding="utf-8") as handle: 170 with io.open(deps_path, "rt", encoding="utf-8") as handle:
170 for line in handle: 171 for line in handle:
171 # Remove comments and whitespace 172 # Remove comments and whitespace
172 line = re.sub(r"#.*", "", line).strip() 173 line = re.sub(r"#.*", "", line).strip()
173 if not line: 174 if not line:
174 continue 175 continue
175 176
176 key, spec = parse_spec(deps_path, line) 177 key, spec = parse_spec(deps_path, line)
177 if spec: 178 if spec and (key not in result or parenttype in spec.keys()):
178 result[key] = spec 179 result[key] = spec
179 return result 180 return result
180 except IOError, e: 181 except IOError, e:
181 if e.errno != errno.ENOENT: 182 if e.errno != errno.ENOENT:
182 raise 183 raise
183 return None 184 return None
184 185
185 def safe_join(path, subpath): 186 def safe_join(path, subpath):
186 # This has been inspired by Flask's safe_join() function 187 # This has been inspired by Flask's safe_join() function
187 forbidden = {os.sep, os.altsep} - {posixpath.sep, None} 188 forbidden = {os.sep, os.altsep} - {posixpath.sep, None}
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 args = parser.parse_args() 333 args = parser.parse_args()
333 334
334 if args.quiet: 335 if args.quiet:
335 logging.disable(logging.INFO) 336 logging.disable(logging.INFO)
336 337
337 repos = args.repos 338 repos = args.repos
338 if not len(repos): 339 if not len(repos):
339 repos = [os.path.dirname(__file__)] 340 repos = [os.path.dirname(__file__)]
340 for repo in repos: 341 for repo in repos:
341 resolve_deps(repo) 342 resolve_deps(repo)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld