Exemplo n.º 1
0
    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 = self_heal(conf_file, conf_dict)
        self._conf_params = {'folder': conf_folder, 'file': conf_file,
                             'filename': ''.join(os.path.basename(conf_file).split('.')[:-1]),
                             'parser': config,
                             'id': config.get('gui_information', 'id'),
                             'config': conf_dict,
                             'gui': conf_gui}

        tag_config = 'config'
        self.f_items = []
        for param, value in config.items(tag_config):
            f_item = {'filter': param.decode('utf-8'), 'replace': value.split('/')}
            f_item['replace'] = [item.strip().decode('utf-8') for item in f_item['replace']]
            self.f_items.append(f_item)
Exemplo n.º 2
0
    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'},
            'non_dynamic': ['mentions.*', 'address.*']}
        config = self_heal(conf_file, conf_dict)
        self._conf_params = {'folder': conf_folder, 'file': conf_file,
                             'filename': ''.join(os.path.basename(conf_file).split('.')[:-1]),
                             'parser': config,
                             'config': conf_dict,
                             'gui': conf_gui}
        mention_tag = 'mentions'
        address_tag = 'address'
        if config.has_section(mention_tag):
            self.mentions = [item for item, value in config.items(mention_tag)]
        else:
            self.mentions = []

        if config.has_section(address_tag):
            self.addresses = [item.decode('utf-8').lower() for item, value in config.items(address_tag)]
        else:
            self.addresses = []
Exemplo n.º 3
0
    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 = self_heal(conf_file, conf_dict)
        modules_list['messaging'] = {'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 = {}
        # Loading modules from cfg.
        if config.items("messaging") > 0:
            for module, item in config.items("messaging"):
                log.info("Loading %s" % 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(module)]
                file_path = os.path.join(*join_path)

                try:
                    tmp = imp.load_source(module, file_path)
                    class_init = getattr(tmp, module)
                    class_module = class_init(main_config['conf_folder'], root_folder=main_config['root_folder'],
                                              main_settings=settings)

                    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[module] = params
                except ModuleLoadException as exc:
                    log.error("Unable to load module {0}".format(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
Exemplo n.º 4
0
    def __init__(self, conf_folder, **kwargs):
        MessagingModule.__init__(self)
        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'] = 'czt'
        conf_dict['style_settings'] = {'font_size': 15}
        conf_gui = {
            'style': {
                'check': 'http',
                'check_type': 'dir',
                'view': 'choose_single'
            },
            'style_settings': {
                'font_size': {
                    'view': 'spin',
                    'min': 10,
                    'max': 100
                }
            },
            'non_dynamic': ['server.*']
        }

        config = self_heal(conf_file, conf_dict)

        fallback_style = 'czt'
        path = os.path.abspath(os.path.join(HTTP_FOLDER, conf_dict['style']))
        if os.path.exists(path):
            style_location = path
        else:
            style_location = os.path.join(HTTP_FOLDER, fallback_style)

        self._conf_params = {
            'folder': conf_folder,
            'file': conf_file,
            'filename': ''.join(os.path.basename(conf_file).split('.')[:-1]),
            'parser': config,
            'id': config.get('gui_information', 'id'),
            'config': conf_dict,
            'gui': conf_gui,
            'host': conf_dict['server']['host'],
            'port': conf_dict['server']['port'],
            'style_location': style_location
        }
        self.queue = None
        self.message_threads = []
Exemplo n.º 5
0
    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': u'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 = self_heal(conf_file, conf_dict)
        self._conf_params = {'folder': conf_folder, 'file': conf_file,
                             'filename': ''.join(os.path.basename(conf_file).split('.')[:-1]),
                             'parser': config,
                             'id': config.get('gui_information', 'id'),
                             'config': OrderedDict(conf_dict),
                             'gui': conf_gui}

        for item in config.sections():
            for param, value in config.items(item):
                if item == 'main':
                    if param == 'message':
                        self.message = value.decode('utf-8')
                elif item == 'users_hide':
                    self.users[param] = 'h'
                elif item == 'words_hide':
                    self.words[param] = 'h'
                elif item == 'users_block':
                    self.users[param] = 'b'
                elif item == 'words_block':
                    self.words[param] = 'b'
Exemplo n.º 6
0
    def __init__(self, queue, python_folder, **kwargs):
        ChatModule.__init__(self)
        # Reading config from main directory.
        conf_folder = os.path.join(python_folder, "conf")

        log.info("Initializing goodgame chat")
        conf_file = os.path.join(conf_folder, "goodgame.cfg")
        config = self_heal(conf_file, CONF_DICT)
        self._conf_params = {'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.host = CONF_DICT['config']['socket']
        self.channel_name = CONF_DICT['config']['channel_name']
Exemplo n.º 7
0
    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'] = {'nothing': '([Нн]икто|[Nn]othing|\w*)'}

        conf_gui = {
            'prof': {
                'view': 'list_dual',
                'addable': True
            },
            'non_dynamic': ['grep.*']
        }
        config = self_heal(conf_file, conf_dict)
        grep_tag = 'grep'
        prof_tag = 'prof'

        self._conf_params = {
            'folder': conf_folder,
            'file': conf_file,
            'filename': ''.join(os.path.basename(conf_file).split('.')[:-1]),
            'parser': config,
            'config': conf_dict,
            'gui': conf_gui
        }
        self.symbol = config.get(grep_tag, 'symbol')
        self.file = config.get(grep_tag, '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

        self.prof = []
        for prof, regex in config.items(prof_tag):
            comp = [prof.capitalize(), self.symbol + regex.decode('utf-8')]
            self.prof.append(comp)
Exemplo n.º 8
0
    def __init__(self, conf_folder, **kwargs):
        MessagingModule.__init__(self)
        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'] = 'czt'
        conf_dict['style_settings'] = {
            'font_size': 15
        }
        conf_gui = {
            'style': {
                'check': 'http',
                'check_type': 'dir',
                'view': 'choose_single'},
            'style_settings': {
                'font_size': {'view': 'spin',
                              'min': 10,
                              'max': 100}},
            'non_dynamic': ['server.*']}

        config = self_heal(conf_file, conf_dict)

        fallback_style = 'czt'
        path = os.path.abspath(os.path.join(HTTP_FOLDER, conf_dict['style']))
        if os.path.exists(path):
            style_location = path
        else:
            style_location = os.path.join(HTTP_FOLDER, fallback_style)

        self._conf_params = {'folder': conf_folder, 'file': conf_file,
                             'filename': ''.join(os.path.basename(conf_file).split('.')[:-1]),
                             'parser': config,
                             'id': config.get('gui_information', 'id'),
                             'config': conf_dict,
                             'gui': conf_gui,
                             'host': conf_dict['server']['host'],
                             'port': conf_dict['server']['port'],
                             'style_location': style_location}
        self.queue = None
        self.message_threads = []
Exemplo n.º 9
0
    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.*'],
            'config': {
                'experience': {
                    'view': 'dropdown',
                    'choices': ['static', 'geometrical', 'random']
                }
            }
        }
        config = self_heal(conf_file, conf_dict)

        self._conf_params = {
            '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.filename = None
        self.levels = None
        self.special_levels = None
        self.db_location = None
        self.message = None
        self.decrease_window = None
        self.threshold_users = None
Exemplo n.º 10
0
    def __init__(self, queue, python_folder, **kwargs):
        ChatModule.__init__(self)
        # Reading config from main directory.
        conf_folder = os.path.join(python_folder, "conf")

        log.info("Initializing goodgame chat")
        conf_file = os.path.join(conf_folder, "goodgame.cfg")
        config = self_heal(conf_file, CONF_DICT)
        self._conf_params = {
            '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.host = CONF_DICT['config']['socket']
        self.channel_name = CONF_DICT['config']['channel_name']
Exemplo n.º 11
0
    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'
            },
            'non_dynamic': ['mentions.*', 'address.*']
        }
        config = self_heal(conf_file, conf_dict)
        self._conf_params = {
            'folder': conf_folder,
            'file': conf_file,
            'filename': ''.join(os.path.basename(conf_file).split('.')[:-1]),
            'parser': config,
            'config': conf_dict,
            'gui': conf_gui
        }
        mention_tag = 'mentions'
        address_tag = 'address'
        if config.has_section(mention_tag):
            self.mentions = [item for item, value in config.items(mention_tag)]
        else:
            self.mentions = []

        if config.has_section(address_tag):
            self.addresses = [
                item.decode('utf-8').lower()
                for item, value in config.items(address_tag)
            ]
        else:
            self.addresses = []
Exemplo n.º 12
0
    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'] = {'nothing': '([Нн]икто|[Nn]othing|\w*)'}

        conf_gui = {
            'prof': {
                'view': 'list_dual',
                'addable': True},
            'non_dynamic': ['grep.*']}
        config = self_heal(conf_file, conf_dict)
        grep_tag = 'grep'
        prof_tag = 'prof'

        self._conf_params = {'folder': conf_folder, 'file': conf_file,
                             'filename': ''.join(os.path.basename(conf_file).split('.')[:-1]),
                             'parser': config,
                             'config': conf_dict,
                             'gui': conf_gui}
        self.symbol = config.get(grep_tag, 'symbol')
        self.file = config.get(grep_tag, '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

        self.prof = []
        for prof, regex in config.items(prof_tag):
            comp = [prof.capitalize(), self.symbol + regex.decode('utf-8')]
            self.prof.append(comp)
Exemplo n.º 13
0
    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 = self_heal(conf_file, conf_dict)
        self._conf_params = {
            'folder': conf_folder,
            'file': conf_file,
            'filename': ''.join(os.path.basename(conf_file).split('.')[:-1]),
            'parser': config,
            'id': config.get('gui_information', 'id'),
            'config': conf_dict,
            'gui': conf_gui
        }

        tag_config = 'config'
        self.f_items = []
        for param, value in config.items(tag_config):
            f_item = {
                'filter': param.decode('utf-8'),
                'replace': value.split('/')
            }
            f_item['replace'] = [
                item.strip().decode('utf-8') for item in f_item['replace']
            ]
            self.f_items.append(f_item)
Exemplo n.º 14
0
    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 = self_heal(conf_file, conf_dict)
        self._conf_params = {
            'folder': conf_folder,
            'file': conf_file,
            'filename': ''.join(os.path.basename(conf_file).split('.')[:-1]),
            'parser': config,
            'id': config.get('gui_information', 'id'),
            'config': conf_dict,
            'gui': conf_gui
        }

        tag_config = 'config'

        self.format = config.get(tag_config, 'file_format')
        self.ts_format = config.get(tag_config, 'message_date_format')
        self.logging = config.get(tag_config, 'logging')
        self.rotation = config.get(tag_config, 'logging')

        self.folder = 'logs'

        self.destination = os.path.join(conf_folder, '..', self.folder)
        if not os.path.exists(self.destination):
            os.makedirs(self.destination)
Exemplo n.º 15
0
    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.*'],
                    'config': {
                        'experience': {
                            'view': 'dropdown',
                            'choices': ['static', 'geometrical', 'random']}}}
        config = self_heal(conf_file, conf_dict)

        self._conf_params = {'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.filename = None
        self.levels = None
        self.special_levels = None
        self.db_location = None
        self.message = None
        self.decrease_window = None
        self.threshold_users = None
Exemplo n.º 16
0
    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 = self_heal(conf_file, conf_dict)
        self._conf_params = {'folder': conf_folder, 'file': conf_file,
                             'filename': ''.join(os.path.basename(conf_file).split('.')[:-1]),
                             'parser': config,
                             'id': config.get('gui_information', 'id'),
                             'config': conf_dict,
                             'gui': conf_gui}

        tag_config = 'config'

        self.format = config.get(tag_config, 'file_format')
        self.ts_format = config.get(tag_config, 'message_date_format')
        self.logging = config.get(tag_config, 'logging')
        self.rotation = config.get(tag_config, 'logging')

        self.folder = 'logs'

        self.destination = os.path.join(conf_folder, '..', self.folder)
        if not os.path.exists(self.destination):
            os.makedirs(self.destination)
Exemplo n.º 17
0
def init():
    def close():
        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 {0} folder".format(CONF_FOLDER))
        try:
            os.mkdir(CONF_FOLDER)
        except:
            log.error("Was unable to create {0} folder.".format(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['gui'] = OrderedDict()
    main_config_dict['gui']['show_hidden'] = False
    main_config_dict['gui']['gui'] = True
    main_config_dict['gui']['on_top'] = 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'
        },
        'non_dynamic': ['language.list_box', 'gui.*']
    }
    config = self_heal(MAIN_CONF_FILE, main_config_dict)
    # Adding config for main module
    loaded_modules['main'] = {
        '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
    }

    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'] = (main_config_dict['gui_information'].get('width'),
                            main_config_dict['gui_information'].get('height'))

    # Checking updates
    log.info("Checking for updates")
    loaded_modules['main']['update'], loaded_modules['main'][
        'update_url'] = get_update()
    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")

    # 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_tag = "chats"
    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 = self_heal(chat_modules, chat_conf_dict)
    loaded_modules['chat'] = {
        '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
    }

    for module, settings in chat_config.items(chat_tag):
        log.info("Loading chat module: {0}".format(module))
        module_location = os.path.join(chat_location, module + ".py")
        if os.path.isfile(module_location):
            log.info("found {0}".format(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(module, module_location)
            chat_init = getattr(tmp, module)
            class_module = chat_init(queue, PYTHON_FOLDER)
            loaded_modules[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:
            f_config['class'].load_module(main_settings=main_config,
                                          loaded_modules=loaded_modules,
                                          queue=queue)
    try:
        load_translations_keys(TRANSLATION_FOLDER, gui_settings['language'])
    except:
        log.exception("Failed loading translations")

    if gui_settings['gui']:
        log.info("Loading GUI Interface")
        window = gui.GuiThread(gui_settings=gui_settings,
                               main_config=loaded_modules['main'],
                               loaded_modules=loaded_modules,
                               queue=queue)
        window.start()
    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)
Exemplo n.º 18
0
    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 = self_heal(conf_file, conf_dict)
        modules_list['messaging'] = {
            '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 = {}
        # Loading modules from cfg.
        if config.items("messaging") > 0:
            for module, item in config.items("messaging"):
                log.info("Loading %s" % 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(module)]
                file_path = os.path.join(*join_path)

                try:
                    tmp = imp.load_source(module, file_path)
                    class_init = getattr(tmp, module)
                    class_module = class_init(
                        main_config['conf_folder'],
                        root_folder=main_config['root_folder'],
                        main_settings=settings)

                    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[module] = params
                except ModuleLoadException as exc:
                    log.error("Unable to load module {0}".format(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
Exemplo n.º 19
0
def init():
    def close():
        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 {0} folder".format(CONF_FOLDER))
        try:
            os.mkdir(CONF_FOLDER)
        except:
            log.error("Was unable to create {0} folder.".format(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['gui'] = OrderedDict()
    main_config_dict['gui']['show_hidden'] = False
    main_config_dict['gui']['gui'] = True
    main_config_dict['gui']['on_top'] = 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'
        },
        'non_dynamic': ['language.list_box', 'gui.*']
    }
    config = self_heal(MAIN_CONF_FILE, main_config_dict)
    # Adding config for main module
    loaded_modules['main'] = {'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}

    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'] = (main_config_dict['gui_information'].get('width'),
                            main_config_dict['gui_information'].get('height'))

    # Checking updates
    log.info("Checking for updates")
    loaded_modules['main']['update'], loaded_modules['main']['update_url'] = get_update()
    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")

    # 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_tag = "chats"
    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 = self_heal(chat_modules, chat_conf_dict)
    loaded_modules['chat'] = {'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}

    for module, settings in chat_config.items(chat_tag):
        log.info("Loading chat module: {0}".format(module))
        module_location = os.path.join(chat_location, module + ".py")
        if os.path.isfile(module_location):
            log.info("found {0}".format(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(module, module_location)
            chat_init = getattr(tmp, module)
            class_module = chat_init(queue, PYTHON_FOLDER)
            loaded_modules[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:
            f_config['class'].load_module(main_settings=main_config, loaded_modules=loaded_modules,
                                          queue=queue)
    try:
        load_translations_keys(TRANSLATION_FOLDER, gui_settings['language'])
    except:
        log.exception("Failed loading translations")

    if gui_settings['gui']:
        log.info("Loading GUI Interface")
        window = gui.GuiThread(gui_settings=gui_settings,
                               main_config=loaded_modules['main'],
                               loaded_modules=loaded_modules,
                               queue=queue)
        window.start()
    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)