def _define_version(self):
architecture = self._get_architecture()
if self.options.version == 'current':
self.release = 'debian'
self.SUITES = [
'wazo-dev/main/binary-%s/Packages' % architecture,
]
elif self.options.version == 'rc':
self.release = 'debian'
self.SUITES = [
'wazo-rc/main/binary-%s/Packages' % architecture,
]
else:
self.release = 'archive'
if self.options.version < '13.25':
distribution = 'squeeze-xivo-skaro-%s' % self.options.version
elif self.options.version < '16.16':
distribution = 'xivo-%s' % self.options.version
else:
distribution = 'wazo-%s' % self.options.version
self.SUITES = [
'%s/main/binary-%s/Packages' % (distribution, architecture),
]
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)
printer(USER_AGENT, debug=True)
return USER_AGENT
def get_items(self):
upMinionCount = Host.objects.filter(minion_status=1).count()
downMinionCount = Host.objects.filter(minion_status=0).count()
# ??????
item_info = Item(
html_id='SysInfo', name='??????',
display=Item.AS_TABLE,
value=(
('??', '%s, %s, %s' % (
platform.system(),
' '.join(platform.linux_distribution()),
platform.release())),
('??', ' '.join(platform.architecture())),
('???', platform.processor()),
('Python??', platform.python_version()),
('??????', Host.objects.count()),
('????', Project.objects.count()),
('???????', '??? %s,??? %s' % (upMinionCount, downMinionCount)),
),
classes='table-bordered table-condensed '
'table-hover table-striped'
)
return [item_info]
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 render(self):
view = View('none')
box = BoxElement(title='widget.info.header', icon='server', padding=False)
table = TableElement(
content=[
('widget.info.os', '%s %s (%s)' % (platform.system(), platform.release(), platform.architecture()[0])),
('widget.info.hostname', platform.node()),
('widget.info.ipaddress', prism.settings.PRISM_CONFIG['host']),
('widget.info.uptime', self.get_uptime())
]
)
box.add(table)
view.add(box)
return view
def TestPlatform():
print ("----------Operation System--------------------------")
# Windows will be : (32bit, WindowsPE)
# Linux will be : (32bit, ELF)
print(platform.architecture())
# Windows will be : Windows-XP-5.1.2600-SP3 or Windows-post2008Server-6.1.7600
# Linux will be : Linux-2.6.18-128.el5-i686-with-redhat-5.3-Final
print(platform.platform())
# Windows will be : Windows
# Linux will be : Linux
print(platform.system())
print ("--------------Python Version-------------------------")
# Windows and Linux will be : 3.1.1 or 3.1.3
print(platform.python_version())
def test_architecture_via_symlink(self): # issue3762
# On Windows, the EXE needs to know where pythonXY.dll is at so we have
# to add the directory to the path.
if sys.platform == "win32":
os.environ["Path"] = "{};{}".format(
os.path.dirname(sys.executable), os.environ["Path"])
def get(python):
cmd = [python, '-c',
'import platform; print(platform.architecture())']
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
return p.communicate()
real = os.path.realpath(sys.executable)
link = os.path.abspath(support.TESTFN)
os.symlink(real, link)
try:
self.assertEqual(get(real), get(link))
finally:
os.remove(link)
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
def import_module_list(modules_list):
# platform data
is_64bit = platform.architecture()[0] == '64bit'
is_python3 = (sys.version_info >= (3, 0))
is_cel = os.path.exists('/etc/system-profile')
# regular modules
for p in modules_list:
full_path = generate_module_path(p, is_python3, is_64bit, is_cel)
if not os.path.exists(full_path):
print("Unable to find required module library: '{0}'".format(p['name']))
print("Please provide the correct path using TREX_STL_EXT_PATH variable")
print("current path used: '{0}'".format(full_path))
exit(0)
sys.path.insert(1, full_path)
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 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 architecture():
"""
Returns the bit depth of the python interpreter's architecture as
a string ('32bit' or '64bit'). Similar to platform.architecture(),
but with fixes for universal binaries on MacOS.
"""
if is_darwin:
# Darwin's platform.architecture() is buggy and always
# returns "64bit" event for the 32bit version of Python's
# universal binary. So we roll out our own (that works
# on Darwin).
if sys.maxsize > 2 ** 32:
return '64bit'
else:
return '32bit'
else:
return platform.architecture()[0]
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 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 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_architecture_via_symlink(self): # issue3762
# On Windows, the EXE needs to know where pythonXY.dll is at so we have
# to add the directory to the path.
if sys.platform == "win32":
os.environ["Path"] = "{};{}".format(
os.path.dirname(sys.executable), os.environ["Path"])
def get(python):
cmd = [python, '-c',
'import platform; print(platform.architecture())']
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
return p.communicate()
real = os.path.realpath(sys.executable)
link = os.path.abspath(support.TESTFN)
os.symlink(real, link)
try:
self.assertEqual(get(real), get(link))
finally:
os.remove(link)
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
def collect():
data = {
'os_type': platform.system(),
'os_release':"%s %s %s "%( platform.release() ,platform.architecture()[0],platform.version()),
'os_distribution': 'Microsoft',
'asset_type':'server'
}
#data.update(cpuinfo())
win32obj = Win32Info()
data.update(win32obj.get_cpu_info())
data.update(win32obj.get_ram_info())
data.update(win32obj.get_server_info())
data.update(win32obj.get_disk_info())
data.update(win32obj.get_nic_info())
#for k,v in data.items():
# print k,v
return data
def dir_from_output(output):
"""Get library directory based on the output of clang.
Args:
output (str): raw output from clang
Returns:
str: path to folder with libclang
"""
log.debug("real output: %s", output)
if platform.system() == "Darwin":
# [HACK] uh... I'm not sure why it happens like this...
folder_to_search = path.join(output, '..', '..')
log.debug("folder to search: %s", folder_to_search)
return folder_to_search
elif platform.system() == "Windows":
log.debug("architecture: %s", platform.architecture())
return path.normpath(output)
elif platform.system() == "Linux":
return path.normpath(path.dirname(output))
return None
gnu.py 文件源码
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda
作者: SignalMedia
项目源码
文件源码
阅读 36
收藏 0
点赞 0
评论 0
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 binaries_urls(platform_name, arch):
"""Return tuple of binaries name and URL, based on given sys informations.
If detected system is not supported, an empty iterable is returned.
Architecture and platforms supported depends of distant binary repository.
"""
try:
subpath = BASE_URL_PLATFORM_SPECIFIC_SUBPATHS[platform_name, arch]
except KeyError:
logging.getLogger().error(
'clasp/gringo3/gringo4 binaries are not available for'
' platform ' + platform_name + ' under architecture '
+ arch + 'bits.')
return tuple() # empty iterable
# no error: build the tuple of binaries paths
return tuple((local_name, BINARIES_BASE_URL.format(subpath, remote_name))
for remote_name, local_name in BINARIES_NAME.items())
def os():
import platform
pm = platform.machine()
if pm != '..' and pm.endswith('64'): # recent Python (not Iron)
return True
else:
import os
if 'PROCESSOR_ARCHITEW6432' in os.environ:
return True # 32 bit program running on 64 bit Windows
try:
return os.environ['PROCESSOR_ARCHITECTURE'].endswith('64') # 64 bit Windows 64 bit program
except IndexError:
pass # not Windows
try:
return '64' in platform.architecture()[0] # this often works in Linux
except:
return False # is an older version of Python, assume also an older os (best we can guess)
def os():
import platform
pm = platform.machine()
if pm != '..' and pm.endswith('64'): # recent Python (not Iron)
return True
else:
import os
if 'PROCESSOR_ARCHITEW6432' in os.environ:
return True # 32 bit program running on 64 bit Windows
try:
return os.environ['PROCESSOR_ARCHITECTURE'].endswith('64') # 64 bit Windows 64 bit program
except IndexError:
pass # not Windows
try:
return '64' in platform.architecture()[0] # this often works in Linux
except:
return False # is an older version of Python, assume also an older os (best we can guess)
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 os():
import platform
pm = platform.machine()
if pm != '..' and pm.endswith('64'): # recent Python (not Iron)
return True
else:
import os
if 'PROCESSOR_ARCHITEW6432' in os.environ:
return True # 32 bit program running on 64 bit Windows
try:
return os.environ['PROCESSOR_ARCHITECTURE'].endswith('64') # 64 bit Windows 64 bit program
except IndexError:
pass # not Windows
try:
return '64' in platform.architecture()[0] # this often works in Linux
except:
return False # is an older version of Python, assume also an older os (best we can guess)
def os():
import platform
pm = platform.machine()
if pm != '..' and pm.endswith('64'): # recent Python (not Iron)
return True
else:
import os
if 'PROCESSOR_ARCHITEW6432' in os.environ:
return True # 32 bit program running on 64 bit Windows
try:
return os.environ['PROCESSOR_ARCHITECTURE'].endswith('64') # 64 bit Windows 64 bit program
except IndexError:
pass # not Windows
try:
return '64' in platform.architecture()[0] # this often works in Linux
except:
return False # is an older version of Python, assume also an older os (best we can guess)
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 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 copyBaseFiles(path):
print (text.copyingFiles)
# Supports 64 bit and 32 bit, no arm yet (though should be an easy fix)
if platform.architecture()[0] == "64bit":
arch = "amd64"
else:
arch = "i386"
version = getFlag.getFlag("-v")
architecture = getFlag.getFlag("-a")
repo = getFlag.getFlag("-r")
if version not in content.versions:
version = "xenial"
if architecture and architecture in content.architectures:
arch = content.architectures.get(architecture)
print (text.usingVersion.format(version))
debCmd = "bash " + getRootDir.getCofferDir() + "debootstrap/debootstrap --arch=" + arch + " {} {}"
if repo:
debCmd += " " + repo
os.system(debCmd.format(version, path))
getSourceList(path, version)
def test_architecture_via_symlink(self): # issue3762
# On Windows, the EXE needs to know where pythonXY.dll is at so we have
# to add the directory to the path.
if sys.platform == "win32":
os.environ["Path"] = "{};{}".format(
os.path.dirname(sys.executable), os.environ["Path"])
def get(python):
cmd = [python, '-c',
'import platform; print(platform.architecture())']
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
return p.communicate()
real = os.path.realpath(sys.executable)
link = os.path.abspath(support.TESTFN)
os.symlink(real, link)
try:
self.assertEqual(get(real), get(link))
finally:
os.remove(link)