def __init__(self):
     # init config.
     init_config()
     #
     self.key_dict = {}
     self.keywords = []
     self.config = Config(get_config_file())
     try:
         tray_path_list = self.config.get("tray", "PATH").split(",")
     except:
         tray_path_list = ["/usr/share/deepin-system-settings/modules"]
     for tray_path in tray_path_list:
         if tray_path != "":
             if os.path.exists(tray_path) and os.path.isdir(tray_path):
                     self.scan_tray_path_modules(tray_path)
class PluginManage(object):
    def __init__(self):
        # init config.
        init_config()
        #
        self.key_dict = {}
        self.keywords = []
        self.config = Config(get_config_file())
        try:
            tray_path_list = self.config.get("tray", "PATH").split(",")
        except:
            tray_path_list = ["/usr/share/deepin-system-settings/modules"]
        for tray_path in tray_path_list:
            if tray_path != "":
                if os.path.exists(tray_path) and os.path.isdir(tray_path):
                        self.scan_tray_path_modules(tray_path)

    def scan_tray_path_modules(self, scan_path):
        scan_modules_path_list = os.listdir(scan_path)
        for i in range(0, len(scan_modules_path_list)):
            self.keywords.append(None)
        # add path to sys path.
        add_sys_path(scan_path)
        #
        for modules_path in scan_modules_path_list:
            modules_path_name = os.path.join(scan_path, modules_path)
            if os.path.isdir(modules_path_name):
                modules_path_config = os.path.join(modules_path_name, "config.ini")
                if os.path.exists(modules_path_config):
                    modules_ini = Config(modules_path_config)
                    modules_info = save_modules_info(modules_ini, modules_path_name)
                    if modules_info:
                        try:
                            add_sys_path(scan_path + "/" + modules_info.id + "/src")
                            modual = __import__("%s.%s" % (modules_info.id, modules_info.include), fromlist=["keywords"])
                            class_init   = modual.return_plugin()
                            class_insert = modual.return_insert()
                            class_id     = modual.return_id()

                            class_run = class_init#()
                            if class_insert != None:
                                #self.keywords.insert(class_insert, class_run)
                                if self.keywords[class_insert] == None:
                                    self.keywords[class_insert] = class_run
                                else:
                                    self.keywords.append(class_run)

                            else:
                                self.keywords.append(class_run)
                            # class_id..
                            self.key_dict[class_id] = class_run
                            '''
                            try:
                                print_msg("load plugin[id]:%s"%(class_run.id()))
                                index = class_run.insert()
                                #self.keywords.insert(index, class_run)
                                if index != None:
                                    if self.keywords[index] == None:
                                        self.keywords[index] = class_run
                                else:
                                    self.keywords.append(class_run)
                            except:
                                self.keywords.append(class_run)
                            #
                            self.key_dict[class_run.id()] = class_run
                            '''
                        except Exception, e:
                            print "trayicon_plugin_manager ERROR:", e