本文整理汇总了Python中os.environ.keys函数的典型用法代码示例。如果您正苦于以下问题:Python keys函数的具体用法?Python keys怎么用?Python keys使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了keys函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:amiorin,项目名称:blaz,代码行数:25,代码来源:blaz.py
示例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)
开发者ID:GVMike,项目名称:TiVoToGo.bundle,代码行数:26,代码来源:__init__.py
示例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
开发者ID:PisiLinuxRepos,项目名称:project,代码行数:28,代码来源:__init__.py
示例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)
开发者ID:csytracy,项目名称:nibabel,代码行数:8,代码来源:test_environment.py
示例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
开发者ID:me-manu,项目名称:batchfarm,代码行数:45,代码来源:lsf.py
示例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>'
开发者ID:asottile,项目名称:ancient-pythons,代码行数:9,代码来源:cgi.py
示例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)
开发者ID:Eric89GXL,项目名称:nibabel,代码行数:10,代码来源:test_environment.py
示例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']
开发者ID:cindeem,项目名称:nipy,代码行数:10,代码来源:test_data.py
示例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)
开发者ID:botchniaque,项目名称:blaz,代码行数:12,代码来源:blaz.py
示例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)
开发者ID:mfelsche,项目名称:blaz,代码行数:12,代码来源:blaz.py
示例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)
开发者ID:lbaehren,项目名称:lofarsoft,代码行数:13,代码来源:FRATScoinCtrOnline.py
示例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
开发者ID:magnusbraaten,项目名称:tassen,代码行数:51,代码来源:generate_postactivate.py
示例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
开发者ID:Shashikanth-Huawei,项目名称:bmp,代码行数:16,代码来源:onos.py
示例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()
开发者ID:ugorur,项目名称:vhost-project,代码行数:17,代码来源:vhost3.py
示例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'
开发者ID:taylan,项目名称:chord-search,代码行数:18,代码来源:config.py
示例16: __environ
def __environ(values, remove=[]):
"""
Modify the environment for a test, adding/updating values in dict `values` and
removing any environment variables mentioned in list `remove`.
"""
new_keys = set(environ.keys()) - set(values.keys())
old_environ = environ.copy()
try:
environ.update(values)
for to_remove in remove:
try:
del environ[remove]
except KeyError:
pass
yield
finally:
environ.update(old_environ)
for key in new_keys:
del environ[key]
开发者ID:BinglanLi,项目名称:galaxy,代码行数:19,代码来源:test_tool_deps.py
示例17: stderr
def stderr(exception, ctx=None):
try:
LOGGER.error(traceback.format_exc())
except Exception:
LOGGER.error(exception)
if type(exception) == UnauthorizedException:
message = 'Session has expired or is invalid, please login again.'
elif type(exception) == AccessForbiddenException:
message = 'Access to the resource is forbidden, please login ' \
'with the required credentials and access level.'
elif type(exception) == RequestTimeoutException:
message = 'The server timed out waiting for the request, ' \
'please check your connection.'
elif hasattr(exception, 'message'):
message = exception.message
else:
message = str(exception)
if ctx is not None and ctx.find_root().params['json_output']:
message = {'error': str(message)}
text = json.dumps(
message, sort_keys=True, indent=4, separators=(',', ': '))
if sys.version_info[0] < 3:
text = str(text, 'utf-8')
if ctx.find_root().params['is_colorized']:
message = highlight(text, lexers.JsonLexer(),
formatters.TerminalFormatter())
else:
message = text
click.echo(message)
sys.exit(1)
else:
click.echo('\x1b[2K\r', nl=False)
if ctx is not None:
if ctx.find_root().params['is_colorized']:
message = Fore.RED + str(message)
ctx.fail(message)
else:
if 'VCD_USE_COLORED_OUTPUT' in environ.keys() and \
environ['VCD_USE_COLORED_OUTPUT'] != '0':
message = Fore.RED + str(message)
click.echo(message)
sys.exit(1)
开发者ID:vmware,项目名称:vca-cli,代码行数:42,代码来源:utils.py
示例18: load_environment
def load_environment(env_path=None, silent=True):
# load the environment path (if it exists)
if env_path is None:
env_path = expanduser("~/.env")
if not exists(env_path) and 'NOTEBOOK_HOME' in environ.keys():
env_path = join(os.environ['NOTEBOOK_HOME'], '.env')
if not exists(env_path):
return
with open(env_path, 'r') as f:
lines = f.readlines()
print('Adding the following system variables:')
for line in lines:
k, v = line.strip().split('=')
environ[k] = v
print(' %s = %s' % (k, v))
print('\nThese can be accessed using the following command: ')
print(' os.environ[key]')
print('\n (e.g.)\n os.environ["HS_USR_NAME"] => %s' % environ['HS_USR_NAME'])
开发者ID:hydroshare,项目名称:hydroshare-jupyterhub,代码行数:20,代码来源:jupyter.py
示例19: load_environment
def load_environment(env_path=None, silent=True):
# load the environment path (if it exists)
if env_path is None:
if 'NOTEBOOK_HOME' in environ.keys():
env_path = join(environ['NOTEBOOK_HOME'], '.env')
if not exists(env_path):
print('\nEnvironment file could not be found. Make sure that the JUPYTER_ENV variable is set properly')
return
with open(env_path, 'r') as f:
lines = f.readlines()
print('Adding the following system variables:')
for line in lines:
k, v = line.strip().split('=')
environ[k] = v
print(' %s = %s' % (k, v))
print('\nThese can be accessed using the following command: ')
print(' os.environ[key]')
print('\n (e.g.)\n os.environ["HS_USR_NAME"] => %s' % environ['HS_USR_NAME'])
开发者ID:hydroshare,项目名称:hydroshare-jupyterhub,代码行数:21,代码来源:jupyter.py
示例20: __init__
def __init__(self, layerpath, dico_layer, dico_fields, tipo, text=''):
u""" Uses gdal/ogr functions to extract basic informations about
geographic file (handles shapefile or MapInfo tables)
and store into the dictionaries.
layerpath = path to the geographic file
dico_layer = dictionary for global informations
dico_fields = dictionary for the fields' informations
tipo = shp or tab
text = dictionary of text in the selected language
"""
# checking the path to GDAL in the path
if "GDAL_DATA" not in env.keys():
try:
gdal.SetConfigOption(str('GDAL_DATA'), str(path.abspath(r'data/gdal')))
except:
pass
else:
pass
# Creating variables
self.alert = 0
source = ogr.Open(layerpath, 0) # OGR driver
if not source:
u""" if layer doesn't have any object, return an error """
## print 'no compatible source'
self.erratum(dico_layer, layerpath, u'err_nobjet')
self.alert = self.alert +1
self.layer = source.GetLayer() # get the layer
if self.layer.GetFeatureCount() == 0:
u""" if layer doesn't have any object, return an error """
self.erratum(dico_layer, layerpath, u'err_nobjet')
self.alert = self.alert +1
return None
if tipo == 'shape':
try:
obj = self.layer.GetFeature(0) # get the first object (shp)
self.geom = obj.GetGeometryRef() # get the geometry
except AttributeError, e:
pass
开发者ID:Guts,项目名称:Metadator,代码行数:40,代码来源:InfosOGR.py
注:本文中的os.environ.keys函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论