selfupdate.py 1.9 KB

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