本文整理汇总了Python中logging.config.read方法的典型用法代码示例。如果您正苦于以下问题:Python config.read方法的具体用法?Python config.read怎么用?Python config.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logging.config
的用法示例。
在下文中一共展示了config.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_conf_file
# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import read [as 别名]
def load_conf_file(conf_file):
"""Loads and parses conf file
Loads and parses the module conf file
Args:
conf_file: string with the conf file name
Returns:
ConfigParser object with conf_file configs
"""
if not os.path.isfile(conf_file):
raise OneViewRedfishResourceNotFoundException(
"File {} not found.".format(conf_file)
)
config = configparser.ConfigParser()
config.optionxform = str
try:
config.read(conf_file)
except Exception:
raise
return config
示例2: create_config
# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import read [as 别名]
def create_config(parser):
options = parse_arguments(parser)
# 1) read the default config at "~/.pyepm"
config = c.read_config()
# 2) read config from file
cfg_fn = getattr(options, 'config')
if cfg_fn:
if not os.path.exists(cfg_fn):
c.read_config(cfg_fn) # creates default
config.read(cfg_fn)
# 3) apply cmd line options to config
for section in config.sections():
for a, v in config.items(section):
if getattr(options, a, None) is not None:
config.set(section, a, getattr(options, a))
# set config_dir
config_dir.set(config.get('misc', 'config_dir'))
return config
示例3: configureData
# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import read [as 别名]
def configureData(args, dataConfigPath):
'''
Configure Data configuration file from command line
:param args: argparse arguments
:param dataConfigPath: Path to data.ini file
:return: None
'''
config = ConfigParser.RawConfigParser()
config.read(os.path.join(path, "data.ini"))
if args.flaskhost is not None:
config.set('FLASK', 'HOST', args.flaskhost)
if args.flaskport is not None:
config.set('FLASK', 'PORT', args.flaskport)
if args.proxyhost is not None:
config.set('PROXY', 'HOST', args.proxyhost)
if args.proxyport is not None:
config.set('PROXY', 'PORT', args.proxyport)
with open(dataConfigPath, 'wb') as configfile:
config.write(configfile)
# Now act upon the command line arguments
# Initialize and configure Data
示例4: get_config
# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import read [as 别名]
def get_config():
global _CURRENT_CONFIG
if _CURRENT_CONFIG is None:
# read the config file
_CURRENT_CONFIG = configparser.ConfigParser()
_CURRENT_CONFIG.read(CONFIG_FILE)
return _CURRENT_CONFIG
示例5: get_restful_params
# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import read [as 别名]
def get_restful_params(urlstring):
"""Returns a dictionary of paired RESTful URI parameters"""
parsed_path = urllib.parse.urlsplit(urlstring.strip("/"))
query_params = urllib.parse.parse_qsl(parsed_path.query)
path_tokens = parsed_path.path.split('/')
# If first token is API version, ensure it isn't obsolete
api_version = API_VERSION
if len(path_tokens[0]) == 2 and path_tokens[0][0] == 'v':
# Require latest API version
if path_tokens[0][1] != API_VERSION:
return None
api_version = path_tokens.pop(0)
path_params = list_to_dict(path_tokens)
path_params["api_version"] = api_version
path_params.update(query_params)
return path_params
# this doesn't currently work
# if LOAD_TEST:
# config = ConfigParser.RawConfigParser()
# config.read(CONFIG_FILE)
# TEST_CREATE_DEEP_QUOTE_DELAY = config.getfloat('general', 'test_deep_quote_delay')
# TEST_CREATE_QUOTE_DELAY = config.getfloat('general','test_quote_delay')
# NOTE These are still used by platform init in dev in eclipse mode
示例6: parse_monitoring_args
# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import read [as 别名]
def parse_monitoring_args(self, args_str, args, sm_args, _rev_tags_dict, base_obj):
config = ConfigParser.SafeConfigParser()
config.read([args.config_file])
try:
if dict(config.items("MONITORING")).keys():
# Handle parsing for monitoring
monitoring_args = self.parse_args(args_str, "MONITORING")
if monitoring_args:
self._smgr_log.log(self._smgr_log.DEBUG, "Monitoring arguments read from config.")
self.monitoring_args = monitoring_args
else:
self._smgr_log.log(self._smgr_log.DEBUG, "No monitoring configuration set.")
else:
self._smgr_log.log(self._smgr_log.DEBUG, "No monitoring configuration set.")
except ConfigParser.NoSectionError:
self._smgr_log.log(self._smgr_log.DEBUG, "No monitoring configuration set.")
if self.monitoring_args:
try:
if self.monitoring_args.monitoring_plugin:
module_components = str(self.monitoring_args.monitoring_plugin).split('.')
monitoring_module = __import__(str(module_components[0]))
monitoring_class = getattr(monitoring_module, module_components[1])
if sm_args.collectors:
self.server_monitoring_obj = monitoring_class(1, self.monitoring_args.monitoring_frequency,
sm_args.listen_ip_addr,
sm_args.listen_port, sm_args.collectors,
sm_args.http_introspect_port, _rev_tags_dict)
self.monitoring_config_set = True
else:
self._smgr_log.log(self._smgr_log.ERROR,
"Analytics IP and Monitoring API misconfigured, monitoring aborted")
self.server_monitoring_obj = base_obj
except ImportError as ie:
self._smgr_log.log(self._smgr_log.ERROR,
"Configured modules are missing. Server Manager will quit now.")
self._smgr_log.log(self._smgr_log.ERROR, "Error: " + str(ie))
raise ImportError
else:
self.server_monitoring_obj = base_obj
return self.server_monitoring_obj
示例7: parse_inventory_args
# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import read [as 别名]
def parse_inventory_args(self, args_str, args, sm_args, _rev_tags_dict, base_obj):
config = ConfigParser.SafeConfigParser()
config.read([args.config_file])
try:
if dict(config.items("INVENTORY")).keys():
# Handle parsing for monitoring
inventory_args = self.parse_args(args_str, "INVENTORY")
if inventory_args:
self._smgr_log.log(self._smgr_log.DEBUG, "Inventory arguments read from config.")
self.inventory_args = inventory_args
else:
self._smgr_log.log(self._smgr_log.DEBUG, "No inventory configuration set.")
else:
self._smgr_log.log(self._smgr_log.DEBUG, "No inventory configuration set.")
except ConfigParser.NoSectionError:
self._smgr_log.log(self._smgr_log.DEBUG, "No inventory configuration set.")
if self.inventory_args:
try:
if self.inventory_args.inventory_plugin:
module_components = str(self.inventory_args.inventory_plugin).split('.')
inventory_module = __import__(str(module_components[0]))
inventory_class = getattr(inventory_module, module_components[1])
if sm_args.collectors:
self.server_inventory_obj = inventory_class(sm_args.listen_ip_addr, sm_args.listen_port,
sm_args.http_introspect_port, _rev_tags_dict)
self.inventory_config_set = True
else:
self._smgr_log.log(self._smgr_log.ERROR,
"Iventory API misconfigured, inventory aborted")
self.server_inventory_obj = base_obj
except ImportError:
self._smgr_log.log(self._smgr_log.ERROR,
"Configured modules are missing. Server Manager will quit now.")
raise ImportError
else:
self.server_inventory_obj = base_obj
return self.server_inventory_obj
示例8: handle_inventory_trigger
# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import read [as 别名]
def handle_inventory_trigger(self, action=None, servers=None):
self._smgr_log.log(self._smgr_log.INFO, "Inventory of added servers will not be read.")
return "Inventory Parameters haven't been configured.\n" \
"Reset the configuration correctly and restart Server Manager.\n"
示例9: can_read_cert
# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import read [as 别名]
def can_read_cert():
if not os.access(CLIENT_CERT_PATH, os.R_OK):
logger.error('Permission denied when trying to read the certificate file.')
exit(1)
if not os.access(CLIENT_KEY_PATH, os.R_OK):
logger.error('Permission denied when trying to read the key file.')
exit(1)
示例10: get_certificate_expiration_date
# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import read [as 别名]
def get_certificate_expiration_date():
"""
Returns the expiration date of the certificate.
"""
can_read_cert()
with open(CLIENT_CERT_PATH, 'r') as f:
cert = x509.load_pem_x509_certificate(
f.read().encode(), default_backend()
)
return cert.not_valid_after.replace(tzinfo=pytz.utc)
示例11: get_device_id
# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import read [as 别名]
def get_device_id(dev=False):
"""
Returns the WoTT Device ID (i.e. fqdn) by reading the first subject from
the certificate on disk.
"""
can_read_cert()
with open(CLIENT_CERT_PATH, 'r') as f:
cert = x509.load_pem_x509_certificate(
f.read().encode(), default_backend()
)
return cert.subject.get_attributes_for_oid(NameOID.COMMON_NAME)[0].value
示例12: try_enroll_in_operation_mode
# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import read [as 别名]
def try_enroll_in_operation_mode(device_id, dev):
enroll_token = get_enroll_token()
if enroll_token is None:
return
logger.info("Enroll token found. Trying to automatically enroll the node.")
setup_endpoints(dev)
response = mtls_request('get', 'claimed', dev=dev, requester_name="Get Node Claim Info")
if response is None or not response.ok:
logger.error('Did not manage to get claim info from the server.')
return
logger.debug("[RECEIVED] Get Node Claim Info: {}".format(response))
claim_info = response.json()
if claim_info['claimed']:
logger.info('The node is already claimed. No enrolling required.')
else:
claim_token = claim_info['claim_token']
if not enroll_device(enroll_token, claim_token, device_id):
logger.error('Node enrolling failed. Will try next time.')
return
logger.info("Update config...")
config = configparser.ConfigParser()
config.read(INI_PATH)
config.remove_option('DEFAULT', 'enroll_token')
with open(INI_PATH, 'w') as configfile:
config.write(configfile)
os.chmod(INI_PATH, 0o600)
示例13: get_fallback_token
# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import read [as 别名]
def get_fallback_token():
config = configparser.ConfigParser()
config.read(INI_PATH)
return config['DEFAULT'].get('fallback_token')
示例14: get_ini_log_file
# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import read [as 别名]
def get_ini_log_file():
config = configparser.ConfigParser()
config.read(INI_PATH)
return config['DEFAULT'].get('log_file')
示例15: get_enroll_token
# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import read [as 别名]
def get_enroll_token():
config = configparser.ConfigParser()
config.read(INI_PATH)
return config['DEFAULT'].get('enroll_token')