本文整理汇总了Python中six.moves.configparser.RawConfigParser.has_option方法的典型用法代码示例。如果您正苦于以下问题:Python RawConfigParser.has_option方法的具体用法?Python RawConfigParser.has_option怎么用?Python RawConfigParser.has_option使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six.moves.configparser.RawConfigParser
的用法示例。
在下文中一共展示了RawConfigParser.has_option方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_config
# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import has_option [as 别名]
def get_config(self, path):
"""
Reads entry from configuration.
"""
section, option = path.split('.', 1)
filename = os.path.join(self.path, '.hg', 'hgrc')
config = RawConfigParser()
config.read(filename)
if config.has_option(section, option):
return config.get(section, option).decode('utf-8')
return None
示例2: get_config
# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import has_option [as 别名]
def get_config(self, path):
"""
Reads entry from configuration.
"""
result = None
section, option = path.split(".", 1)
filename = os.path.join(self.path, ".hg", "hgrc")
config = RawConfigParser()
config.read(filename)
if config.has_option(section, option):
result = config.get(section, option)
if six.PY2:
result = result.decode("utf-8")
return result
示例3: set_config
# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import has_option [as 别名]
def set_config(self, path, value):
"""Set entry in local configuration."""
section, option = path.split('.', 1)
filename = os.path.join(self.path, '.hg', 'hgrc')
if six.PY2:
value = value.encode('utf-8')
section = section.encode('utf-8')
option = option.encode('utf-8')
config = RawConfigParser()
config.read(filename)
if not config.has_section(section):
config.add_section(section)
if (config.has_option(section, option) and
config.get(section, option) == value):
return
config.set(section, option, value)
with open(filename, 'w') as handle:
config.write(handle)
示例4: set_config
# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import has_option [as 别名]
def set_config(self, path, value):
"""
Set entry in local configuration.
"""
section, option = path.split(".", 1)
filename = os.path.join(self.path, ".hg", "hgrc")
if six.PY2:
value = value.encode("utf-8")
section = section.encode("utf-8")
option = option.encode("utf-8")
config = RawConfigParser()
config.read(filename)
if not config.has_section(section):
config.add_section(section)
if config.has_option(section, option) and config.get(section, option) == value:
return
config.set(section, option, value)
with open(filename, "w") as handle:
config.write(handle)
示例5: load_config
# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import has_option [as 别名]
def load_config(self, environ):
"""Load configuration options
Options are read from a config file.
Backwards compatibility:
- if ConfigFile is not set, opts are loaded from http config
- if ConfigFile is set, then the http config must not provide Koji options
- In a future version we will load the default hub config regardless
- all PythonOptions (except koji.web.ConfigFile) are now deprecated and
support for them will disappear in a future version of Koji
"""
cf = environ.get('koji.web.ConfigFile', '/etc/kojiweb/web.conf')
cfdir = environ.get('koji.web.ConfigDir', '/etc/kojiweb/web.conf.d')
if cfdir:
configs = koji.config_directory_contents(cfdir)
else:
configs = []
if cf and os.path.isfile(cf):
configs.append(cf)
if configs:
config = RawConfigParser()
config.read(configs)
else:
raise koji.GenericError("Configuration missing")
opts = {}
for name, dtype, default in self.cfgmap:
key = ('web', name)
if config and config.has_option(*key):
if dtype == 'integer':
opts[name] = config.getint(*key)
elif dtype == 'boolean':
opts[name] = config.getboolean(*key)
elif dtype == 'list':
opts[name] = [x.strip() for x in config.get(*key).split(',')]
else:
opts[name] = config.get(*key)
else:
opts[name] = default
opts['Secret'] = koji.util.HiddenValue(opts['Secret'])
self.options = opts
return opts
示例6: print
# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import has_option [as 别名]
print("Error... must supply the full absolute path of the configuration file.", file=sys.stderr)
sys.exit(1)
startcron = False # variable to say whether to create the crontab (if this is the first time the script is run then this will be changed to True later)
cronid = 'knopeJob' # default ID for the crontab job
# open and parse config file
cp = RawConfigParser()
try:
cp.read(inifile)
except:
print("Error... cannot parse configuration file '%s'" % inifile, file=sys.stderr)
sys.exit(1)
# if configuration file has previous_endtimes option then the cronjob must have started
if not cp.has_option('times', 'previous_endtimes'): # make sure to start the crontab job
startcron = True
# open and parse the run configuration file
if cp.has_option('configuration', 'file'):
runconfig = cp.get('configuration', 'file') # Get main configuration ini template for the run
if not os.path.isfile(runconfig):
print("Error... run configuration file '%s' does not exist!" % runconfig, file=sys.stderr)
if not startcron: remove_cron(cronid) # remove cron job
sys.exit(1)
else:
print("Error... must specify a run configuration '.ini' file", file=sys.stderr)
if startcron: remove_cron(cronid)
sys.exit(1)
示例7: load_config
# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import has_option [as 别名]
def load_config(environ):
"""Load configuration options
Options are read from a config file. The config file location is
controlled by the PythonOption ConfigFile in the httpd config.
Backwards compatibility:
- if ConfigFile is not set, opts are loaded from http config
- if ConfigFile is set, then the http config must not provide Koji options
- In a future version we will load the default hub config regardless
- all PythonOptions (except ConfigFile) are now deprecated and support for them
will disappear in a future version of Koji
"""
logger = logging.getLogger("koji")
#get our config file(s)
cf = environ.get('koji.hub.ConfigFile', '/etc/koji-hub/hub.conf')
cfdir = environ.get('koji.hub.ConfigDir', '/etc/koji-hub/hub.conf.d')
if cfdir:
configs = koji.config_directory_contents(cfdir)
else:
configs = []
if cf and os.path.isfile(cf):
configs.append(cf)
if configs:
config = RawConfigParser()
config.read(configs)
else:
config = None
cfgmap = [
#option, type, default
['DBName', 'string', None],
['DBUser', 'string', None],
['DBHost', 'string', None],
['DBhost', 'string', None], # alias for backwards compatibility
['DBPort', 'integer', None],
['DBPass', 'string', None],
['KojiDir', 'string', None],
['AuthPrincipal', 'string', None],
['AuthKeytab', 'string', None],
['ProxyPrincipals', 'string', ''],
['HostPrincipalFormat', 'string', None],
['DNUsernameComponent', 'string', 'CN'],
['ProxyDNs', 'string', ''],
['CheckClientIP', 'boolean', True],
['LoginCreatesUser', 'boolean', True],
['KojiWebURL', 'string', 'http://localhost.localdomain/koji'],
['EmailDomain', 'string', None],
['NotifyOnSuccess', 'boolean', True],
['DisableNotifications', 'boolean', False],
['Plugins', 'string', ''],
['PluginPath', 'string', '/usr/lib/koji-hub-plugins'],
['KojiDebug', 'boolean', False],
['KojiTraceback', 'string', None],
['VerbosePolicy', 'boolean', False],
['EnableFunctionDebug', 'boolean', False],
['LogLevel', 'string', 'WARNING'],
['LogFormat', 'string', '%(asctime)s [%(levelname)s] m=%(method)s u=%(user_name)s p=%(process)s r=%(remoteaddr)s %(name)s: %(message)s'],
['MissingPolicyOk', 'boolean', True],
['EnableMaven', 'boolean', False],
['EnableWin', 'boolean', False],
['RLIMIT_AS', 'string', None],
['RLIMIT_CORE', 'string', None],
['RLIMIT_CPU', 'string', None],
['RLIMIT_DATA', 'string', None],
['RLIMIT_FSIZE', 'string', None],
['RLIMIT_MEMLOCK', 'string', None],
['RLIMIT_NOFILE', 'string', None],
['RLIMIT_NPROC', 'string', None],
['RLIMIT_OFILE', 'string', None],
['RLIMIT_RSS', 'string', None],
['RLIMIT_STACK', 'string', None],
['MemoryWarnThreshold', 'integer', 5000],
['MaxRequestLength', 'integer', 4194304],
['LockOut', 'boolean', False],
['ServerOffline', 'boolean', False],
['OfflineMessage', 'string', None],
]
opts = {}
for name, dtype, default in cfgmap:
key = ('hub', name)
if config and config.has_option(*key):
if dtype == 'integer':
opts[name] = config.getint(*key)
elif dtype == 'boolean':
opts[name] = config.getboolean(*key)
else:
opts[name] = config.get(*key)
continue
opts[name] = default
#.........这里部分代码省略.........
示例8: get
# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import has_option [as 别名]
def get(self, section, option, literal_eval=True):
value = RawConfigParser.get(self, section, option) if \
RawConfigParser.has_option(self, section, option) else None
if literal_eval:
return CallbackConfigParser.get_literal_value(value)
return value