OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """A git command for managing a local cache of git repositories.""" | 6 """A git command for managing a local cache of git repositories.""" |
7 | 7 |
8 from __future__ import print_function | 8 from __future__ import print_function |
9 import errno | 9 import errno |
10 import logging | 10 import logging |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 'Extracting bootstrap zipfile %s failed.\n' | 311 'Extracting bootstrap zipfile %s failed.\n' |
312 'Resuming normal operations.' % filename) | 312 'Resuming normal operations.' % filename) |
313 return False | 313 return False |
314 return True | 314 return True |
315 | 315 |
316 def exists(self): | 316 def exists(self): |
317 return os.path.isfile(os.path.join(self.mirror_path, 'config')) | 317 return os.path.isfile(os.path.join(self.mirror_path, 'config')) |
318 | 318 |
319 def populate(self, depth=None, shallow=False, bootstrap=False, | 319 def populate(self, depth=None, shallow=False, bootstrap=False, |
320 verbose=False): | 320 verbose=False): |
| 321 assert self.GetCachePath() |
321 if shallow and not depth: | 322 if shallow and not depth: |
322 depth = 10000 | 323 depth = 10000 |
323 gclient_utils.safe_makedirs(self.GetCachePath()) | 324 gclient_utils.safe_makedirs(self.GetCachePath()) |
324 | 325 |
325 v = [] | 326 v = [] |
326 if verbose: | 327 if verbose: |
327 v = ['-v', '--progress'] | 328 v = ['-v', '--progress'] |
328 | 329 |
329 d = [] | 330 d = [] |
330 if depth: | 331 if depth: |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 os.remove(lf) | 422 os.remove(lf) |
422 did_unlock = True | 423 did_unlock = True |
423 return did_unlock | 424 return did_unlock |
424 | 425 |
425 def unlock(self): | 426 def unlock(self): |
426 return self.BreakLocks(self.mirror_path) | 427 return self.BreakLocks(self.mirror_path) |
427 | 428 |
428 @classmethod | 429 @classmethod |
429 def UnlockAll(cls): | 430 def UnlockAll(cls): |
430 cachepath = cls.GetCachePath() | 431 cachepath = cls.GetCachePath() |
| 432 if not cachepath: |
| 433 return |
431 dirlist = os.listdir(cachepath) | 434 dirlist = os.listdir(cachepath) |
432 repo_dirs = set([os.path.join(cachepath, path) for path in dirlist | 435 repo_dirs = set([os.path.join(cachepath, path) for path in dirlist |
433 if os.path.isdir(os.path.join(cachepath, path))]) | 436 if os.path.isdir(os.path.join(cachepath, path))]) |
434 for dirent in dirlist: | 437 for dirent in dirlist: |
435 if (dirent.endswith('.lock') and | 438 if (dirent.endswith('.lock') and |
436 os.path.isfile(os.path.join(cachepath, dirent))): | 439 os.path.isfile(os.path.join(cachepath, dirent))): |
437 repo_dirs.add(os.path.join(cachepath, dirent[:-5])) | 440 repo_dirs.add(os.path.join(cachepath, dirent[:-5])) |
438 | 441 |
439 unlocked_repos = [] | 442 unlocked_repos = [] |
440 for repo_dir in repo_dirs: | 443 for repo_dir in repo_dirs: |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 return options, args | 576 return options, args |
574 | 577 |
575 | 578 |
576 def main(argv): | 579 def main(argv): |
577 dispatcher = subcommand.CommandDispatcher(__name__) | 580 dispatcher = subcommand.CommandDispatcher(__name__) |
578 return dispatcher.execute(OptionParser(), argv) | 581 return dispatcher.execute(OptionParser(), argv) |
579 | 582 |
580 | 583 |
581 if __name__ == '__main__': | 584 if __name__ == '__main__': |
582 sys.exit(main(sys.argv[1:])) | 585 sys.exit(main(sys.argv[1:])) |
OLD | NEW |