version.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. import platform
  18. import sys
  19. from command import Command, MirrorSafeCommand
  20. from git_command import git, RepoSourceVersion, user_agent
  21. from git_refs import HEAD
  22. class Version(Command, MirrorSafeCommand):
  23. wrapper_version = None
  24. wrapper_path = None
  25. common = False
  26. helpSummary = "Display the version of repo"
  27. helpUsage = """
  28. %prog
  29. """
  30. def Execute(self, opt, args):
  31. rp = self.manifest.repoProject
  32. rem = rp.GetRemote(rp.remote.name)
  33. # These might not be the same. Report them both.
  34. src_ver = RepoSourceVersion()
  35. rp_ver = rp.bare_git.describe(HEAD)
  36. print('repo version %s' % rp_ver)
  37. print(' (from %s)' % rem.url)
  38. print(' (%s)' % rp.bare_git.log('-1', '--format=%cD', HEAD))
  39. if self.wrapper_path is not None:
  40. print('repo launcher version %s' % self.wrapper_version)
  41. print(' (from %s)' % self.wrapper_path)
  42. if src_ver != rp_ver:
  43. print(' (currently at %s)' % src_ver)
  44. print('repo User-Agent %s' % user_agent.repo)
  45. print('git %s' % git.version_tuple().full)
  46. print('git User-Agent %s' % user_agent.git)
  47. print('Python %s' % sys.version)
  48. uname = platform.uname()
  49. if sys.version_info.major < 3:
  50. # Python 3 returns a named tuple, but Python 2 is simpler.
  51. print(uname)
  52. else:
  53. print('OS %s %s (%s)' % (uname.system, uname.release, uname.version))
  54. print('CPU %s (%s)' %
  55. (uname.machine, uname.processor if uname.processor else 'unknown'))