def __init__(self, cfg=None): """Create new object by reading a configuration file. :param: cfg (string) path of the configuration file. """ default_cfg = 'smtp.cfg' config = ConfigParser.ConfigParser() if cfg is None or not os.path.isfile(cfg): cfg = default_cfg try: with open(cfg) as f: config.readfp(f) except IOError: raise ConfigError("File %s not found!" % cfg) try: self.our_domain = config.get('general', 'our_domain') self.mirrors = config.get('general', 'mirrors') self.i18ndir = config.get('i18n', 'dir') logdir = config.get('log', 'dir') logfile = os.path.join(logdir, 'smtp.log') loglevel = config.get('log', 'level') blacklist_cfg = config.get('blacklist', 'cfg') self.bl = blacklist.Blacklist(blacklist_cfg) self.bl_max_req = config.get('blacklist', 'max_requests') self.bl_max_req = int(self.bl_max_req) self.bl_wait_time = config.get('blacklist', 'wait_time') self.bl_wait_time = int(self.bl_wait_time) core_cfg = config.get('general', 'core_cfg') self.core = core.Core(core_cfg) except ConfigParser.Error as e: raise ConfigError("Configuration error: %s" % str(e)) except blacklist.ConfigError as e: raise InternalError("Blacklist error: %s" % str(e)) except core.ConfigError as e: raise InternalError("Core error: %s" % str(e)) # logging log = logging.getLogger(__name__) logging_format = utils.get_logging_format() date_format = utils.get_date_format() formatter = logging.Formatter(logging_format, date_format) log.info('Redirecting SMTP logging to %s' % logfile) logfileh = logging.FileHandler(logfile, mode='a+') logfileh.setFormatter(formatter) logfileh.setLevel(logging.getLevelName(loglevel)) log.addHandler(logfileh) # stop logging on stdout from now on log.propagate = False self.log = log
def __init__(self, cfg=None): """Create a new core object by reading a configuration file. :param: cfg (string) the path of the configuration file. :raise: ConfigurationError if the configuration file doesn't exists or if something goes wrong while reading options from it. """ default_cfg = 'core.cfg' config = ConfigParser.ConfigParser() if cfg is None or not os.path.isfile(cfg): cfg = default_cfg try: with open(cfg) as f: config.readfp(f) except IOError: raise ConfigError("File %s not found!" % cfg) try: self.supported_lc = config.get('links', 'locales') self.supported_os = config.get('links', 'os') basedir = config.get('general', 'basedir') self.linksdir = config.get('links', 'dir') self.linksdir = os.path.join(basedir, self.linksdir) self.i18ndir = config.get('i18n', 'dir') loglevel = config.get('log', 'level') logdir = config.get('log', 'dir') logfile = os.path.join(logdir, 'core.log') dbname = config.get('general', 'db') dbname = os.path.join(basedir, dbname) self.db = db.DB(dbname) except ConfigParser.Error as e: raise ConfigError("Configuration error: %s" % str(e)) except db.Exception as e: raise InternalError("%s" % e) # logging log = logging.getLogger(__name__) logging_format = utils.get_logging_format() date_format = utils.get_date_format() formatter = logging.Formatter(logging_format, date_format) log.info('Redirecting CORE logging to %s' % logfile) logfileh = logging.FileHandler(logfile, mode='a+') logfileh.setFormatter(formatter) logfileh.setLevel(logging.getLevelName(loglevel)) log.addHandler(logfileh) # stop logging on stdout from now on log.propagate = False self.log = log
def __init__(self, cfg=None): """Create new object by reading a configuration file. :param: cfg (string) path of the configuration file. """ default_cfg = 'blacklist.cfg' config = ConfigParser.ConfigParser() if cfg is None or not os.path.isfile(cfg): cfg = default_cfg try: with open(cfg) as f: config.readfp(f) except IOError: raise ConfigError("File %s not found!" % cfg) try: dbname = config.get('general', 'db') logdir = config.get('log', 'dir') logfile = os.path.join(logdir, 'blacklist.log') loglevel = config.get('log', 'level') self.db = db.DB(dbname) except ConfigParser.Error as e: raise ConfigError("%s" % e) except db.Exception as e: raise ConfigError("%s" % e) # logging log = logging.getLogger(__name__) logging_format = utils.get_logging_format() date_format = utils.get_date_format() formatter = logging.Formatter(logging_format, date_format) log.info('Redirecting BLACKLIST logging to %s' % logfile) logfileh = logging.FileHandler(logfile, mode='a+') logfileh.setFormatter(formatter) logfileh.setLevel(logging.getLevelName(loglevel)) log.addHandler(logfileh) # stop logging on stdout from now on log.propagate = False self.log = log
def __init__(self, cfg=None): """ Create new object by reading a configuration file. :param: cfg (string) the path of the configuration file. """ default_cfg = 'twitter.cfg' config = ConfigParser.ConfigParser() if cfg is None or not os.path.isfile(cfg): cfg = default_cfg try: with open(cfg) as f: config.readfp(f) except IOError: raise ConfigError("File %s not found!" % cfg) try: self.api_key = config.get('access_config', 'api_key') self.api_secret = config.get('access_config', 'api_secret') self.access_token = config.get('access_config', 'access_token') self.token_secret = config.get('access_config', 'token_secret') self.mirrors = config.get('general', 'mirrors') self.i18ndir = config.get('i18n', 'dir') logdir = config.get('log', 'dir') logfile = os.path.join(logdir, 'twitter.log') loglevel = config.get('log', 'level') blacklist_cfg = config.get('blacklist', 'cfg') self.bl = blacklist.Blacklist(blacklist_cfg) self.bl_max_request = config.get('blacklist', 'max_requests') self.bl_max_request = int(self.bl_max_request) self.bl_wait_time = config.get('blacklist', 'wait_time') self.bl_wait_time = int(self.bl_wait_time) core_cfg = config.get('general', 'core_cfg') self.core = core.Core(core_cfg) except ConfigParser.Error as e: raise ConfigError("Configuration error: %s" % str(e)) except blacklist.ConfigError as e: raise InternalError("Blacklist error: %s" % str(e)) except core.ConfigError as e: raise InternalError("Core error: %s" % str(e)) # logging log = logging.getLogger(__name__) logging_format = utils.get_logging_format() date_format = utils.get_date_format() formatter = logging.Formatter(logging_format, date_format) log.info('Redirecting Twitter logging to %s' % logfile) logfileh = logging.FileHandler(logfile, mode='a+') logfileh.setFormatter(formatter) logfileh.setLevel(logging.getLevelName(loglevel)) log.addHandler(logfileh) self.log = log
def __init__(self, cfg=None): """Create new object by reading a configuration file. :param: cfg (string) the path of the configuration file. """ # define a set of default values default_cfg = 'xmpp.cfg' config = ConfigParser.ConfigParser() if cfg is None or not os.path.isfile(cfg): cfg = default_cfg try: with open(cfg) as f: config.readfp(f) except IOError: raise ConfigError("File %s not found!" % cfg) try: self.user = config.get('account', 'user') self.password = config.get('account', 'password') self.mirrors = config.get('general', 'mirrors') self.max_words = config.get('general', 'max_words') self.max_words = int(self.max_words) core_cfg = config.get('general', 'core_cfg') self.core = core.Core(core_cfg) self.i18ndir = config.get('i18n', 'dir') blacklist_cfg = config.get('blacklist', 'cfg') self.bl = blacklist.Blacklist(blacklist_cfg) self.bl_max_req = config.get('blacklist', 'max_requests') self.bl_max_req = int(self.bl_max_req) self.bl_wait_time = config.get('blacklist', 'wait_time') self.bl_wait_time = int(self.bl_wait_time) logdir = config.get('log', 'dir') logfile = os.path.join(logdir, 'xmpp.log') loglevel = config.get('log', 'level') except ConfigParser.Error as e: raise ConfigError("Configuration error: %s" % str(e)) except blacklist.ConfigError as e: raise InternalError("Blacklist error: %s" % str(e)) except core.ConfigError as e: raise InternalError("Core error: %s" % str(e)) # logging log = logging.getLogger(__name__) logging_format = utils.get_logging_format() date_format = utils.get_date_format() formatter = logging.Formatter(logging_format, date_format) log.info('Redirecting XMPP logging to %s' % logfile) logfileh = logging.FileHandler(logfile, mode='a+') logfileh.setFormatter(formatter) logfileh.setLevel(logging.getLevelName(loglevel)) log.addHandler(logfileh) # stop logging on stdout from now on log.propagate = False self.log = log