Common code to run hooks from plugins
"""
import os
+import glob
import sys
import types
import ConfigParser
logger.debug("looking for config")
confname = "gerrithooks.conf"
- conf = find_config(confname, subdir="gerrithooks")
+ conf, confd = find_config(confname, subdir="gerrithooks")
if not conf:
logger.error("Log configuration file %s not found or not readable",
confname)
config = ConfigParser.RawConfigParser()
config.optionxform = str
- logger.debug("runner: reading config from %s", conf)
+ logger.debug("Reading main config from %s", conf)
config.read(conf)
+ if confd:
+ conf = glob.glob(os.path.join(confd,"*.conf"))
+ if conf:
+ logger.debug("Reading additional configs from %s", conf)
+ conf = config.read(conf)
+ logger.debug("read from %s", conf)
+
entry_point_group = "gerrithooks"
- logger.debug("runner: looking for plugins in entry %s", entry_point_group)
for entry_point in iter_entry_points(group=entry_point_group, name=hook):
logger.debug("Loading plugin %s from %s",
def cmd_inout(command, args, cmd_input=None, extra_env=None, cwd=None,
- capture_stderr=False, output_f=None, filter_fn=None,
+ capture_stderr=False, output_f=None, filter_fn=None,
filter_kwargs={}, logger=None):
"""
Run command in subprocess
homedir = pwd.getpwuid(os.getuid()).pw_dir
dirs = []
if subdir:
- dirs.append(os.path.join(homedir,"."+subdir))
+ dirs.append(os.path.join(homedir, "."+subdir))
dirs.append(os.path.join("/etc", subdir))
else:
dirs.append(homedir)
for dirname in dirs:
confpath = os.path.join(dirname, name)
if os.access(confpath, os.R_OK):
- return confpath
+ return (confpath, dirname+'.d')
if os.getenv('VIRTUAL_ENV'):
resource_conf = resource_filename(__package__, name)
if resource_conf and os.access(resource_conf, os.R_OK):
- return resource_conf
- return None
+ return (resource_conf, None)
+ return (None, None)
def configure_logging(appname):
"""Setup logging"""
- homedir = pwd.getpwuid(os.getuid()).pw_dir
log_confname = "gerrithooks-log.conf"
- log_config = find_config(log_confname, subdir="gerrithooks")
+ log_config, _ = find_config(log_confname, subdir="gerrithooks")
if not log_config:
raise SystemExit("Log configuration file %s not found or not readable" \
% log_confname)