OLD | NEW |
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 Loading... |
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 config_path = os.path.join(repo, '.hg', 'hgrc') |
| 74 ignore_file = os.path.join('.hg', 'dependencies') |
| 75 ignore_path = os.path.join(repo, ignore_file) |
73 | 76 |
74 if not self.istype(target): | 77 config = RawConfigParser() |
| 78 config.read(config_path) |
75 | 79 |
76 config_path = os.path.join(repo, '.hg', 'hgrc') | 80 if not config.has_section('ui'): |
77 ignore_path = os.path.abspath(os.path.join(repo, '.hg', 'dependencie
s')) | 81 config.add_section('ui') |
78 | 82 |
79 config = RawConfigParser() | 83 config.set('ui', 'ignore.dependencies', ignore_file) |
80 config.read(config_path) | 84 with open(config_path, 'w') as stream: |
| 85 config.write(stream) |
81 | 86 |
82 if not config.has_section('ui'): | 87 module = os.path.relpath(target, repo) |
83 config.add_section('ui') | 88 _ensure_line_exists(ignore_path, module) |
84 | |
85 config.set('ui', 'ignore.dependencies', ignore_path) | |
86 with open(config_path, 'w') as stream: | |
87 config.write(stream) | |
88 | |
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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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) |
OLD | NEW |