2009-02-19 08:35:58 +00:00
#! /usr/bin/env python
2012-04-01 00:59:25 +00:00
import locale , os , platform , 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
2011-01-21 02:10:11 +00:00
pkg_resources # hush pyflakes
2010-11-06 22:44:04 +00:00
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 )
2011-11-01 07:45:32 +00:00
def foldlines ( s , numlines = None ) :
lines = s . split ( " \n " )
if numlines is not None :
lines = lines [ : numlines ]
return " " . join ( lines ) . replace ( " \r " , " " )
2010-08-03 10:11:28 +00:00
2010-05-16 05:01:22 +00:00
def print_platform ( ) :
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-08-03 10:11:28 +00:00
print " python: " , foldlines ( sys . version )
print ' maxunicode: ' + str ( sys . maxunicode )
def print_python_encoding_settings ( ) :
print ' filesystem.encoding: ' + str ( sys . getfilesystemencoding ( ) )
print ' locale.getpreferredencoding: ' + str ( locale . getpreferredencoding ( ) )
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
2011-11-01 07:45:32 +00:00
def print_stdout ( cmdlist , label = None , numlines = None ) :
2010-06-09 04:07:14 +00:00
try :
2010-08-03 10:11:28 +00:00
if label is None :
label = cmdlist [ 0 ]
2011-11-01 07:45:32 +00:00
res = subprocess . Popen ( cmdlist , stdin = open ( os . devnull ) ,
stdout = subprocess . PIPE ) . communicate ( ) [ 0 ]
print label + ' : ' + foldlines ( res , numlines )
except EnvironmentError , e :
if isinstance ( e , OSError ) and e . errno == 2 :
print label + ' : no such file or directory '
return
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-05-16 05:01:22 +00:00
def print_as_ver ( ) :
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-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
2011-11-01 08:00:10 +00:00
except pkg_resources . DistributionNotFound :
print ' setuptools: DistributionNotFound '
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 :
2011-11-01 07:45:32 +00:00
print pkgname + ' : DistributionNotFound '
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 ( )
2011-11-01 07:45:32 +00:00
print
2010-05-16 05:01:22 +00:00
print_python_ver ( )
2011-11-01 07:45:32 +00:00
print
2010-08-03 10:11:28 +00:00
print_stdout ( [ ' locale ' ] )
2010-06-09 04:07:14 +00:00
print_python_encoding_settings ( )
2011-11-01 07:45:32 +00:00
print
2010-08-03 10:11:28 +00:00
print_stdout ( [ ' buildbot ' , ' --version ' ] )
2012-04-01 00:59:25 +00:00
print_stdout ( [ ' buildslave ' , ' --version ' ] )
if ' windows ' in platform . system ( ) . lower ( ) :
2012-04-01 02:28:26 +00:00
print_stdout ( [ ' cl ' ] )
2011-11-01 07:45:32 +00:00
print_stdout ( [ ' gcc ' , ' --version ' ] , numlines = 1 )
print_stdout ( [ ' g++ ' , ' --version ' ] , numlines = 1 )
2010-08-03 10:11:28 +00:00
print_stdout ( [ ' cryptest ' , ' V ' ] )
2012-04-01 00:59:25 +00:00
print_stdout ( [ ' git ' , ' --version ' ] )
print_stdout ( [ ' openssl ' , ' version ' ] )
2010-09-23 07:23:25 +00:00
print_stdout ( [ ' flappclient ' , ' --version ' ] )
2010-11-18 03:06:23 +00:00
print_stdout ( [ ' valgrind ' , ' --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 ' )
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-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 ' )
2010-11-14 10:05:40 +00:00
print_py_pkg_ver ( ' pycryptopp ' )
2014-04-15 16:24:36 +00:00
print_py_pkg_ver ( ' cryptography ' )
print_py_pkg_ver ( ' cffi ' )