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

Delta Between Two Patch Sets: ensure_dependencies.py

Issue 29374637: Issue 4549 - Implement the Windows Store API to upload development builds (Closed)
Left Patch Set: Switch to urllib2 Created Feb. 15, 2017, 3:41 a.m.
Right Patch Set: Rebase Created Feb. 16, 2017, 1:14 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « dependencies ('k') | sitescripts/extensions/bin/createNightlies.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 # This Source Code Form is subject to the terms of the Mozilla Public 3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this 4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 6
7 import sys 7 import sys
8 import os 8 import os
9 import posixpath 9 import posixpath
10 import re 10 import re
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subpro cess.PIPE).communicate()[0] 63 result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subpro cess.PIPE).communicate()[0]
64 return result.strip() 64 return result.strip()
65 65
66 def pull(self, repo): 66 def pull(self, repo):
67 subprocess.check_call(['hg', 'pull', '--repository', repo, '--quiet']) 67 subprocess.check_call(['hg', 'pull', '--repository', repo, '--quiet'])
68 68
69 def update(self, repo, rev, revname): 69 def update(self, repo, rev, revname):
70 subprocess.check_call(['hg', 'update', '--repository', repo, '--quiet', '--check', '--rev', rev]) 70 subprocess.check_call(['hg', 'update', '--repository', repo, '--quiet', '--check', '--rev', rev])
71 71
72 def ignore(self, target, repo): 72 def ignore(self, target, repo):
73 73 config_path = os.path.join(repo, '.hg', 'hgrc')
74 if not self.istype(target): 74 ignore_file = os.path.join('.hg', 'dependencies')
75 75 ignore_path = os.path.join(repo, ignore_file)
76 config_path = os.path.join(repo, '.hg', 'hgrc') 76
77 ignore_path = os.path.abspath(os.path.join(repo, '.hg', 'dependencie s')) 77 config = RawConfigParser()
78 78 config.read(config_path)
79 config = RawConfigParser() 79
80 config.read(config_path) 80 if not config.has_section('ui'):
81 81 config.add_section('ui')
82 if not config.has_section('ui'): 82
83 config.add_section('ui') 83 config.set('ui', 'ignore.dependencies', ignore_file)
84 84 with open(config_path, 'w') as stream:
85 config.set('ui', 'ignore.dependencies', ignore_path) 85 config.write(stream)
86 with open(config_path, 'w') as stream: 86
87 config.write(stream) 87 module = os.path.relpath(target, repo)
88 88 _ensure_line_exists(ignore_path, module)
89 module = os.path.relpath(target, repo)
90 _ensure_line_exists(ignore_path, module)
91 89
92 def postprocess_url(self, url): 90 def postprocess_url(self, url):
93 return url 91 return url
94 92
95 93
96 class Git(): 94 class Git():
97 def istype(self, repodir): 95 def istype(self, repodir):
98 return os.path.exists(os.path.join(repodir, '.git')) 96 return os.path.exists(os.path.join(repodir, '.git'))
99 97
100 def clone(self, source, target): 98 def clone(self, source, target):
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 for line in handle: 211 for line in handle:
214 # Remove comments and whitespace 212 # Remove comments and whitespace
215 line = re.sub(r'#.*', '', line).strip() 213 line = re.sub(r'#.*', '', line).strip()
216 if not line: 214 if not line:
217 continue 215 continue
218 216
219 key, spec = parse_spec(deps_path, line) 217 key, spec = parse_spec(deps_path, line)
220 if spec: 218 if spec:
221 result[key] = spec 219 result[key] = spec
222 return result 220 return result
223 except IOError, e: 221 except IOError as e:
224 if e.errno != errno.ENOENT: 222 if e.errno != errno.ENOENT:
225 raise 223 raise
226 return None 224 return None
227 225
228 226
229 def safe_join(path, subpath): 227 def safe_join(path, subpath):
230 # This has been inspired by Flask's safe_join() function 228 # This has been inspired by Flask's safe_join() function
231 forbidden = {os.sep, os.altsep} - {posixpath.sep, None} 229 forbidden = {os.sep, os.altsep} - {posixpath.sep, None}
232 if any(sep in subpath for sep in forbidden): 230 if any(sep in subpath for sep in forbidden):
233 raise Exception('Illegal directory separator in dependency path %s' % su bpath) 231 raise Exception('Illegal directory separator in dependency path %s' % su bpath)
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 ensure_repo(repodir, parenttype, target, vcs, _root.get(vcs, ''), source ) 323 ensure_repo(repodir, parenttype, target, vcs, _root.get(vcs, ''), source )
326 update_repo(target, vcs, rev) 324 update_repo(target, vcs, rev)
327 resolve_deps(target, level + 1, self_update=False, 325 resolve_deps(target, level + 1, self_update=False,
328 overrideroots=overrideroots, skipdependencies=skipdependenc ies) 326 overrideroots=overrideroots, skipdependencies=skipdependenc ies)
329 327
330 if self_update and '_self' in config and '*' in config['_self']: 328 if self_update and '_self' in config and '*' in config['_self']:
331 source = safe_join(repodir, config['_self']['*']) 329 source = safe_join(repodir, config['_self']['*'])
332 try: 330 try:
333 with io.open(source, 'rb') as handle: 331 with io.open(source, 'rb') as handle:
334 sourcedata = handle.read() 332 sourcedata = handle.read()
335 except IOError, e: 333 except IOError as e:
336 if e.errno != errno.ENOENT: 334 if e.errno != errno.ENOENT:
337 raise 335 raise
338 logging.warning("File %s doesn't exist, skipping self-update" % sour ce) 336 logging.warning("File %s doesn't exist, skipping self-update" % sour ce)
339 return 337 return
340 338
341 target = __file__ 339 target = __file__
342 with io.open(target, 'rb') as handle: 340 with io.open(target, 'rb') as handle:
343 targetdata = handle.read() 341 targetdata = handle.read()
344 342
345 if sourcedata != targetdata: 343 if sourcedata != targetdata:
346 logging.info("Updating %s from %s, don't forget to commit" % (target , source)) 344 logging.info("Updating %s from %s, don't forget to commit" % (target , source))
347 with io.open(target, 'wb') as handle: 345 with io.open(target, 'wb') as handle:
348 handle.write(sourcedata) 346 handle.write(sourcedata)
349 if __name__ == '__main__': 347 if __name__ == '__main__':
350 logging.info('Restarting %s' % target) 348 logging.info('Restarting %s' % target)
351 os.execv(sys.executable, [sys.executable, target] + sys.argv[1:] ) 349 os.execv(sys.executable, [sys.executable, target] + sys.argv[1:] )
352 else: 350 else:
353 logging.warning('Cannot restart %s automatically, please rerun' % target) 351 logging.warning('Cannot restart %s automatically, please rerun' % target)
354 352
355 353
356 def _ensure_line_exists(path, pattern): 354 def _ensure_line_exists(path, pattern):
357 with open(path, 'a+') as f: 355 with open(path, 'a+') as f:
356 f.seek(0, os.SEEK_SET)
358 file_content = [l.strip() for l in f.readlines()] 357 file_content = [l.strip() for l in f.readlines()]
359 if not pattern in file_content: 358 if not pattern in file_content:
360 file_content.append(pattern) 359 file_content.append(pattern)
361 f.seek(0, os.SEEK_SET) 360 f.seek(0, os.SEEK_SET)
362 f.truncate() 361 f.truncate()
363 for l in file_content: 362 for l in file_content:
364 print >>f, l 363 print >>f, l
365 364
366 if __name__ == '__main__': 365 if __name__ == '__main__':
367 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO) 366 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
368 367
369 parser = argparse.ArgumentParser(description='Verify dependencies for a set of repositories, by default the repository of this script.') 368 parser = argparse.ArgumentParser(description='Verify dependencies for a set of repositories, by default the repository of this script.')
370 parser.add_argument('repos', metavar='repository', type=str, nargs='*', help ='Repository path') 369 parser.add_argument('repos', metavar='repository', type=str, nargs='*', help ='Repository path')
371 parser.add_argument('-q', '--quiet', action='store_true', help='Suppress inf ormational output') 370 parser.add_argument('-q', '--quiet', action='store_true', help='Suppress inf ormational output')
372 args = parser.parse_args() 371 args = parser.parse_args()
373 372
374 if args.quiet: 373 if args.quiet:
375 logging.disable(logging.INFO) 374 logging.disable(logging.INFO)
376 375
377 repos = args.repos 376 repos = args.repos
378 if not len(repos): 377 if not len(repos):
379 repos = [os.path.dirname(__file__)] 378 repos = [os.path.dirname(__file__)]
380 for repo in repos: 379 for repo in repos:
381 resolve_deps(repo) 380 resolve_deps(repo)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld