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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 with zipfile.ZipFile(filename, 'r') as f: | 305 with zipfile.ZipFile(filename, 'r') as f: |
306 f.printdir() | 306 f.printdir() |
307 f.extractall(directory) | 307 f.extractall(directory) |
308 except Exception as e: | 308 except Exception as e: |
309 self.print('Encountered error: %s' % str(e), file=sys.stderr) | 309 self.print('Encountered error: %s' % str(e), file=sys.stderr) |
310 retcode = 1 | 310 retcode = 1 |
311 else: | 311 else: |
312 retcode = 0 | 312 retcode = 0 |
313 finally: | 313 finally: |
314 # Clean up the downloaded zipfile. | 314 # Clean up the downloaded zipfile. |
315 gclient_utils.rmtree(tempdir) | 315 gclient_utils.rm_file_or_tree(tempdir) |
316 | 316 |
317 if retcode: | 317 if retcode: |
318 self.print( | 318 self.print( |
319 'Extracting bootstrap zipfile %s failed.\n' | 319 'Extracting bootstrap zipfile %s failed.\n' |
320 'Resuming normal operations.' % filename) | 320 'Resuming normal operations.' % filename) |
321 return False | 321 return False |
322 return True | 322 return True |
323 | 323 |
324 def exists(self): | 324 def exists(self): |
325 return os.path.isfile(os.path.join(self.mirror_path, 'config')) | 325 return os.path.isfile(os.path.join(self.mirror_path, 'config')) |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 @classmethod | 479 @classmethod |
480 def UnlockAll(cls): | 480 def UnlockAll(cls): |
481 cachepath = cls.GetCachePath() | 481 cachepath = cls.GetCachePath() |
482 if not cachepath: | 482 if not cachepath: |
483 return | 483 return |
484 dirlist = os.listdir(cachepath) | 484 dirlist = os.listdir(cachepath) |
485 repo_dirs = set([os.path.join(cachepath, path) for path in dirlist | 485 repo_dirs = set([os.path.join(cachepath, path) for path in dirlist |
486 if os.path.isdir(os.path.join(cachepath, path))]) | 486 if os.path.isdir(os.path.join(cachepath, path))]) |
487 for dirent in dirlist: | 487 for dirent in dirlist: |
488 if dirent.startswith('_cache_tmp') or dirent.startswith('tmp'): | 488 if dirent.startswith('_cache_tmp') or dirent.startswith('tmp'): |
489 gclient_utils.rmtree(os.path.join(cachepath, dirent)) | 489 gclient_utils.rm_file_or_tree(os.path.join(cachepath, dirent)) |
490 elif (dirent.endswith('.lock') and | 490 elif (dirent.endswith('.lock') and |
491 os.path.isfile(os.path.join(cachepath, dirent))): | 491 os.path.isfile(os.path.join(cachepath, dirent))): |
492 repo_dirs.add(os.path.join(cachepath, dirent[:-5])) | 492 repo_dirs.add(os.path.join(cachepath, dirent[:-5])) |
493 | 493 |
494 unlocked_repos = [] | 494 unlocked_repos = [] |
495 for repo_dir in repo_dirs: | 495 for repo_dir in repo_dirs: |
496 if cls.BreakLocks(repo_dir): | 496 if cls.BreakLocks(repo_dir): |
497 unlocked_repos.append(repo_dir) | 497 unlocked_repos.append(repo_dir) |
498 | 498 |
499 return unlocked_repos | 499 return unlocked_repos |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 return options, args | 684 return options, args |
685 | 685 |
686 | 686 |
687 def main(argv): | 687 def main(argv): |
688 dispatcher = subcommand.CommandDispatcher(__name__) | 688 dispatcher = subcommand.CommandDispatcher(__name__) |
689 return dispatcher.execute(OptionParser(), argv) | 689 return dispatcher.execute(OptionParser(), argv) |
690 | 690 |
691 | 691 |
692 if __name__ == '__main__': | 692 if __name__ == '__main__': |
693 sys.exit(main(sys.argv[1:])) | 693 sys.exit(main(sys.argv[1:])) |
OLD | NEW |