version.py 2.1 KB

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