本文整理汇总了Python中os.environ.keys函数的典型用法代码示例。如果您正苦于以下问题:Python keys函数的具体用法?Python keys怎么用?Python keys使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了keys函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _forward_blaz_env_vars
def _forward_blaz_env_vars(self):
self._find_uid_and_guid()
result = []
for k in environ.keys():
if k.find('BLAZ_') == 0 and k != 'BLAZ_LOCK' and k != 'BLAZ_VERSION' and k != 'BLAZ_CHDIR_REL' and k != 'BLAZ_SKIP':
result.append('''
--env={}="{}"
'''.format(k, environ[k]))
if k.find('BLAZ_VARS') == 0:
env_vars = re.split('\W+', environ[k])
for j in env_vars:
result.append('''
--env={}="{}"
'''.format(j, environ[j]))
elif k.find('_BLAZ_') == 0:
result.append('''
--env={0}="${0}"
'''.format(k))
if k.find('_BLAZ_VARS') == 0:
env_vars = re.split('\W+', environ[k])
for j in env_vars:
result.append('''
--env={0}="${0}"
'''.format(j))
return ''.join(result)
示例2: do_GET
def do_GET(self):
try:
url = base64.b64decode(string.split(self.path[1:], "/")[0], "-_")
Log("GET URL: %s" % url)
if sys.platform != "win32":
self.send_response(200)
self.send_header('Content-type', 'video/mpeg2')
self.end_headers()
tvd = getTvd()
curl = getCurl()
Log.Debug("TVD: %s" % tvd)
Log.Debug("CMD: %s %s %s %s %s %s %s %s" % (curl, url, "--digest", "-s", "-u", "tivo:"+getMyMAC(), "-c", "/tmp/cookies.txt"))
Log.Debug(" PIPED to: %s %s %s %s" % (tvd, "-m", getMyMAC(), "-"))
if "LD_LIBRARY_PATH" in environ.keys():
del environ["LD_LIBRARY_PATH"]
curlp = Popen([curl, url, "--digest", "-s", "-u", "tivo:"+getMyMAC(), "-c", "/tmp/cookies.txt"], stdout=PIPE)
tivodecode = Popen([tvd, "-m", getMyMAC(), "-"],stdin=curlp.stdout, stdout=PIPE)
Log("Starting decoder")
while True:
data = tivodecode.stdout.read(4192)
if not data:
break
self.wfile.write(data)
except Exception, e:
Log("Unexpected error: %s" % e)
示例3: session
def session(self):
if not self._session:
env = getenv('DESKTOP_SESSION')
if not env:
for var in list(environ.keys()):
v = var.split('_')
if len(v) < 2: continue
elif v[1] == 'DESKTOP':
env = v[0].lower()
break
elif env == 'default' or env == 'gnome':
session = readfile('/etc/default/desktop', DefaultDe.Name)
env = session.split('=')[1].strip()
for de in Pds.SupportedDesktops:
if env:
if env in de.SessionTypes or env.lower() == de.Name.lower():
self._session = de
else:
if de.VersionKey:
if getenv(de.VersionKey) == de.Version:
self._session = de
if not self._session:
self._session = DefaultDe
else:
for de in Pds.SupportedDesktops:
if de.Version == self.version and (env in de.SessionTypes or env == de.Name):
self._session = de
return self._session
示例4: teardown_environment
def teardown_environment():
"""Restore things that were remembered by the setup_environment function
"""
orig_env = GIVEN_ENV['env']
for key in env.keys():
if key not in orig_env:
del env[key]
env.update(orig_env)
示例5: init_lsf
def init_lsf(local_id = 0):
"""
Init lsf cluster jobs: set up tmpdir on cluster scratch, determine job_id and set pfiles to tmpdir on scratch
kwargs
------
local_id: int, if not on lsf, return this value as job_id
Returns
-------
tuple with tmpdir on cluster scratch and lsf job id
"""
try:
environ.keys().index("LSB_JOBNAME")
job_id = int(environ["LSB_JOBINDEX"])
tmpdir = mkdir(join('/scratch/{0:s}.{1:s}/'.format(environ['USER'],environ["LSB_JOBID"])))
logging.info('os.listdir: {0}'.format(listdir(tmpdir)))
sleep(20.)
tmpdir = join(tmpdir,'{0:s}.XXXXXX'.format(environ["LSB_JOBID"]))
p = Popen(["mktemp", "-d", tmpdir], stdout=PIPE) # make a temporary directory and get its name
sleep(20.)
out, err = p.communicate()
logging.info('out: {0}'.format(out))
logging.info('err: {0}'.format(err))
tmpdir = join('/scratch',out.split()[0])
sleep(20.)
except ValueError:
job_id = local_id
#tmpdir = environ["PWD"]
tmpdir = mkdir(join(environ["PWD"],'tmp/'))
#system('export PFILES={0:s}:$PFILES'.format(tmpdir))
#sleep(10.)
logging.info('tmpdir is {0:s}.'.format(tmpdir))
if not exists(tmpdir):
logging.error('Tmpdir does not exist: {0}. Exit 14'.format(tmpdir))
sys.exit(14)
return tmpdir,job_id
示例6: print_environ
def print_environ():
skeys = environ.keys()
skeys.sort()
print '<h3> The following environment variables ' \
'were set by the CGI script: </h3>'
print '<dl>'
for key in skeys:
print '<dt>', escape(key), '<dd>', escape(environ[key])
print '</dl>'
示例7: teardown_environment
def teardown_environment():
"""Restore things that were remembered by the setup_environment function
"""
orig_env = GIVEN_ENV['env']
# Pull keys out into list to avoid altering dictionary during iteration,
# causing python 3 error
for key in list(env.keys()):
if key not in orig_env:
del env[key]
env.update(orig_env)
示例8: teardown_environment
def teardown_environment():
"""Restore things that were remebered by the setup_environment function
"""
orig_env = GIVEN_ENV['env']
for key in env.keys():
if key not in orig_env:
del env[key]
env.update(orig_env)
nud.get_nipy_system_dir = GIVEN_ENV['sys_dir_func']
nud.get_data_path = GIVEN_ENV['path_func']
示例9: _forward_blaz_env_vars
def _forward_blaz_env_vars(self):
result = []
for k in environ.keys():
if k.find('BLAZ_') == 0 and k != 'BLAZ_LOCK' and k != 'BLAZ_VERSION' and k != 'BLAZ_CHDIR' and k != 'BLAZ_SKIP':
result.append('''
--env={}={}
'''.format(k, environ[k]))
elif k.find('_BLAZ_') == 0:
result.append('''
--env={0}=${0}
'''.format(k))
return ''.join(result)
示例10: _forward_blaz_env_vars
def _forward_blaz_env_vars(self):
result = []
for k in environ.keys():
if k.find('BLAZ_') == 0:
result.append('''
--env={}={}
'''.format(k, environ[k]))
elif k.find('_BLAZ_') == 0:
result.append('''
--env={0}=${0}
'''.format(k))
return ''.join(result)
示例11: get_pointing
def get_pointing(obsID,beam):
from os import environ
if 'parsetdir' in environ.keys():
parsetdir=os.environ['parsetdir']
else:
parsetdir='/Users/STV/Astro/Analysis/FRAT/parsets/'
if type(obsID)==type(1):
p=bf.get_parameters_new('parsets/L'+str(obsID)+'.parset',True)
else:
p=bf.get_parameters_new('parsets/'+obsID+'.parset',True)
RA=p['beam'][beam]['RA']
DEC=p['beam'][beam]['DEC']
return (RA,DEC)
示例12: make_postactivate_text
def make_postactivate_text(site_url):
"""
Generate the text of a shell script to run on virtualenv activation.
Returns the contents as a tuple containing a string and a dictionary.
"""
settings = {}
for key in environ.keys():
if key.startswith(PREFIX):
new_item = {
key.replace(
PREFIX,
'',
1).lower().replace(
'_',
' '): environ.get(key)}
settings.update(new_item)
settings.update({
'source folder': '{root}/{url}/source'.format(root=WEBSERVER_ROOT, url=site_url, ),
'site url': site_url,
'settings module': '{module}.{version}'.format(
module=SETTINGS_MODULE, version=site_url.split('.')[0],
),
'secret key': _make_random_sequence(50),
'db password': _make_random_sequence(50),
'db user': site_url.replace('.', '_'),
'db name': site_url.replace('.', '_'),
'user': site_url.replace('.', '_'),
'debug toolbar internal ips': _find_my_ip_address(),
})
if site_url in OVERRIDES:
settings.update(OVERRIDES[site_url])
postactivate = (
'#!/bin/bash\n'
'# This hook is run after the virtualenv is activated.\n\n'
'# Environmental variables for django projects.\n\n'
)
for key in sorted(settings):
postactivate += 'export {prefix}{key}="{value}"\n'.format(
prefix=PREFIX,
key=key.replace(' ', '_').upper(),
value=settings[key],
)
postactivate += ('\n'
'export PYTHONPATH="$DJANGO_SOURCE_FOLDER:$PYTHONPATH"\n'
'export PATH="$(dirname $DJANGO_SOURCE_FOLDER)/node_modules/.bin:$PATH"\n'
'export PYTHONWARNINGS=ignore\n'
'cd $DJANGO_SOURCE_FOLDER\n')
return postactivate, settings
示例13: updateNodeIPs
def updateNodeIPs( env, nodes ):
"Update env dict and environ with node IPs"
# Get rid of stale junk
for var in 'ONOS_NIC', 'ONOS_CELL', 'ONOS_INSTANCES':
env[ var ] = ''
for var in environ.keys():
if var.startswith( 'OC' ):
env[ var ] = ''
for index, node in enumerate( nodes, 1 ):
var = 'OC%d' % index
env[ var ] = node.IP()
env[ 'OCI' ] = env[ 'OCN' ] = env[ 'OC1' ]
env[ 'ONOS_INSTANCES' ] = '\n'.join(
node.IP() for node in nodes )
environ.update( env )
return env
示例14: _kontrol
def _kontrol(self):
if 'SUDO_UID' in environ.keys():
if len(argv) == 2:
if argv[1] == 'yenile':
self._yenile()
if argv[1] == 'kur':
self._kur()
elif argv[1] == '--versiyon' or argv[1] == '-v':
print VERSIYON
exit()
if len(argv) < 3:
print '\033[1m\033[91mHATA:\033[0m Lüften programı bir komut ile çalıştırın: "sudo vhost3 <platform> <islem>"'
exit()
else:
print '\033[1m\033[91mHATA:\033[0m Yönetici girişi yapmak gerek. Lüften programı "sudo vhost3 <platform> <islem>" komutu ile çalıştırın'
exit()
示例15: initialize_config
def initialize_config(config_file_name='env.yaml'):
config_keys = ['DBSERVER', 'DBNAME', 'DBUSER', 'DBPASS', 'DBPORT', 'REDISHOST', 'REDISPORT', 'REDISPASS']
if contains(config_keys, list(environ.keys())):
environ['DEBUG'] = 'False'
return
config_file_path = path.join(path.dirname(path.abspath(__file__)), config_file_name)
if not path.exists(config_file_path):
raise Exception('env.yaml required for config initialization')
with open(config_file_path, 'r') as config_file:
config = yaml.load(config_file)
config['dbconfig']['DBPORT'] = str(config['dbconfig']['DBPORT'])
config['redisconfig']['REDISPORT'] = str(config['redisconfig']['REDISPORT'])
environ.update(config['dbconfig'])
environ.update(config['redisconfig'])
environ['DEBUG'] = 'True'