def __init__(self, conf_folder, **kwargs): MessagingModule.__init__(self) # Dwarf professions. conf_file = os.path.join(conf_folder, CONFIG_FILE) # Ordered because order matters conf_dict = OrderedDict() conf_dict['gui_information'] = { 'category': 'test', 'id': DEFAULT_PRIORITY } config = load_from_config_file(conf_file, conf_dict) self._conf_params.update({ 'folder': conf_folder, 'file': conf_file, 'filename': ''.join(os.path.basename(conf_file).split('.')[:-1]), 'parser': config, 'id': conf_dict['gui_information']['id'], 'config': OrderedDict(conf_dict), 'custom_renderer': True })
def __init__(self, queue, python_folder, **kwargs): ChatModule.__init__(self) log.info("Initializing funstream chat") # Reading config from main directory. conf_folder = os.path.join(python_folder, "conf") conf_file = os.path.join(conf_folder, "sc2tv.cfg") config = load_from_config_file(conf_file, CONF_DICT) self._conf_params.update( {'folder': conf_folder, 'file': conf_file, 'filename': ''.join(os.path.basename(conf_file).split('.')[:-1]), 'parser': config, 'config': CONF_DICT, 'gui': CONF_GUI}) self.queue = queue self.socket = CONF_DICT['config']['socket'] self.channels_list = CONF_DICT['config']['channels_list'] self.fs_thread = {} if len(self.channels_list) == 1: if CONF_DICT['config']['show_channel_names']: CONF_DICT['config']['show_channel_names'] = False self.testing = kwargs.get('testing') if self.testing: self.testing = TestSc2tv(self)
def __init__(self, conf_folder, **kwargs): MessagingModule.__init__(self) # Dwarf professions. conf_file = os.path.join(conf_folder, "blacklist.cfg") # Ordered because order matters conf_dict = OrderedDict() conf_dict['gui_information'] = { 'category': 'messaging', 'id': DEFAULT_PRIORITY } conf_dict['main'] = {'message': 'ignored message'} conf_dict['users_hide'] = [] conf_dict['users_block'] = [] conf_dict['words_hide'] = [] conf_dict['words_block'] = [] conf_gui = { 'words_hide': { 'addable': True, 'view': 'list' }, 'words_block': { 'addable': True, 'view': 'list' }, 'users_hide': { 'view': 'list', 'addable': 'true' }, 'users_block': { 'view': 'list', 'addable': 'true' }, 'non_dynamic': ['main.*'] } config = load_from_config_file(conf_file, conf_dict) self._conf_params.update({ 'folder': conf_folder, 'file': conf_file, 'filename': ''.join(os.path.basename(conf_file).split('.')[:-1]), 'parser': config, 'id': conf_dict['gui_information']['id'], 'config': OrderedDict(conf_dict), 'gui': conf_gui })
def __init__(self, conf_folder, **kwargs): MessagingModule.__init__(self) # Creating filter and replace strings. conf_file = os.path.join(conf_folder, "logger.cfg") conf_dict = OrderedDict() conf_dict['gui_information'] = { 'category': 'messaging', 'id': DEFAULT_PRIORITY } conf_dict['config'] = OrderedDict() conf_dict['config']['logging'] = True conf_dict['config']['file_format'] = '%Y-%m-%d' conf_dict['config']['message_date_format'] = '%Y-%m-%d %H:%M:%S' conf_dict['config']['rotation'] = 'daily' conf_gui = {'non_dynamic': ['config.*']} config = load_from_config_file(conf_file, conf_dict) self._conf_params.update({ 'folder': conf_folder, 'file': conf_file, 'filename': ''.join(os.path.basename(conf_file).split('.')[:-1]), 'parser': config, 'id': conf_dict['gui_information']['id'], 'config': conf_dict, 'gui': conf_gui }) self.format = conf_dict['config']['file_format'] self.ts_format = conf_dict['config']['message_date_format'] self.logging = conf_dict['config']['logging'] self.rotation = conf_dict['config']['rotation'] self.folder = 'logs' self.destination = os.path.join(conf_folder, '..', self.folder) if not os.path.exists(self.destination): os.makedirs(self.destination)
def __init__(self, conf_folder, **kwargs): MessagingModule.__init__(self) # Dwarf professions. conf_file = os.path.join(conf_folder, "df.cfg") conf_dict = OrderedDict() conf_dict['gui_information'] = {'category': 'messaging'} conf_dict['grep'] = OrderedDict() conf_dict['grep']['symbol'] = '#' conf_dict['grep']['file'] = 'logs/df.txt' conf_dict['prof'] = OrderedDict() conf_gui = { 'prof': { 'view': 'list_dual', 'addable': True }, 'non_dynamic': ['grep.*'] } config = load_from_config_file(conf_file, conf_dict) self._conf_params.update({ 'folder': conf_folder, 'file': conf_file, 'filename': ''.join(os.path.basename(conf_file).split('.')[:-1]), 'parser': config, 'config': conf_dict, 'gui': conf_gui }) self.file = conf_dict['grep']['file'] dir_name = os.path.dirname(self.file) if not os.path.exists(dir_name): os.makedirs(os.path.dirname(self.file)) if not os.path.isfile(self.file): with open(self.file, 'w'): pass
def __init__(self, queue, python_folder, **kwargs): ChatModule.__init__(self) log.info("Initializing twitch chat") # Reading config from main directory. conf_folder = os.path.join(python_folder, "conf") conf_file = os.path.join(conf_folder, "twitch.cfg") config = load_from_config_file(conf_file, CONF_DICT) self._conf_params.update({ 'folder': conf_folder, 'file': conf_file, 'filename': ''.join(os.path.basename(conf_file).split('.')[:-1]), 'parser': config, 'config': CONF_DICT, 'gui': CONF_GUI, 'settings': {} }) self.queue = queue self.host = CONF_DICT['config']['host'] self.port = int(CONF_DICT['config']['port']) self.channels_list = CONF_DICT['config']['channels_list'] self.bttv = CONF_DICT['config']['bttv'] self.tw_dict = {} if len(self.channels_list) == 1: if CONF_DICT['config']['show_channel_names']: CONF_DICT['config']['show_channel_names'] = False self.testing = kwargs.get('testing') if self.testing: self.testing = TestTwitch(self)
def __init__(self, conf_folder, **kwargs): MessagingModule.__init__(self) # Creating filter and replace strings. conf_file = os.path.join(conf_folder, "mentions.cfg") conf_dict = OrderedDict() conf_dict['gui_information'] = {'category': 'messaging'} conf_dict['mentions'] = [] conf_dict['address'] = [] conf_gui = { 'mentions': { 'addable': 'true', 'view': 'list'}, 'address': { 'addable': 'true', 'view': 'list'}} config = load_from_config_file(conf_file, conf_dict) self._conf_params.update( {'folder': conf_folder, 'file': conf_file, 'filename': ''.join(os.path.basename(conf_file).split('.')[:-1]), 'parser': config, 'config': conf_dict, 'gui': conf_gui})
def __init__(self, conf_folder, **kwargs): MessagingModule.__init__(self) # Creating filter and replace strings. conf_file = os.path.join(conf_folder, "c2b.cfg") conf_dict = OrderedDict() conf_dict['gui_information'] = { 'category': 'messaging', 'id': DEFAULT_PRIORITY } conf_dict['config'] = {} conf_gui = { 'config': { 'addable': 'true', 'view': 'list_dual' }, 'non_dynamic': ['config.*'] } config = load_from_config_file(conf_file, conf_dict) self._conf_params.update({ 'folder': conf_folder, 'file': conf_file, 'filename': ''.join(os.path.basename(conf_file).split('.')[:-1]), 'parser': config, 'id': conf_dict['gui_information']['id'], 'config': conf_dict, 'gui': conf_gui })
def load_modules(self, main_config, settings): log.info("Loading configuration file for messaging") modules_list = OrderedDict() conf_file = os.path.join(main_config['conf_folder'], "messaging_modules.cfg") conf_dict = OrderedDict() conf_dict['gui_information'] = {'category': 'messaging'} conf_dict['messaging'] = {'webchat': None} conf_gui = { 'messaging': { 'check': 'modules/messaging', 'check_type': 'files', 'file_extension': False, 'view': 'choose_multiple', 'description': True }, 'non_dynamic': ['messaging.*'] } config = load_from_config_file(conf_file, conf_dict) messaging_module = BaseModule( conf_params={ 'folder': main_config['conf_folder'], 'file': conf_file, 'filename': ''.join( os.path.basename(conf_file).split('.')[:-1]), 'parser': config, 'config': conf_dict, 'gui': conf_gui }) modules_list['messaging'] = messaging_module.conf_params() modules = {} # Loading modules from cfg. if len(conf_dict['messaging']) > 0: for m_module in conf_dict['messaging']: log.info("Loading %s" % m_module) # We load the module, and then we initalize it. # When writing your modules you should have class with the # same name as module name join_path = [ main_config['root_folder'] ] + self.module_tag.split('.') + ['{0}.py'.format(m_module)] file_path = os.path.join(*join_path) try: tmp = imp.load_source(m_module, file_path) class_init = getattr(tmp, m_module) class_module = class_init( main_config['conf_folder'], root_folder=main_config['root_folder'], main_settings=settings, conf_file=os.path.join(CONF_FOLDER, '{0}.cfg'.format(m_module))) params = class_module.conf_params() if 'id' in params: priority = params['id'] else: priority = MODULE_PRI_DEFAULT if int(priority) in modules: modules[int(priority)].append(class_module) else: modules[int(priority)] = [class_module] modules_list[m_module] = params except ModuleLoadException: log.error("Unable to load module {0}".format(m_module)) sorted_module = sorted(modules.items(), key=operator.itemgetter(0)) for sorted_priority, sorted_list in sorted_module: for sorted_list_item in sorted_list: self.modules.append(sorted_list_item) return modules_list
def __init__(self, conf_folder, **kwargs): MessagingModule.__init__(self) # Module configuration conf_file = os.path.join(conf_folder, "webchat.cfg") conf_dict = OrderedDict() conf_dict['gui_information'] = { 'category': 'main', 'id': DEFAULT_PRIORITY } conf_dict['server'] = OrderedDict() conf_dict['server']['host'] = '127.0.0.1' conf_dict['server']['port'] = '8080' conf_dict['style_gui'] = DEFAULT_STYLE conf_dict['style_gui_settings'] = OrderedDict() conf_dict['style'] = DEFAULT_STYLE conf_dict['style_settings'] = OrderedDict() conf_dict['style_settings']['show_system_msg'] = True conf_gui = { 'style_gui': { 'check': 'http', 'check_type': 'dir', 'view': 'choose_single' }, 'style_gui_settings': {}, 'style': { 'check': 'http', 'check_type': 'dir', 'view': 'choose_single' }, 'style_settings': {}, 'non_dynamic': ['server.*'], 'ignored_sections': ['style_settings', 'style_gui_settings'], 'redraw': { 'style_settings': { 'redraw_trigger': ['style'], 'type': 'chat', 'get_config': self.load_style_settings, 'get_gui': self.get_style_gui_from_file }, 'style_gui_settings': { 'redraw_trigger': ['style_gui'], 'type': 'gui', 'get_config': self.load_style_settings, 'get_gui': self.get_style_gui_from_file }, } } parser = load_from_config_file(conf_file, conf_dict) self._conf_params.update({ 'folder': conf_folder, 'file': conf_file, 'filename': ''.join(os.path.basename(conf_file).split('.')[:-1]), 'parser': parser, 'id': conf_dict['gui_information']['id'], 'config': conf_dict, 'gui': conf_gui, 'host': conf_dict['server']['host'], 'port': conf_dict['server']['port'], 'style_settings': { 'gui': { 'style_name': None, 'location': None, 'keys': {} }, 'chat': { 'style_name': None, 'location': None, 'keys': {} } } }) self.prepare_style_settings() self.s_thread = None self.queue = None self.message_threads = [] # Rest Api Settings self.rest_add('GET', 'style', self.rest_get_style_settings) self.rest_add('GET', 'style_gui', self.rest_get_style_settings) self.rest_add('GET', 'history', self.rest_get_history) self.rest_add('DELETE', 'chat', self.rest_delete_history)
def load_modules(self, main_config, settings): log.info("Loading configuration file for messaging") modules_list = OrderedDict() conf_file = os.path.join(main_config['conf_folder'], "messaging_modules.cfg") conf_dict = LCPanel() conf_dict['gui_information'] = {'category': 'messaging'} conf_dict['messaging'] = LCChooseMultiple(['webchat'], check_type='files', folder='modules/messaging', keep_extension=False, description=True) conf_gui = {'non_dynamic': ['messaging.*']} config = load_from_config_file(conf_file, conf_dict) messaging_module = BaseModule(conf_params={ 'folder': main_config['conf_folder'], 'file': conf_file, 'filename': ''.join(os.path.basename(conf_file).split('.')[:-1]), 'parser': config, 'config': conf_dict, 'gui': conf_gui }, conf_file_name='messaging_modules.cfg', category='messaging') modules_list['messaging'] = messaging_module.conf_params() modules = {} # Loading modules from cfg. if len(conf_dict['messaging'].value) > 0: for m_module_name in conf_dict['messaging'].value: log.info("Loading %s" % m_module_name) # We load the module, and then we initalize it. # When writing your modules you should have class with the # same name as module name join_path = [main_config['root_folder'] ] + self.module_tag.split('.') + [ '{0}.py'.format(m_module_name) ] file_path = os.path.join(*join_path) try: class_init = get_class_from_iname(file_path, m_module_name) class_module = class_init( main_config['conf_folder'], root_folder=main_config['root_folder'], main_settings=settings, conf_file=os.path.join( CONF_FOLDER, '{0}.cfg'.format(m_module_name)), queue=self.queue) params = class_module.conf_params() priority = class_module.load_priority if int(priority) in modules: modules[int(priority)].append(class_module) else: modules[int(priority)] = [class_module] modules_list[m_module_name.lower()] = params except ModuleLoadException: log.error( "Unable to load module {0}".format(m_module_name)) sorted_module = sorted(modules.items(), key=operator.itemgetter(0)) for sorted_priority, sorted_list in sorted_module: for sorted_list_item in sorted_list: self.modules.append(sorted_list_item) return modules_list
def __init__(self, conf_folder, **kwargs): MessagingModule.__init__(self) conf_file = os.path.join(conf_folder, "levels.cfg") conf_dict = OrderedDict() conf_dict['gui_information'] = {'category': 'messaging'} conf_dict['config'] = OrderedDict() conf_dict['config']['message'] = u'{0} has leveled up, now he is {1}' conf_dict['config']['db'] = os.path.join('conf', u'levels.db') conf_dict['config']['experience'] = u'geometrical' conf_dict['config']['exp_for_level'] = 200 conf_dict['config']['exp_for_message'] = 1 conf_dict['config']['decrease_window'] = 60 conf_gui = { 'non_dynamic': [ 'config.db', 'config.experience', 'config.exp_for_level', 'config.exp_for_message', 'decrease_window' ], 'config': { 'experience': { 'view': 'dropdown', 'choices': ['static', 'geometrical', 'random'] }, 'exp_for_level': { 'view': 'spin', 'min': 0, 'max': 100000 }, 'exp_for_message': { 'view': 'spin', 'min': 0, 'max': 100000 }, 'decrease_window': { 'view': 'spin', 'min': 0, 'max': 100000 } } } config = load_from_config_file(conf_file, conf_dict) self._conf_params.update({ 'folder': conf_folder, 'file': conf_file, 'filename': ''.join(os.path.basename(conf_file).split('.')[:-1]), 'parser': config, 'config': conf_dict, 'gui': conf_gui }) self.conf_folder = None self.experience = None self.exp_for_level = None self.exp_for_message = None self.level_file = None self.levels = None self.special_levels = None self.db_location = None self.decrease_window = None self.threshold_users = None
def init(): def close(): for l_module, l_module_dict in loaded_modules.iteritems(): l_module_dict['class'].apply_settings(system_exit=True) if window: window.gui.on_close('Closing Program from console') else: os._exit(0) # For system compatibility, loading chats loaded_modules = OrderedDict() gui_settings = {} window = None # Creating dict with folder settings main_config = { 'root_folder': PYTHON_FOLDER, 'conf_folder': CONF_FOLDER, 'main_conf_file': MAIN_CONF_FILE, 'main_conf_file_loc': MAIN_CONF_FILE, 'main_conf_file_name': ''.join(os.path.basename(MAIN_CONF_FILE).split('.')[:-1]), 'update': False } if not os.path.isdir(MODULE_FOLDER): logging.error( "Was not able to find modules folder, check you installation") exit() # Trying to load config file. # Create folder if doesn't exist if not os.path.isdir(CONF_FOLDER): log.error("Could not find %s folder", CONF_FOLDER) try: os.mkdir(CONF_FOLDER) except Exception as exc: log.debug("Exception: %s", exc) log.error("Was unable to create %s folder.", CONF_FOLDER) exit() log.info("Loading basic configuration") main_config_dict = OrderedDict() main_config_dict['gui_information'] = OrderedDict() main_config_dict['gui_information']['category'] = 'main' main_config_dict['gui_information']['width'] = '450' main_config_dict['gui_information']['height'] = '500' main_config_dict['system'] = OrderedDict() main_config_dict['system']['log_level'] = 'INFO' main_config_dict['system']['testing_mode'] = False main_config_dict['gui'] = OrderedDict() main_config_dict['gui']['cli'] = False main_config_dict['gui']['show_icons'] = False main_config_dict['gui']['show_hidden'] = False main_config_dict['gui']['gui'] = True main_config_dict['gui']['on_top'] = True main_config_dict['gui']['show_browser'] = True main_config_dict['gui']['show_counters'] = True main_config_dict['gui']['reload'] = None main_config_dict['language'] = get_language() main_config_gui = { 'language': { 'view': 'choose_single', 'check_type': 'dir', 'check': 'translations' }, 'system': { 'hidden': ['log_level', 'testing_mode'], }, 'gui': { 'hidden': ['cli'] }, 'ignored_sections': ['gui.reload'], 'non_dynamic': ['language.list_box', 'gui.*', 'system.*'] } config = load_from_config_file(MAIN_CONF_FILE, main_config_dict) root_logger.setLevel(level=logging.getLevelName( main_config_dict['system'].get('log_level', 'INFO'))) # Adding config for main module main_class = BaseModule( conf_params={ 'folder': CONF_FOLDER, 'file': main_config['main_conf_file_loc'], 'filename': main_config['main_conf_file_name'], 'parser': config, 'root_folder': main_config['root_folder'], 'logs_folder': LOG_FOLDER, 'config': main_config_dict, 'gui': main_config_gui }) loaded_modules['main'] = main_class.conf_params() gui_settings['gui'] = main_config_dict[GUI_TAG].get('gui') gui_settings['on_top'] = main_config_dict[GUI_TAG].get('on_top') gui_settings['language'] = main_config_dict.get('language') gui_settings['show_hidden'] = main_config_dict[GUI_TAG].get('show_hidden') gui_settings['size'] = ( int(main_config_dict['gui_information'].get('width')), int(main_config_dict['gui_information'].get('height'))) gui_settings['show_browser'] = main_config_dict['gui'].get('show_browser') # Checking updates log.info("Checking for updates") loaded_modules['main']['update'], loaded_modules['main'][ 'update_url'] = get_update(SEM_VERSION) if loaded_modules['main']['update']: log.info("There is new update, please update!") # Starting modules log.info("Loading Messaging Handler") log.info("Loading Queue for message handling") try: load_translations_keys(TRANSLATION_FOLDER, gui_settings['language']) except Exception as exc: log.debug("Exception: %s", exc) log.exception("Failed loading translations") # Creating queues for messaging transfer between chat threads queue = Queue.Queue() # Loading module for message processing... msg = messaging.Message(queue) loaded_modules.update(msg.load_modules(main_config, loaded_modules['main'])) msg.start() log.info("Loading Chats") # Trying to dynamically load chats that are in config file. chat_modules = os.path.join(CONF_FOLDER, "chat_modules.cfg") chat_location = os.path.join(MODULE_FOLDER, "chat") chat_conf_dict = OrderedDict() chat_conf_dict['gui_information'] = {'category': 'chat'} chat_conf_dict['chats'] = [] chat_conf_gui = { 'chats': { 'view': 'choose_multiple', 'check_type': 'files', 'check': os.path.sep.join(['modules', 'chat']), 'file_extension': False }, 'non_dynamic': ['chats.list_box'] } chat_config = load_from_config_file(chat_modules, chat_conf_dict) chat_module = BaseModule( conf_params={ 'folder': CONF_FOLDER, 'file': chat_modules, 'filename': ''.join( os.path.basename(chat_modules).split('.')[:-1]), 'parser': chat_config, 'config': chat_conf_dict, 'gui': chat_conf_gui }) loaded_modules['chat'] = chat_module.conf_params() for chat_module in chat_conf_dict['chats']: log.info("Loading chat module: {0}".format(chat_module)) module_location = os.path.join(chat_location, chat_module + ".py") if os.path.isfile(module_location): log.info("found {0}".format(chat_module)) # After module is find, we are initializing it. # Class should be named as in config # Also passing core folder to module so it can load it's own # configuration correctly tmp = imp.load_source(chat_module, module_location) chat_init = getattr(tmp, chat_module) class_module = chat_init( queue, PYTHON_FOLDER, conf_folder=CONF_FOLDER, conf_file=os.path.join(CONF_FOLDER, '{0}.cfg'.format(chat_module)), testing=main_config_dict['system']['testing_mode']) loaded_modules[chat_module] = class_module.conf_params() else: log.error("Unable to find {0} module") # Actually loading modules for f_module, f_config in loaded_modules.iteritems(): if 'class' in f_config: try: f_config['class'].load_module(main_settings=main_config, loaded_modules=loaded_modules, queue=queue) log.debug('loaded module {}'.format(f_module)) except ModuleLoadException: msg.modules.remove(loaded_modules[f_module]['class']) loaded_modules.pop(f_module) log.info('LalkaChat loaded successfully') if gui_settings['gui']: import gui log.info("Loading GUI Interface") window = gui.GuiThread(gui_settings=gui_settings, main_config=loaded_modules['main'], loaded_modules=loaded_modules, queue=queue) loaded_modules['gui'] = window.conf_params() window.start() if main_config_dict['gui']['cli']: try: while True: console = raw_input("> ") log.info(console) if console == "exit": log.info("Exiting now!") close() else: log.info("Incorrect Command") except (KeyboardInterrupt, SystemExit): log.info("Exiting now") close() except Exception as exc: log.info(exc) else: try: while True: sleep(1) except (KeyboardInterrupt, SystemExit): log.info("Exiting now") close()