def __init__(self, conf_file, logging_level, group):
# Load the default conf and store it globally
sg.config = ConfigParser.RawConfigParser()
with codecs.open(conf_file, 'r', sg.DEFAULT_CHARSET) as fp:
sg.config.readfp(fp)
# Set up the logger and store it globally
logger_file = sg.config.get(sg.CONF_LOG_SECTION, sg.CONF_LOG_FILE)
logger_file_max_size = sg.config.get(sg.CONF_LOG_SECTION, sg.CONF_LOG_FILE_MAX_SIZE)
logger_formatter = sg.config.get(sg.CONF_LOG_SECTION, sg.CONF_LOG_FORMATTER)
sg.createDirName(logger_file);
log_file = RotatingFileHandler(logger_file, 'a', logger_file_max_size, 1)
log_file.setLevel(logging_level)
log_file.setFormatter(logging.Formatter(logger_formatter))
sg.logger = logging.getLogger()
sg.logger.setLevel(logging.DEBUG)
sg.logger.addHandler(log_file)
# Set up the database connection and store it globally
sg.db = SQLHelper()
# Load the stored configuration
try:
confs = sg.db.session.query(CONF).filter(CONF.group_id == None, CONF.section == sg.CONF_INSTANCE_SECTION).all()
for conf in confs:
sg.config.set(sg.CONF_INSTANCE_SECTION, conf.key, conf.value)
sg.logger.info('Loaded stored configurations for instance!')
except (NoResultFound, ProgrammingError) as e:
sg.logger.warning('No configurations for instance!')
# Mail walker
评论列表
文章目录