/misc/build_helpers/show-tool-versions.py

https://github.com/jsgf/tahoe-lafs
Python | 162 lines | 142 code | 18 blank | 2 comment | 27 complexity | e3b9d8d824da3e9b3996293b2013c397 MD5 | raw file
  1. #! /usr/bin/env python
  2. import locale, os, subprocess, sys, traceback
  3. added_zetuptoolz_egg = False
  4. try:
  5. import pkg_resources
  6. pkg_resources # hush pyflakes
  7. except ImportError:
  8. import glob
  9. eggz = glob.glob('setuptools-*.egg')
  10. if len(eggz) > 0:
  11. egg = os.path.realpath(eggz[0])
  12. print >>sys.stderr, "Inserting egg on sys.path: %r" % (egg,)
  13. added_zetuptoolz_egg = True
  14. sys.path.insert(0, egg)
  15. def foldlines(s):
  16. return s.replace("\n", " ").replace("\r", "")
  17. def print_platform():
  18. print
  19. try:
  20. import platform
  21. out = platform.platform()
  22. print "platform:", foldlines(out)
  23. print "machine: ", platform.machine()
  24. if hasattr(platform, 'linux_distribution'):
  25. print "linux_distribution:", repr(platform.linux_distribution())
  26. except EnvironmentError:
  27. sys.stderr.write("\nGot exception using 'platform'. Exception follows\n")
  28. traceback.print_exc(file=sys.stderr)
  29. sys.stderr.flush()
  30. pass
  31. def print_python_ver():
  32. print
  33. print "python:", foldlines(sys.version)
  34. print 'maxunicode: ' + str(sys.maxunicode)
  35. def print_python_encoding_settings():
  36. print
  37. print 'filesystem.encoding: ' + str(sys.getfilesystemencoding())
  38. print 'locale.getpreferredencoding: ' + str(locale.getpreferredencoding())
  39. try:
  40. print 'locale.defaultlocale: ' + str(locale.getdefaultlocale())
  41. except ValueError, e:
  42. print 'got exception from locale.getdefaultlocale(): ', e
  43. print 'locale.locale: ' + str(locale.getlocale())
  44. def print_stdout(cmdlist, label=None):
  45. print
  46. try:
  47. res = subprocess.Popen(cmdlist, stdin=open(os.devnull),
  48. stdout=subprocess.PIPE).communicate()[0]
  49. if label is None:
  50. label = cmdlist[0]
  51. print label + ': ' + foldlines(res)
  52. except EnvironmentError:
  53. sys.stderr.write("\nGot exception invoking '%s'. Exception follows.\n" % (cmdlist[0],))
  54. traceback.print_exc(file=sys.stderr)
  55. sys.stderr.flush()
  56. pass
  57. def print_as_ver():
  58. print
  59. if os.path.exists('a.out'):
  60. print "WARNING: a file named a.out exists, and getting the version of the 'as' assembler writes to that filename, so I'm not attempting to get the version of 'as'."
  61. return
  62. try:
  63. res = subprocess.Popen(['as', '-version'], stdin=open(os.devnull),
  64. stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
  65. print 'as: ' + foldlines(res[0]+' '+res[1])
  66. if os.path.exists('a.out'):
  67. os.remove('a.out')
  68. except EnvironmentError:
  69. sys.stderr.write("\nGot exception invoking '%s'. Exception follows.\n" % ('as',))
  70. traceback.print_exc(file=sys.stderr)
  71. sys.stderr.flush()
  72. pass
  73. def print_setuptools_ver():
  74. print
  75. if added_zetuptoolz_egg:
  76. # it would be misleading to report the bundled version of zetuptoolz as the installed version
  77. print "setuptools: using bundled egg"
  78. return
  79. try:
  80. import pkg_resources
  81. out = str(pkg_resources.require("setuptools"))
  82. print "setuptools:", foldlines(out)
  83. except (ImportError, EnvironmentError):
  84. sys.stderr.write("\nGot exception using 'pkg_resources' to get the version of setuptools. Exception follows\n")
  85. traceback.print_exc(file=sys.stderr)
  86. sys.stderr.flush()
  87. pass
  88. def print_py_pkg_ver(pkgname, modulename=None):
  89. if modulename is None:
  90. modulename = pkgname
  91. print
  92. try:
  93. import pkg_resources
  94. out = str(pkg_resources.require(pkgname))
  95. print pkgname + ': ' + foldlines(out)
  96. except (ImportError, EnvironmentError):
  97. sys.stderr.write("\nGot exception using 'pkg_resources' to get the version of %s. Exception follows.\n" % (pkgname,))
  98. traceback.print_exc(file=sys.stderr)
  99. sys.stderr.flush()
  100. pass
  101. except pkg_resources.DistributionNotFound:
  102. sys.stderr.write("\npkg_resources reported no %s package installed. Exception follows.\n" % (pkgname,))
  103. traceback.print_exc(file=sys.stderr)
  104. sys.stderr.flush()
  105. pass
  106. try:
  107. __import__(modulename)
  108. except ImportError:
  109. pass
  110. else:
  111. modobj = sys.modules.get(modulename)
  112. print pkgname + ' module: ' + str(modobj)
  113. try:
  114. print pkgname + ' __version__: ' + str(modobj.__version__)
  115. except AttributeError:
  116. pass
  117. print_platform()
  118. print_python_ver()
  119. print_stdout(['locale'])
  120. print_python_encoding_settings()
  121. print_stdout(['buildbot', '--version'])
  122. print_stdout(['cl'])
  123. print_stdout(['gcc', '--version'])
  124. print_stdout(['g++', '--version'])
  125. print_stdout(['cryptest', 'V'])
  126. print_stdout(['darcs', '--version'])
  127. print_stdout(['darcs', '--exact-version'], label='darcs-exact-version')
  128. print_stdout(['7za'])
  129. print_stdout(['flappclient', '--version'])
  130. print_stdout(['valgrind', '--version'])
  131. print_as_ver()
  132. print_setuptools_ver()
  133. print_py_pkg_ver('coverage')
  134. print_py_pkg_ver('trialcoverage')
  135. print_py_pkg_ver('setuptools_trial')
  136. print_py_pkg_ver('pyflakes')
  137. print_py_pkg_ver('zope.interface')
  138. print_py_pkg_ver('setuptools_darcs')
  139. print_py_pkg_ver('darcsver')
  140. print_py_pkg_ver('Twisted', 'twisted')
  141. print_py_pkg_ver('TwistedCore', 'twisted.python')
  142. print_py_pkg_ver('TwistedWeb', 'twisted.web')
  143. print_py_pkg_ver('TwistedConch', 'twisted.conch')
  144. print_py_pkg_ver('pycryptopp')