selfupdate.py 2.0 KB

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