本文整理汇总了Python中git.repo.Repo.config_reader方法的典型用法代码示例。如果您正苦于以下问题:Python Repo.config_reader方法的具体用法?Python Repo.config_reader怎么用?Python Repo.config_reader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git.repo.Repo
的用法示例。
在下文中一共展示了Repo.config_reader方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Configuration
# 需要导入模块: from git.repo import Repo [as 别名]
# 或者: from git.repo.Repo import config_reader [as 别名]
class Configuration(object):
config = {}
drivers = {}
_config_levels = ['system', 'global', 'trigger', 'repository']
def __init__(self):
try:
self.repo = Repo('.')
except InvalidGitRepositoryError:
msg = 'Not in a git repository'
raise ConfigurationError(msg, 1)
self._load_config()
self._missing_config = {}
config = {
'repo-name': ('deploy', 'repo-name', None),
'user.name': ('user', 'name', None),
'user.email': ('user', 'email', None),
}
self._register_config(config)
self.register_drivers()
self._check_config()
def _load_config(self):
self._repo_config = {}
self._repo_config['system'] = self.repo.config_reader('system')
self._repo_config['global'] = self.repo.config_reader('global')
try:
f = open(os.path.join(self.repo.working_dir, '.trigger'), 'r')
trigger_config = f.read()
f.close()
self._repo_config['trigger'] = yaml.safe_load(trigger_config)
except (IOError, OSError):
self._repo_config['trigger'] = {}
except (ValueError, KeyError):
LOG.warning('Found a .trigger config file, but could not parse'
' it. Unable to load repo specific config.')
self._repo_config['repository'] = self.repo.config_reader('repository')
def register_drivers(self):
driver_config = {
'sync-driver': ('deploy', 'sync-driver',
'trebuchet.local.SyncDriver'),
'lock-driver': ('deploy', 'lock-driver',
'trebuchet.local.LockDriver'),
'service-driver': ('deploy', 'service-driver',
'trebuchet.local.ServiceDriver'),
'report-driver': ('deploy', 'report-driver',
'trebuchet.local.ReportDriver'),
}
self._register_config(driver_config)
for driver in driver_config:
LOG.debug('Getting config for driver: {}'.format(driver))
driver_config = self.config[driver]
mod, _, cls = driver_config.rpartition('.')
mod = 'trigger.drivers.' + mod
try:
LOG.debug('Importing {}'.format(mod))
__import__(mod)
driver_class = getattr(sys.modules[mod], cls)
self.drivers[driver] = driver_class(self)
self._register_config(self.drivers[driver].get_config())
except (ValueError, AttributeError):
msg = 'Failed to import driver: {0}'.format(mod)
raise ConfigurationError(msg, 1)
def _register_config(self, config):
for level in self._config_levels:
repo_config = self._repo_config[level]
for key, val in config.items():
try:
if level == 'trigger':
_key = '{0}.{1}'.format(val[0], val[1])
self.config[key] = repo_config[_key]
else:
self.config[key] = repo_config.get_value(val[0],
val[1])
except (KeyError,
ConfigParser.NoOptionError,
ConfigParser.NoSectionError):
if val[2] is not None:
self.config[key] = val[2]
for key, val in config.items():
if key not in self.config:
self._missing_config[key] = val
def _check_config(self):
if self._missing_config:
for key, val in self._missing_config.items():
msg = ('Missing the following configuration item:'
' {0}.{1}').format(val[0], val[1])
LOG.error(msg)
raise ConfigurationError('Please add the missing configuration'
' items via git config or in the'
' .trigger file', 1)
def register_cli_options(self, options):
raise NotImplementedError
示例2: Configuration
# 需要导入模块: from git.repo import Repo [as 别名]
# 或者: from git.repo.Repo import config_reader [as 别名]
class Configuration(object):
config = {}
drivers = {}
_config_levels = ['system', 'global', 'trigger', 'repository']
def __init__(self):
try:
self.repo = Repo('.')
except InvalidGitRepositoryError:
msg = 'Not in a git repository'
raise ConfigurationError(msg, 1)
self._load_config()
self._missing_config = []
config = {
'deploy.repo-name': {
'required': True,
},
'deploy.required-umask': {
'required': False,
'default': None,
},
'user.name': {
'required': True,
},
'user.email': {
'required': True,
},
}
self._register_config(config)
self.register_drivers()
def _load_config(self):
self._repo_config = {}
self._repo_config['system'] = self.repo.config_reader('system')
self._repo_config['global'] = self.repo.config_reader('global')
try:
f = open(os.path.join(self.repo.working_dir, '.trigger'), 'r')
trigger_config = f.read()
f.close()
self._repo_config['trigger'] = yaml.safe_load(trigger_config)
except (IOError, OSError):
self._repo_config['trigger'] = {}
except (ValueError, KeyError):
LOG.warning('Found a .trigger config file, but could not parse'
' it. Unable to load repo specific config.')
self._repo_config['repository'] = self.repo.config_reader('repository')
def register_drivers(self):
driver_config = {
'deploy.sync-driver': {
'required': True,
'default': 'trebuchet.local.SyncDriver'
},
'deploy.lock-driver': {
'required': True,
'default': 'trebuchet.local.LockDriver'
},
'deploy.service-driver': {
'required': True,
'default': 'trebuchet.local.ServiceDriver'
},
'deploy.report-driver': {
'required': True,
'default': 'trebuchet.local.ReportDriver'
},
}
self._register_config(driver_config)
for driver in driver_config:
driver_config = self.config[driver]
driver_name = driver.split('.')[1]
LOG.debug('Getting config for driver: {}'.format(driver_name))
mod, _, cls = driver_config.rpartition('.')
mod = 'trigger.drivers.' + mod
try:
LOG.debug('Importing {}'.format(mod))
__import__(mod)
driver_class = getattr(sys.modules[mod], cls)
self.drivers[driver_name] = driver_class(self)
self._register_config(self.drivers[driver_name].get_config())
except (ValueError, AttributeError):
msg = 'Failed to import driver: {0}'.format(mod)
raise ConfigurationError(msg, 1)
def _register_config(self, config):
for level in self._config_levels:
repo_config = self._repo_config[level]
for key, item in config.items():
try:
section, name = key.split('.')
if level == 'trigger':
self.config[key] = repo_config[key]
else:
self.config[key] = repo_config.get_value(section,
name)
except (KeyError,
ConfigParser.NoOptionError,
ConfigParser.NoSectionError):
if 'default' in item:
self.config[key] = item['default']
#.........这里部分代码省略.........