本文整理汇总了Python中sys.platform方法的典型用法代码示例。如果您正苦于以下问题:Python sys.platform方法的具体用法?Python sys.platform怎么用?Python sys.platform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sys
的用法示例。
在下文中一共展示了sys.platform方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import sys [as 别名]
# 或者: from sys import platform [as 别名]
def __init__(self, bus):
self.bus = bus
# Set default handlers
self.handlers = {'SIGTERM': self.bus.exit,
'SIGHUP': self.handle_SIGHUP,
'SIGUSR1': self.bus.graceful,
}
if sys.platform[:4] == 'java':
del self.handlers['SIGUSR1']
self.handlers['SIGUSR2'] = self.bus.graceful
self.bus.log('SIGUSR1 cannot be set on the JVM platform. '
'Using SIGUSR2 instead.')
self.handlers['SIGINT'] = self._jython_SIGINT_handler
self._previous_handlers = {}
# used to determine is the process is a daemon in `self._is_daemonized`
self._original_pid = os.getpid()
示例2: wr
# 需要导入模块: import sys [as 别名]
# 或者: from sys import platform [as 别名]
def wr( self, str ):
if ( self.debug ):
print("FT600_WR:" + str );
str = "~".join( str );# only using 8bits of 16bit FT600, so pad with ~
bytes_to_write = len( str );# str is now "~1~2~3 .. ~e~f" - Twice as long
channel = 0;
result = False;
timeout = 5;
tx_pipe = 0x02 + channel;
if sys.platform == 'linux2':
tx_pipe -= 0x02;
if ( sys.version_info.major == 3 ):
str = str.encode('latin1');
xferd = 0
while ( xferd != bytes_to_write ):
# write data to specified pipe
xferd += self.D3XX.writePipe(tx_pipe,str,bytes_to_write-xferd);
return;
示例3: parse_arguments
# 需要导入模块: import sys [as 别名]
# 或者: from sys import platform [as 别名]
def parse_arguments():
"""Parse the arguments"""
parser = argparse.ArgumentParser()
parser.add_argument("--setup", "-s", action="store_true")
parser.add_argument("--phone", "-p", action="append")
parser.add_argument("--token", "-t", action="append", dest="tokens")
parser.add_argument("--heroku", action="store_true")
parser.add_argument("--local-db", dest="local", action="store_true")
parser.add_argument("--web-only", dest="web_only", action="store_true")
parser.add_argument("--no-web", dest="web", action="store_false")
parser.add_argument("--heroku-web-internal", dest="heroku_web_internal", action="store_true",
help="This is for internal use only. If you use it, things will go wrong.")
arguments = parser.parse_args()
logging.debug(arguments)
if sys.platform == "win32":
# Subprocess support; not needed in 3.8 but not harmful
asyncio.set_event_loop(asyncio.ProactorEventLoop())
return arguments
示例4: ale_load_from_rom
# 需要导入模块: import sys [as 别名]
# 或者: from sys import platform [as 别名]
def ale_load_from_rom(rom_path, display_screen):
rng = get_numpy_rng()
try:
from ale_python_interface import ALEInterface
except ImportError as e:
raise ImportError('Unable to import the python package of Arcade Learning Environment. ' \
'ALE may not have been installed correctly. Refer to ' \
'`https://github.com/mgbellemare/Arcade-Learning-Environment` for some' \
'installation guidance')
ale = ALEInterface()
ale.setInt(b'random_seed', rng.randint(1000))
if display_screen:
import sys
if sys.platform == 'darwin':
import pygame
pygame.init()
ale.setBool(b'sound', False) # Sound doesn't work on OSX
ale.setBool(b'display_screen', True)
else:
ale.setBool(b'display_screen', False)
ale.setFloat(b'repeat_action_probability', 0)
ale.loadROM(str.encode(rom_path))
return ale
示例5: train
# 需要导入模块: import sys [as 别名]
# 或者: from sys import platform [as 别名]
def train(env_id, num_timesteps, seed, policy):
ncpu = multiprocessing.cpu_count()
if sys.platform == 'darwin': ncpu //= 2
config = tf.ConfigProto(allow_soft_placement=True,
intra_op_parallelism_threads=ncpu,
inter_op_parallelism_threads=ncpu)
config.gpu_options.allow_growth = True #pylint: disable=E1101
tf.Session(config=config).__enter__()
env = VecFrameStack(make_atari_env(env_id, 8, seed), 4)
policy = {'cnn' : CnnPolicy, 'lstm' : LstmPolicy, 'lnlstm' : LnLstmPolicy}[policy]
ppo2.learn(policy=policy, env=env, nsteps=128, nminibatches=4,
lam=0.95, gamma=0.99, noptepochs=4, log_interval=1,
ent_coef=.01,
lr=lambda f : f * 2.5e-4,
cliprange=lambda f : f * 0.1,
total_timesteps=int(num_timesteps * 1.1))
示例6: find_media_viewer
# 需要导入模块: import sys [as 别名]
# 或者: from sys import platform [as 别名]
def find_media_viewer():
global VWR
VWR_LIST = [
"feh",
"gio",
"sxiv",
"gnome-open",
"gvfs-open",
"xdg-open",
"kde-open",
"firefox"
]
if sys.platform == "win32":
VWR = ["start"]
elif sys.platform == "darwin":
VWR = ["open"]
else:
for i in VWR_LIST:
if shutil.which(i) is not None:
VWR = [i]
break
if VWR[0] in {"gio"}:
VWR.append("open")
示例7: finalize_env
# 需要导入模块: import sys [as 别名]
# 或者: from sys import platform [as 别名]
def finalize_env(env):
"""
Produce a platform specific env for passing into subprocess.Popen
family of external process calling methods, and the supplied env
will be updated on top of it. Returns a new env.
"""
keys = _PLATFORM_ENV_KEYS.get(sys.platform, [])
if 'PATH' not in keys:
# this MUST be available due to Node.js (and others really)
# needing something to look for binary locations when it shells
# out to other binaries.
keys.append('PATH')
results = {
key: os.environ.get(key, '') for key in keys
}
results.update(env)
return results
示例8: test_found_win32
# 需要导入模块: import sys [as 别名]
# 或者: from sys import platform [as 别名]
def test_found_win32(self):
sys.platform = 'win32'
tempdir = os.environ['PATH'] = mkdtemp(self)
os.environ['PATHEXT'] = pathsep.join(('.com', '.exe', '.bat'))
f = join(tempdir, 'binary.exe')
with open(f, 'w'):
pass
os.chmod(f, 0o777)
self.assertEqual(which('binary'), f)
self.assertEqual(which('binary.exe'), f)
self.assertEqual(which(f), f)
self.assertIsNone(which('binary.com'))
os.environ['PATH'] = ''
self.assertEqual(which('binary', path=tempdir), f)
self.assertEqual(which('binary.exe', path=tempdir), f)
self.assertEqual(which(f, path=tempdir), f)
self.assertIsNone(which('binary.com', path=tempdir))
示例9: test_finalize_env_win32
# 需要导入模块: import sys [as 别名]
# 或者: from sys import platform [as 别名]
def test_finalize_env_win32(self):
sys.platform = 'win32'
# when os.environ is empty or missing the required keys, the
# values will be empty strings.
os.environ = {}
self.assertEqual(finalize_env({}), {
'APPDATA': '', 'PATH': '', 'PATHEXT': '', 'SYSTEMROOT': ''})
# should be identical with the keys copied
os.environ['APPDATA'] = 'C:\\Users\\Guest\\AppData\\Roaming'
os.environ['PATH'] = 'C:\\Windows'
os.environ['PATHEXT'] = pathsep.join(('.com', '.exe', '.bat'))
os.environ['SYSTEMROOT'] = 'C:\\Windows'
self.assertEqual(finalize_env({}), os.environ)
# This test is done with conjunction with finalize_env to mimic how
# this is typically used within the rest of the library.
示例10: rmtree
# 需要导入模块: import sys [as 别名]
# 或者: from sys import platform [as 别名]
def rmtree(path):
try:
rmtree_(path)
except (IOError, OSError):
# As it turns out nested node_modules directories are a bad
# idea, especially on Windows. It turns out this situation
# is rather common, so we need a way to deal with this. As
# it turns out a workaround exists around this legacy win32
# issue through this proprietary prefix:
path_ = '\\\\?\\' + path if sys.platform == 'win32' else path
# and try again
try:
rmtree_(path_)
except (IOError, OSError):
pass
# Don't blow the remaining teardown up if it fails anyway.
if exists(path):
warnings.warn("rmtree failed to remove %r" % path)
示例11: hide_cursor
# 需要导入模块: import sys [as 别名]
# 或者: from sys import platform [as 别名]
def hide_cursor():
"""
Turns the cursor off in the terminal.
"""
global is_conemu
if not sys.platform == 'win32':
sys.stdout.write('\033[?25l')
is_conemu = False
else:
ci = ConsoleCursorInfo()
handle = ctypes.windll.kernel32.GetStdHandle(-11)
ctypes.windll.kernel32.GetConsoleCursorInfo(handle, ctypes.byref(ci))
ci.visible = False
ctypes.windll.kernel32.SetConsoleCursorInfo(handle, ctypes.byref(ci))
is_conemu = os.environ.get('ConEmuANSI') == 'ON'
# some characters are forbidden in NTFS, but are not in ext4. the most popular of these characters
# seems to be the colon character. LXSS solves this issue by escaping the character on NTFS.
# while this seems like a dumb implementation, it will be called a lot of times inside the
# decompression loop, so it has to be fast: http://stackoverflow.com/a/27086669/156626
示例12: build_extensions
# 需要导入模块: import sys [as 别名]
# 或者: from sys import platform [as 别名]
def build_extensions(self):
compiler = self.compiler.compiler_type
if compiler == 'msvc': # visual studio
for e in self.extensions:
e.extra_compile_args += ['/O2', '/openmp']
else:
for e in self.extensions:
e.extra_compile_args += ['-O3', '-march=native', '-fopenmp']
e.extra_link_args += ['-fopenmp']
if e.language == "c++":
e.extra_compile_args += ['-std=c++11']
### Remove this code if you have a mac with gcc or clang + openmp
if platform[:3] == "dar":
for e in self.extensions:
e.extra_compile_args = [arg for arg in e.extra_compile_args if arg != '-fopenmp']
e.extra_link_args = [arg for arg in e.extra_link_args if arg != '-fopenmp']
build_ext.build_extensions(self)
示例13: cd_sys_type
# 需要导入模块: import sys [as 别名]
# 或者: from sys import platform [as 别名]
def cd_sys_type():
"""
:return: 平台类型 0 win, 1 mac 2 Linux 3 其他
"""
"""
a = sys.platform
if a == 'win32' or a == 'win64':
return 0
elif a == 'darwin':
return 1
else:
return 2
"""
a = platform.system()
if a == 'Windows':
return 0
elif a == 'Darwin':
return 1
elif a == 'Linux':
return 2
else:
return 3
示例14: test_dsa_2048_sha1_sign
# 需要导入模块: import sys [as 别名]
# 或者: from sys import platform [as 别名]
def test_dsa_2048_sha1_sign(self):
def do_run():
original_data = b'This is data to sign'
private = asymmetric.load_private_key(os.path.join(fixtures_dir, 'keys/test-dsa-2048.key'))
public = asymmetric.load_public_key(os.path.join(fixtures_dir, 'keys/test-dsa-2048.crt'))
signature = asymmetric.dsa_sign(private, original_data, 'sha1')
self.assertIsInstance(signature, byte_cls)
asymmetric.dsa_verify(public, signature, original_data, 'sha1')
if sys.platform == 'win32':
with self.assertRaises(errors.AsymmetricKeyError):
do_run()
else:
do_run()
示例15: makelink
# 需要导入模块: import sys [as 别名]
# 或者: from sys import platform [as 别名]
def makelink(self, tarinfo, targetpath):
"""Make a (symbolic) link called targetpath. If it cannot be created
(platform limitation), we try to make a copy of the referenced file
instead of a link.
"""
try:
# For systems that support symbolic and hard links.
if tarinfo.issym():
os.symlink(tarinfo.linkname, targetpath)
else:
# See extract().
if os.path.exists(tarinfo._link_target):
os.link(tarinfo._link_target, targetpath)
else:
self._extract_member(self._find_link_target(tarinfo),
targetpath)
except symlink_exception:
try:
self._extract_member(self._find_link_target(tarinfo),
targetpath)
except KeyError:
raise ExtractError("unable to resolve link inside archive")