2009-02-19 08:35:58 +00:00
#! /usr/bin/env python
2010-09-19 01:15:54 +00:00
import locale , os , subprocess , sys , traceback
2010-05-04 04:56:43 +00:00
2010-08-03 10:11:28 +00:00
def foldlines ( s ) :
return s . replace ( " \n " , " " ) . replace ( " \r " , " " )
2010-05-16 05:01:22 +00:00
def print_platform ( ) :
2010-08-03 10:11:28 +00:00
print
2010-05-16 05:01:22 +00:00
try :
import platform
out = platform . platform ( )
2010-08-03 10:11:28 +00:00
print " platform: " , foldlines ( out )
2010-06-08 00:45:23 +00:00
if hasattr ( platform , ' linux_distribution ' ) :
print " linux_distribution: " , repr ( platform . linux_distribution ( ) )
2010-09-19 01:15:54 +00:00
except EnvironmentError :
sys . stderr . write ( " Got exception using ' platform ' . Exception follows \n " )
traceback . print_exc ( file = sys . stderr )
pass
2009-02-19 08:35:58 +00:00
2010-05-16 05:01:22 +00:00
def print_python_ver ( ) :
2010-06-09 04:07:14 +00:00
print
2010-08-03 10:11:28 +00:00
print " python: " , foldlines ( sys . version )
print ' maxunicode: ' + str ( sys . maxunicode )
def print_python_encoding_settings ( ) :
print_stderr ( [ sys . executable , ' -c ' , ' import sys; print >>sys.stderr, sys.stdout.encoding ' ] , label = ' sys.stdout.encoding ' )
print_stdout ( [ sys . executable , ' -c ' , ' import sys; print sys.stderr.encoding ' ] , label = ' sys.stderr.encoding ' )
print
print ' filesystem.encoding: ' + str ( sys . getfilesystemencoding ( ) )
print ' locale.getpreferredencoding: ' + str ( locale . getpreferredencoding ( ) )
print ' os.path.supports_unicode_filenames: ' + str ( os . path . supports_unicode_filenames )
print ' locale.defaultlocale: ' + str ( locale . getdefaultlocale ( ) )
print ' locale.locale: ' + str ( locale . getlocale ( ) )
2010-06-09 04:07:14 +00:00
2010-08-03 10:11:28 +00:00
def print_stdout ( cmdlist , label = None ) :
print
2010-06-09 04:07:14 +00:00
try :
res = subprocess . Popen ( cmdlist , stdin = open ( os . devnull ) ,
stdout = subprocess . PIPE ) . communicate ( ) [ 0 ]
2010-08-03 10:11:28 +00:00
if label is None :
label = cmdlist [ 0 ]
print label + ' : ' + foldlines ( res )
2010-09-19 01:15:54 +00:00
except EnvironmentError :
sys . stderr . write ( " Got exception invoking ' %s ' . Exception follows. \n " % ( cmdlist [ 0 ] , ) )
traceback . print_exc ( file = sys . stderr )
2010-06-09 04:07:14 +00:00
pass
2010-08-03 10:11:28 +00:00
def print_stderr ( cmdlist , label = None ) :
2010-06-09 04:07:14 +00:00
print
2010-05-16 05:01:22 +00:00
try :
res = subprocess . Popen ( cmdlist , stdin = open ( os . devnull ) ,
2010-08-03 10:11:28 +00:00
stderr = subprocess . PIPE ) . communicate ( ) [ 1 ]
2010-05-16 05:01:22 +00:00
if label is None :
label = cmdlist [ 0 ]
2010-08-03 10:11:28 +00:00
print label + ' : ' + foldlines ( res )
2010-09-19 01:15:54 +00:00
except EnvironmentError :
sys . stderr . write ( " Got exception invoking ' %s ' . Exception follows \n " % ( cmdlist [ 0 ] , ) )
traceback . print_exc ( file = sys . stderr )
2010-05-16 05:01:22 +00:00
pass
2010-05-04 04:56:43 +00:00
2010-05-16 05:01:22 +00:00
def print_as_ver ( ) :
2010-08-03 10:11:28 +00:00
print
2010-05-16 05:01:22 +00:00
if os . path . exists ( ' a.out ' ) :
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 ' . "
return
try :
res = subprocess . Popen ( [ ' as ' , ' -version ' ] , stdin = open ( os . devnull ) ,
2010-08-03 10:11:28 +00:00
stdout = subprocess . PIPE , stderr = subprocess . PIPE ) . communicate ( )
print ' as: ' + foldlines ( res [ 0 ] + ' ' + res [ 1 ] )
2010-08-03 09:48:12 +00:00
if os . path . exists ( ' a.out ' ) :
os . remove ( ' a.out ' )
2010-09-19 01:15:54 +00:00
except EnvironmentError :
sys . stderr . write ( " Got exception invoking ' %s ' . Exception follows. \n " % ( ' as ' , ) )
traceback . print_exc ( file = sys . stderr )
2010-05-16 05:01:22 +00:00
pass
2009-02-19 08:35:58 +00:00
2010-05-16 05:01:22 +00:00
def print_setuptools_ver ( ) :
2010-08-03 10:11:28 +00:00
print
2010-05-16 05:01:22 +00:00
try :
import pkg_resources
out = str ( pkg_resources . require ( " setuptools " ) )
2010-08-03 10:11:28 +00:00
print " setuptools: " , foldlines ( out )
2010-09-19 01:15:54 +00:00
except ( ImportError , EnvironmentError ) :
sys . stderr . write ( " Got exception using ' pkg_resources ' to get the version of setuptools. Exception follows \n " )
traceback . print_exc ( file = sys . stderr )
2010-05-16 05:01:22 +00:00
pass
2009-06-21 05:58:46 +00:00
2010-05-16 05:01:22 +00:00
def print_py_pkg_ver ( pkgname ) :
2010-08-03 10:11:28 +00:00
print
2010-05-16 05:01:22 +00:00
try :
import pkg_resources
out = str ( pkg_resources . require ( pkgname ) )
2010-08-03 10:11:28 +00:00
print pkgname + ' : ' + foldlines ( out )
2010-09-19 01:15:54 +00:00
except ( ImportError , EnvironmentError ) :
sys . stderr . write ( " Got exception using ' pkg_resources ' to get the version of %s . Exception follows. \n " % ( pkgname , ) )
traceback . print_exc ( file = sys . stderr )
2010-05-16 05:01:22 +00:00
pass
2010-09-19 01:15:54 +00:00
except pkg_resources . DistributionNotFound :
sys . stderr . write ( " pkg_resources reported no %s package installed. Exception follows. \n " % ( pkgname , ) )
traceback . print_exc ( file = sys . stderr )
2010-05-16 05:01:22 +00:00
pass
2009-06-21 05:58:46 +00:00
2010-05-16 05:01:22 +00:00
print_platform ( )
2010-05-04 04:56:43 +00:00
2010-05-16 05:01:22 +00:00
print_python_ver ( )
2010-05-04 04:56:43 +00:00
2010-08-03 10:11:28 +00:00
print_stdout ( [ ' locale ' ] )
2010-06-09 04:07:14 +00:00
print_python_encoding_settings ( )
2010-08-03 10:11:28 +00:00
print_stdout ( [ ' buildbot ' , ' --version ' ] )
print_stdout ( [ ' cl ' ] )
print_stdout ( [ ' gcc ' , ' --version ' ] )
print_stdout ( [ ' g++ ' , ' --version ' ] )
print_stdout ( [ ' cryptest ' , ' V ' ] )
print_stdout ( [ ' darcs ' , ' --version ' ] )
print_stdout ( [ ' darcs ' , ' --exact-version ' ] , label = ' darcs-exact-version ' )
print_stdout ( [ ' 7za ' ] )
2010-05-10 06:29:55 +00:00
2010-05-16 05:01:22 +00:00
print_as_ver ( )
2010-05-10 06:29:55 +00:00
2010-05-16 05:01:22 +00:00
print_setuptools_ver ( )
2010-05-10 06:29:55 +00:00
2010-05-16 05:01:22 +00:00
print_py_pkg_ver ( ' coverage ' )
print_py_pkg_ver ( ' trialcoverage ' )
print_py_pkg_ver ( ' setuptools_trial ' )
2010-06-07 05:16:18 +00:00
print_py_pkg_ver ( ' pyflakes ' )
2010-06-09 03:49:15 +00:00
print_py_pkg_ver ( ' zope.interface ' )
2010-09-18 22:04:10 +00:00
print_py_pkg_ver ( ' setuptools_darcs ' )
print_py_pkg_ver ( ' darcsver ' )