selfupdate.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 optparse import SUPPRESS_HELP
  16. import sys
  17. from command import Command, MirrorSafeCommand
  18. from subcmds.sync import _PostRepoUpgrade
  19. from subcmds.sync import _PostRepoFetch
  20. class Selfupdate(Command, MirrorSafeCommand):
  21. common = False
  22. helpSummary = "Update repo to the latest version"
  23. helpUsage = """
  24. %prog
  25. """
  26. helpDescription = """
  27. The '%prog' command upgrades repo to the latest version, if a
  28. newer version is available.
  29. Normally this is done automatically by 'repo sync' and does not
  30. need to be performed by an end-user.
  31. """
  32. def _Options(self, p):
  33. g = p.add_option_group('repo Version options')
  34. g.add_option('--no-repo-verify',
  35. dest='no_repo_verify', action='store_true',
  36. help='do not verify repo source code')
  37. g.add_option('--repo-upgraded',
  38. dest='repo_upgraded', action='store_true',
  39. help=SUPPRESS_HELP)
  40. def Execute(self, opt, args):
  41. rp = self.manifest.repoProject
  42. rp.PreSync()
  43. if opt.repo_upgraded:
  44. _PostRepoUpgrade(self.manifest)
  45. else:
  46. if not rp.Sync_NetworkHalf():
  47. print >>sys.stderr, "error: can't update repo"
  48. sys.exit(1)
  49. _PostRepoFetch(rp,
  50. no_repo_verify = opt.no_repo_verify,
  51. verbose = True)