def valid_wfile(self,s): """return True if we can write to the file""" try: util.can_write_file(s,delete=True) return True except: return False
def valid_wfile(self,s): """return True if we can write to the file""" try: util.can_write_file(s,delete=True) return True except: return False
def __init__(self,conf_file): """create a new config parser tied to the given bot""" # OrderedDict containing full descriptions of options self.OPTS = odict([ #option default requir parse_func validate_func post_func whitelist blacklist #----------------------------------------------------------------------------------------------------------------------------- ('protocols', ({}, True, self.parse_protocols, None, None, None, None)), ('enable', ([], False, self.parse_plugins, None, None, None, None)), ('disable', ([], False, self.parse_plugins, None, None, None, None)), ('rename', ({}, False, self.parse_rename, None, None, None, None)), ('cmd_dir', ('cmds', False, None, self.valid_dir, None, None, None)), ('rooms', ({}, False, self.parse_rooms, None, self.post_rooms, None, None)), ('nick_name', ('Sibyl', False, None, None, None, None, None)), ('log_level', (logging.INFO, False, self.parse_log, None, None, None, None)), ('log_file', ('data/sibyl.log', False, None, self.valid_wfile, None, None, None)), ('log_append', (True, False, self.parse_bool, None, None, None, None)), ('log_hooks', (False, False, self.parse_bool, None, None, None, None)), ('log_requests',(False, False, self.parse_bool, None, None, None, None)), ('log_urllib3', (False, False, self.parse_bool, None, None, None, None)), ('bw_list', ([('w','*','*')], False, self.parse_bw, None, None, None, None)), ('chat_ctrl', (False, False, self.parse_bool, None, None, None, None)), ('cmd_prefix', (None, False, None, None, None, None, None)), ('except_reply',(False, False, self.parse_bool, None, None, None, None)), ('only_direct', (True, False, self.parse_bool, None, None, None, None)), ('catch_except',(True, False, self.parse_bool, None, None, None, None)), ('help_plugin', (False, False, self.parse_bool, None, None, None, None)), ('recon_min', (30, False, self.parse_int, None, None, None, None)), ('recon_max', (300, False, self.parse_int, None, None, None, None)), ('kill_stdout', (True, False, self.parse_bool, None, None, None, None)), ('tell_errors', (True, False, self.parse_bool, None, None, None, None)), ('admin_protos',(['cli'], False, self.parse_admin, self.valid_admin, None, None, None)), ('persistence', (True, False, self.parse_bool, None, None, None, None)), ('state_file', ('data/state.pickle', False, None, self.valid_wfile, None, None, None)), ('idle_time', (0.1, False, self.parse_float, self.valid_nump, None, None, None)), ('idle_count', (5, False, self.parse_int, self.valid_nump, None, None, None)), ('idle_freq', (1, False, self.parse_int, self.valid_nump, None, None, None)), ('defer_total', (100, False, self.parse_int, None, None, None, None)), ('defer_proto', (100, False, self.parse_int, None, None, None, None)), ('defer_room', (10, False, self.parse_int, None, None, None, None)), ('defer_priv', (10, False, self.parse_int, None, None, None, None)) ]) # create "namespace" dict self.NS = {k:'sibylbot' for k in self.OPTS} # initialise variables self.opts = None self.conf_file = conf_file self.log_msgs = [] self.logging = True self.real_time = False self.__log = logging.getLogger('config') # raise an exception if we can't write to conf_file util.can_write_file(self.conf_file,delete=True) # write a default conf_file if it doesn't exist at all if not os.path.isfile(self.conf_file): self.write_default_conf()
def __init__(self,conf_file): """create a new config parser tied to the given bot""" # OrderedDict containing full descriptions of options self.OPTS = odict([ #option default requir parse_func validate_func post_func #------------------------------------------------------------------------------------------------ ('protocols', ({}, True, self.parse_protocols, None, None)), ('enable', ([], False, self.parse_plugins, None, None)), ('disable', ([], False, self.parse_plugins, None, None)), ('rename', ({}, False, self.parse_rename, None, None)), ('cmd_dir', ('cmds', False, None, self.valid_dir, None)), ('rooms', ({}, False, self.parse_rooms, None, self.post_rooms)), ('nick_name', ('Sibyl', False, None, None, None)), ('log_level', (logging.INFO, False, self.parse_log, None, None)), ('log_file', ('data/sibyl.log', False, None, self.valid_wfile, None)), ('log_append', (True, False, self.parse_bool, None, None)), ('log_hooks', (False, False, self.parse_bool, None, None)), ('log_requests',(False, False, self.parse_bool, None, None)), ('log_urllib3', (False, False, self.parse_bool, None, None)), ('bw_list', ([('w','*','*')], False, self.parse_bw, None, None)), ('chat_ctrl', (False, False, self.parse_bool, None, None)), ('cmd_prefix', (None, False, None, None, None)), ('except_reply',(False, False, self.parse_bool, None, None)), ('only_direct', (True, False, self.parse_bool, None, None)), ('catch_except',(True, False, self.parse_bool, None, None)), ('help_plugin', (False, False, self.parse_bool, None, None)), ('recon_wait', (60, False, self.parse_int, None, None)), ('kill_stdout', (True, False, self.parse_bool, None, None)), ('tell_errors', (True, False, self.parse_bool, None, None)), ('admin_protos',(['cli'], False, self.parse_admin, self.valid_admin, None)), ('persistence', (True, False, self.parse_bool, None, None)), ('state_file', ('data/state.pickle', False, None, self.valid_wfile, None)), ('idle_time', (0.1, False, self.parse_float, self.valid_nump, None)), ('idle_count', (5, False, self.parse_int, self.valid_nump, None)), ('idle_freq', (1, False, self.parse_int, self.valid_nump, None)), ('defer_total', (100, False, self.parse_int, None, None)), ('defer_proto', (100, False, self.parse_int, None, None)), ('defer_room', (10, False, self.parse_int, None, None)), ('defer_priv', (10, False, self.parse_int, None, None)) ]) # create "namespace" dict self.NS = {k:'sibylbot' for k in self.OPTS} # initialise variables self.opts = None self.conf_file = conf_file self.log_msgs = [] self.logging = True self.real_time = False self.__log = logging.getLogger('config') # raise an exception if we can't write to conf_file util.can_write_file(self.conf_file,delete=True) # write a default conf_file if it doesn't exist at all if not os.path.isfile(self.conf_file): self.write_default_conf()