selfupdate.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #
  2. # Copyright (C) 2009 The Android Open Source Project
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from __future__ import print_function
  16. from optparse import SUPPRESS_HELP
  17. import sys
  18. from command import Command, MirrorSafeCommand
  19. from subcmds.sync import _PostRepoUpgrade
  20. from subcmds.sync import _PostRepoFetch
  21. class Selfupdate(Command, MirrorSafeCommand):
  22. common = False
  23. helpSummary = "Update repo to the latest version"
  24. helpUsage = """
  25. %prog
  26. """
  27. helpDescription = """
  28. The '%prog' command upgrades repo to the latest version, if a
  29. newer version is available.
  30. Normally this is done automatically by 'repo sync' and does not
  31. need to be performed by an end-user.
  32. """
  33. def _Options(self, p):
  34. g = p.add_option_group('repo Version options')
  35. g.add_option('--no-repo-verify',
  36. dest='no_repo_verify', action='store_true',
  37. help='do not verify repo source code')
  38. g.add_option('--repo-upgraded',
  39. dest='repo_upgraded', action='store_true',
  40. help=SUPPRESS_HELP)
  41. def Execute(self, opt, args):
  42. rp = self.manifest.repoProject
  43. rp.PreSync()
  44. if opt.repo_upgraded:
  45. _PostRepoUpgrade(self.manifest)
  46. else:
  47. if not rp.Sync_NetworkHalf():
  48. print("error: can't update repo", file=sys.stderr)
  49. sys.exit(1)
  50. rp.bare_git.gc('--auto')
  51. _PostRepoFetch(rp,
  52. no_repo_verify = opt.no_repo_verify,
  53. verbose = True)