3232#
3333# <see CVS and SVN checkin messages for history>
3434#
35+ # 1.0.7 - added DEV_NULL
3536# 1.0.6 - added linux_distribution()
3637# 1.0.5 - fixed Java support to allow running the module on Jython
3738# 1.0.4 - added IronPython support
8990
9091__copyright__ = """
9192 Copyright (c) 1999-2000, Marc-Andre Lemburg; mailto:[email protected] 92- Copyright (c) 2000-2008 , eGenix.com Software GmbH; mailto:[email protected] 93+ Copyright (c) 2000-2009 , eGenix.com Software GmbH; mailto:[email protected] 9394
9495 Permission to use, copy, modify, and distribute this software and its
9596 documentation for any purpose and without fee or royalty is hereby granted,
108109
109110"""
110111
111- __version__ = '1.0.6 '
112+ __version__ = '1.0.7 '
112113
113114import sys , os , re
114115
116+ ### Globals & Constants
117+
118+ # Determine the platform's /dev/null device
119+ try :
120+ DEV_NULL = os .devnull
121+ except AttributeError :
122+ # os.devnull was added in Python 2.4, so emulate it for earlier
123+ # Python versions
124+ if sys .platform in ('dos' ,'win32' ,'win16' ,'os2' ):
125+ # Use the old CP/M NUL as device name
126+ DEV_NULL = 'NUL'
127+ else :
128+ # Standard Unix uses /dev/null
129+ DEV_NULL = '/dev/null'
130+
115131### Platform specific APIs
116132
117133_libc_search = re .compile (r'(__libc_init)'
@@ -446,7 +462,16 @@ def _norm_version(version, build=''):
446462
447463_ver_output = re .compile (r'(?:([\w ]+) ([\w.]+) '
448464 '.*'
449- 'Version ([\d.]+))' , re .ASCII )
465+ '\[.* ([\d.]+)\])' )
466+
467+ # Examples of VER command output:
468+ #
469+ # Windows 2000: Microsoft Windows 2000 [Version 5.00.2195]
470+ # Windows XP: Microsoft Windows XP [Version 5.1.2600]
471+ # Windows Vista: Microsoft Windows [Version 6.0.6002]
472+ #
473+ # Note that the "Version" string gets localized on different
474+ # Windows versions.
450475
451476def _syscmd_ver (system = '' , release = '' , version = '' ,
452477
@@ -578,6 +603,7 @@ def win32_ver(release='',version='',csd='',ptype=''):
578603 version = '%i.%i.%i' % (maj ,min ,buildno & 0xFFFF )
579604 if csd [:13 ] == 'Service Pack ' :
580605 csd = 'SP' + csd [13 :]
606+
581607 if plat == VER_PLATFORM_WIN32_WINDOWS :
582608 regkey = 'SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion'
583609 # Try to guess the release name
@@ -592,6 +618,7 @@ def win32_ver(release='',version='',csd='',ptype=''):
592618 release = 'postMe'
593619 elif maj == 5 :
594620 release = '2000'
621+
595622 elif plat == VER_PLATFORM_WIN32_NT :
596623 regkey = 'SOFTWARE\\ Microsoft\\ Windows NT\\ CurrentVersion'
597624 if maj <= 4 :
@@ -620,8 +647,12 @@ def win32_ver(release='',version='',csd='',ptype=''):
620647 release = 'Vista'
621648 else :
622649 release = '2008Server'
650+ #elif min == 1:
651+ # # Windows 7 release candidate uses version 6.1.7100
652+ # release = '7RC'
623653 else :
624654 release = 'post2008Server'
655+
625656 else :
626657 if not release :
627658 # E.g. Win3.1 with win32s
@@ -902,7 +933,7 @@ def _syscmd_uname(option,default=''):
902933 # XXX Others too ?
903934 return default
904935 try :
905- f = os .popen ('uname %s 2> /dev/null ' % option )
936+ f = os .popen ('uname %s 2> %s ' % ( option , DEV_NULL ) )
906937 except (AttributeError ,os .error ):
907938 return default
908939 output = f .read ().strip ()
@@ -927,7 +958,7 @@ def _syscmd_file(target,default=''):
927958 return default
928959 target = _follow_symlinks (target )
929960 try :
930- f = os .popen ('file "%s" 2> /dev/null ' % target )
961+ f = os .popen ('file "%s" 2> %s ' % ( target , DEV_NULL ) )
931962 except (AttributeError ,os .error ):
932963 return default
933964 output = f .read ().strip ()
0 commit comments