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-11-06 22:44:04 +00:00
added_zetuptoolz_egg = False
try :
import pkg_resources
except ImportError :
import glob
2010-11-07 23:36:15 +00:00
eggz = glob . glob ( ' setuptools-*.egg ' )
2010-11-06 22:44:04 +00:00
if len ( eggz ) > 0 :
egg = os . path . realpath ( eggz [ 0 ] )
print >> sys . stderr , " Inserting egg on sys.path: %r " % ( egg , )
added_zetuptoolz_egg = True
sys . path . insert ( 0 , egg )
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-11-01 04:27:21 +00:00
print " machine: " , platform . machine ( )
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 :
2010-09-20 22:54:15 +00:00
sys . stderr . write ( " \n Got exception using ' platform ' . Exception follows \n " )
2010-09-19 01:15:54 +00:00
traceback . print_exc ( file = sys . stderr )
2010-09-20 22:54:15 +00:00
sys . stderr . flush ( )
2010-09-19 01:15:54 +00:00
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 )
2010-10-15 05:44:40 +00:00
try :
print ' locale.defaultlocale: ' + str ( locale . getdefaultlocale ( ) )
except ValueError , e :
print ' got exception from locale.getdefaultlocale(): ' , e
2010-08-03 10:11:28 +00:00
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 :
2010-09-20 22:54:15 +00:00
sys . stderr . write ( " \n Got exception invoking ' %s ' . Exception follows. \n " % ( cmdlist [ 0 ] , ) )
2010-09-19 01:15:54 +00:00
traceback . print_exc ( file = sys . stderr )
2010-09-20 22:54:15 +00:00
sys . stderr . flush ( )
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 :
2010-09-20 22:54:15 +00:00
sys . stderr . write ( " \n Got exception invoking ' %s ' . Exception follows \n " % ( cmdlist [ 0 ] , ) )
2010-09-19 01:15:54 +00:00
traceback . print_exc ( file = sys . stderr )
2010-09-20 22:54:15 +00:00
sys . stderr . flush ( )
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 :
2010-09-20 22:54:15 +00:00
sys . stderr . write ( " \n Got exception invoking ' %s ' . Exception follows. \n " % ( ' as ' , ) )
2010-09-19 01:15:54 +00:00
traceback . print_exc ( file = sys . stderr )
2010-09-20 22:54:15 +00:00
sys . stderr . flush ( )
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-11-06 22:44:04 +00:00
if added_zetuptoolz_egg :
# it would be misleading to report the bundled version of zetuptoolz as the installed version
print " setuptools: using bundled egg "
return
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 ) :
2010-09-20 22:54:15 +00:00
sys . stderr . write ( " \n Got exception using ' pkg_resources ' to get the version of setuptools. Exception follows \n " )
2010-09-19 01:15:54 +00:00
traceback . print_exc ( file = sys . stderr )
2010-09-20 22:54:15 +00:00
sys . stderr . flush ( )
2010-05-16 05:01:22 +00:00
pass
2009-06-21 05:58:46 +00:00
2010-10-30 07:02:33 +00:00
def print_py_pkg_ver ( pkgname , modulename = None ) :
if modulename is None :
modulename = 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 ) :
2010-09-20 22:54:15 +00:00
sys . stderr . write ( " \n Got exception using ' pkg_resources ' to get the version of %s . Exception follows. \n " % ( pkgname , ) )
2010-09-19 01:15:54 +00:00
traceback . print_exc ( file = sys . stderr )
2010-09-20 22:54:15 +00:00
sys . stderr . flush ( )
2010-05-16 05:01:22 +00:00
pass
2010-09-19 01:15:54 +00:00
except pkg_resources . DistributionNotFound :
2010-09-20 22:54:15 +00:00
sys . stderr . write ( " \n pkg_resources reported no %s package installed. Exception follows. \n " % ( pkgname , ) )
2010-09-19 01:15:54 +00:00
traceback . print_exc ( file = sys . stderr )
2010-09-20 22:54:15 +00:00
sys . stderr . flush ( )
2010-05-16 05:01:22 +00:00
pass
2010-10-30 07:02:33 +00:00
try :
__import__ ( modulename )
except ImportError :
pass
else :
modobj = sys . modules . get ( modulename )
print pkgname + ' module: ' + str ( modobj )
try :
print pkgname + ' __version__: ' + str ( modobj . __version__ )
except AttributeError :
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-09-23 07:23:25 +00:00
print_stdout ( [ ' flappclient ' , ' --version ' ] )
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 ' )
2010-10-30 07:02:33 +00:00
print_py_pkg_ver ( ' Twisted ' , ' twisted ' )
print_py_pkg_ver ( ' TwistedCore ' , ' twisted.python ' )
print_py_pkg_ver ( ' TwistedWeb ' , ' twisted.web ' )
print_py_pkg_ver ( ' TwistedConch ' , ' twisted.conch ' )