def scan_plugin_info(self):
        self.engine_list = []
        self.engine_dict = {}

        for plugin_name in os.listdir(self.plugin_dir):
            plugin_config_file = os.path.join(self.plugin_dir, plugin_name,
                                              self.plugin_config_name)
            plugin_config = Config(plugin_config_file)
            plugin_config.load()

            language = get_language()
            plugin_display_name = plugin_config.get(
                "Plugin Info", "name[%s]" % language) or plugin_config.get(
                    "Plugin Info", "name[en]")

            need_network = is_true(
                plugin_config.get("Voice Info", "need_network"))
            support_all_language = is_true(
                plugin_config.get("Voice Info", "support_all_language"))
            support_languages_info = plugin_config.get("Voice Info",
                                                       "support_languages")
            priority = plugin_config.get("Voice Info", "priority")
            if support_languages_info == None:
                support_languages = []
            else:
                support_languages = support_languages_info.split(",")

            if support_all_language:
                self.engine_list.append(
                    (plugin_name, plugin_display_name, priority, need_network))
            else:
                self.update_dict(self.engine_dict, support_languages,
                                 plugin_name, plugin_display_name, priority,
                                 need_network)
def is_mirror_disabled():
    if os.path.exists(deepin_version_path):
        config = Config(deepin_version_path)
        config.load()
        return config.has_option("Custom", "Mirror") and config.get("Custom", "Mirror") == "False"
    else:
        return True # not deepin os, disable mirror change
Exemple #3
0
    def __init__(self, module_path):
        '''
        init docs
        '''
        self.path = module_path
        self.config = Config(os.path.join(self.path, "config.ini"))
        self.config.load()
        self.id = self.config.get("main", "id")
        # TODO: lihongwu req to support i18n
        self.name = MODULES_NAME_FOR_L18N.get(self.id, "")
        self.default_name = self.config.get("name", "default")
        """
        self.name = self.default_name
        if MAIN_LANG != "en_US":
            self.name = self.config.get("name", MAIN_LANG)
        """

        icon_infos = [
            self.get_system_icon_info(self.id, 48),
            self.get_system_icon_info(self.id, 16),
        ]

        self.icon_pixbuf = None
        self.menu_icon_pixbuf = None
        try:
            self.icon_pixbuf = gtk.gdk.pixbuf_new_from_file(icon_infos[0])
            self.menu_icon_pixbuf = gtk.gdk.pixbuf_new_from_file(icon_infos[1])
        except:
            self.icon_pixbuf = app_theme.get_pixbuf(
                "navigate/none-big.png").get_pixbuf()
            self.menu_icon_pixbuf = app_theme.get_pixbuf(
                "navigate/none-small.png").get_pixbuf()

        self.search_keyword = self.config.get("main", "search_keyword")
Exemple #4
0
 def __init__(self, ini_file):
     self.ini_file = ini_file
     self.config = Config(ini_file)
     self.config.load()
     deepin_url = self.get_repo_urls()[1]
     self._url_parse = urlparse(deepin_url)
     self._hostname = self._url_parse.scheme + "://" + self._url_parse.netloc
Exemple #5
0
    def __init__(self, module_config_path, argv=""):
        '''
        init docs
        '''
        # Init.
        gtk.Plug.__init__(self, 0)
        self.module_config_path = module_config_path
        self.module_config = Config(self.module_config_path)
        self.module_config.load()
        self.module_id = self.module_config.get("main", "id")
        self.argv = argv

        # WARING: only use once in one process
        DBusGMainLoop(set_as_default=True)

        # Init threads.
        if self.module_id != "bluetooth":  # Added by hualet, wonder why? go ask him :)
            gtk.gdk.threads_init()

        # Init dbus.
        self.bus = dbus.SessionBus()
        self.module_dbus_name = "com.deepin.%s_settings" % (self.module_id)
        self.module_object_name = "/com/deepin/%s_settings" % (self.module_id)
        self.module_bus_name = dbus.service.BusName(self.module_dbus_name,
                                                    bus=self.bus)

        # Handle signals.
        self.connect("realize", self.module_frame_realize)
        self.connect("destroy", self.module_frame_exit)

        glib.timeout_add(1000, self.is_exist)
    def clear_data_folder(self):
        # clear data when ui is not running

        # judge which data is in using
        if os.path.exists(DATA_CURRENT_ID_CONFIG_PATH):
            current_data_id_config = Config(DATA_CURRENT_ID_CONFIG_PATH)
            current_data_id_config.load()
            current_data_id = current_data_id_config.get("current", "data_id")
        else:
            current_data_id = None

        self.newest_data_id_config.load()
        newest_data_id = self.newest_data_id_config.get("newest", "data_id")
        data_file_list = ["newest",
                          "origin",
                          "patch",
                          "update",
                          "data_newest_id.ini",
                          "patch_status.ini",
                          "cache_soft.db",
                          "origin_data_time"
                          ]
        data_id_list = (current_data_id, newest_data_id)
        
        for data_file in os.listdir(DATA_DIR):
            if data_file not in data_file_list:
                remove_directory(os.path.join(DATA_DIR, data_file))
                print ">> remove file: %s" % data_file
                log(">> remove file: %s" % data_file)
            elif data_file == "update":
                for data_id in os.listdir(os.path.join(DATA_DIR, "update")):
                    if data_id not in data_id_list:
                        remove_directory(os.path.join(DATA_DIR, "update", data_id))
                        print '>> remove old data: %s' % data_id
                        log('>> remove old data: %s' % data_id)
def get_config_info_config():
    config_info_config = Config(CONFIG_INFO_PATH)
    if os.path.exists(CONFIG_INFO_PATH):
        config_info_config.load()
    else:
        touch_file(CONFIG_INFO_PATH)
        config_info_config.load()
    return config_info_config
def get_vpc_remind_config():
    CONFIG_INFO_PATH = os.path.expanduser("~/.config/deepin-system-settings/tray/config.ini")
    config_info_config = Config(CONFIG_INFO_PATH)
    if os.path.exists(CONFIG_INFO_PATH):
        config_info_config.load()
    else:
        touch_file(CONFIG_INFO_PATH)
        config_info_config.load()
    return config_info_config
Exemple #9
0
    def load_skin(self, skin_name, system_skin_dir=None, user_skin_dir=None):
        '''
        Internal function to Load skin.

        @return: Return True if load finish, otherwise return False.
        '''
        try:
            # Save skin dir.
            self.skin_name = skin_name

            if system_skin_dir:
                self.system_skin_dir = system_skin_dir
                create_directory(self.system_skin_dir)

            if user_skin_dir:
                self.user_skin_dir = user_skin_dir
                create_directory(self.user_skin_dir)

            self.skin_dir = self.get_skin_dir()

            # Load config file.
            self.config = Config(self.get_skin_file_path("config.ini"))
            self.config.load()

            # Get theme config.
            self.theme_name = self.config.get("theme", "theme_name")

            # Get application config.
            self.app_id = self.config.get("application", "app_id")
            self.app_version = self.config.getfloat("application", "app_version")

            # Get background config.
            self.image = self.config.get("background", "image")
            self.x = self.config.getfloat("background", "x")
            self.y = self.config.getfloat("background", "y")
            self.scale_x = self.config.getfloat("background", "scale_x")
            self.scale_y = self.config.getfloat("background", "scale_y")
            self.dominant_color = self.config.get("background", "dominant_color")

            # Get action config.
            self.deletable = self.config.getboolean("action", "deletable")
            self.editable = self.config.getboolean("action", "editable")
            self.vertical_mirror = self.config.getboolean("action", "vertical_mirror")
            self.horizontal_mirror = self.config.getboolean("action", "horizontal_mirror")

            # Generate background pixbuf.
            self.background_pixbuf = gtk.gdk.pixbuf_new_from_file(self.get_skin_file_path(self.image))

            # Save skin name.
            self.save_skin_name()

            return True
        except Exception, e:
            print "function load_skin got error: %s" % (e)
            traceback.print_exc(file=sys.stdout)

            return False
Exemple #10
0
 def __init__(self):
     QObject.__init__(self)
     self.config_file = get_config_file("config.ini")
     
     if os.path.exists(self.config_file):
         self.config = Config(self.config_file, DEFAULT_CONFIG)
         self.config.load()
     else:
         self.config = Config(self.config_file, DEFAULT_CONFIG)
         self.config.write()
Exemple #11
0
    def __init__(self):
        QObject.__init__(self)
        self.config_file = get_config_file("config.ini")

        if os.path.exists(self.config_file):
            self.config = Config(self.config_file, DEFAULT_CONFIG)
            self.config.load()
        else:
            self.config = Config(self.config_file, DEFAULT_CONFIG)
            self.config.write()
class Mirror(object):
    def __init__(self, ini_file):
        self.config = Config(ini_file)
        self.config.load()
        deepin_url = self.get_repo_urls()[1]
        _url_parse = urlparse(deepin_url)
        self._hostname = _url_parse.scheme + "://" + _url_parse.netloc
        self._priority = int(self.config.get("mirror", "priority")) if self.config.has_option("mirror", "priority") else 100
    
    @property
    def hostname(self):
        return self._hostname

    @property
    def name(self):
        if self.config.has_option('mirror', 'name[%s]' % LANGUAGE):
            return self.config.get('mirror', 'name[%s]' % LANGUAGE)
        else:
            return self.config.get('mirror', 'name[%s]' % 'en_US')

    @property
    def priority(self):
        return self._priority

    def get_repo_urls(self):
        return (self.config.get('mirror', 'ubuntu_url'), self.config.get('mirror', 'deepin_url'))
 def is_fontend_running(self):
     if os.path.exists(DATA_CURRENT_ID_CONFIG_PATH):
         config = Config(DATA_CURRENT_ID_CONFIG_PATH)
         config.load()
         data_id = config.get('current', 'data_id')
         if data_id:
             return True
         else:
             return False
     else:
         False
Exemple #14
0
    def __init__(self,
                 config_file,
                 default_config=None):
        '''
        Init config module.

        @param config_file: Config filepath.
        @param default_config: Default config value use when config file is empty.
        '''
        print "Please import deepin_utils.config instead dtk.ui.config, this module will remove in next version."
        DConfig.__init__(self, config_file, default_config)
Exemple #15
0
 def is_fontend_running(self):
     if os.path.exists(DATA_CURRENT_ID_CONFIG_PATH):
         config = Config(DATA_CURRENT_ID_CONFIG_PATH)
         config.load()
         data_id = config.get('current', 'data_id')
         if data_id:
             return True
         else:
             return False
     else:
         False
Exemple #16
0
 def save_skin_name(self):
     '''
     Internal function to save skin name.
     '''
     skin_config = Config(self.skin_config_file)
     skin_config.load()
     if skin_config.get("skin", "skin_name") != self.skin_name:
         skin_config.set("skin", "skin_name", self.skin_name)
         skin_config.write(self.skin_config_file)
 def scan_plugin_info(self):
     self.engine_list = []
     self.engine_dict = {}
     
     for plugin_name in os.listdir(self.plugin_dir):
         plugin_config_file = os.path.join(self.plugin_dir, plugin_name, self.plugin_config_name)
         plugin_config = Config(plugin_config_file)
         plugin_config.load()
         
         language = get_language()
         plugin_display_name = plugin_config.get("Plugin Info", "name[%s]" % language) or plugin_config.get("Plugin Info", "name[en]")
         
         need_network = is_true(plugin_config.get("Voice Info", "need_network"))
         support_all_language = is_true(plugin_config.get("Voice Info", "support_all_language"))
         support_languages_info = plugin_config.get("Voice Info", "support_languages")
         priority = plugin_config.get("Voice Info", "priority")
         if support_languages_info == None:
             support_languages = []
         else:
             support_languages = support_languages_info.split(",")
             
         if support_all_language:
             self.engine_list.append((plugin_name, plugin_display_name, priority, need_network))
         else:
             self.update_dict(self.engine_dict, support_languages, plugin_name, plugin_display_name, priority, need_network)
Exemple #18
0
class ModuleInfo(object):
    '''
    class docs
    '''
    def __init__(self, module_path):
        '''
        init docs
        '''
        self.path = module_path
        self.config = Config(os.path.join(self.path, "config.ini"))
        self.config.load()
        self.id = self.config.get("main", "id")
        # TODO: lihongwu req to support i18n
        self.name = MODULES_NAME_FOR_L18N.get(self.id, "")
        self.default_name = self.config.get("name", "default")
        """
        self.name = self.default_name
        if MAIN_LANG != "en_US":
            self.name = self.config.get("name", MAIN_LANG)
        """

        icon_infos = [
            self.get_system_icon_info(self.id, 48),
            self.get_system_icon_info(self.id, 16),
        ]

        self.icon_pixbuf = None
        self.menu_icon_pixbuf = None
        try:
            self.icon_pixbuf = gtk.gdk.pixbuf_new_from_file(icon_infos[0])
            self.menu_icon_pixbuf = gtk.gdk.pixbuf_new_from_file(icon_infos[1])
        except:
            self.icon_pixbuf = app_theme.get_pixbuf(
                "navigate/none-big.png").get_pixbuf()
            self.menu_icon_pixbuf = app_theme.get_pixbuf(
                "navigate/none-small.png").get_pixbuf()

        self.search_keyword = self.config.get("main", "search_keyword")

    def get_system_icon_info(self, icon_id, icon_size):
        '''
        NOTE: Because dtk.ui.utils.get_system_icon_info need take 20ms every call,
        it will slow down start speed of deepin system settings.
        
        So i return path directly to solve start speed problem.
        '''
        return "/usr/share/icons/Deepin/apps/%s/preferences-%s.png" % (
            icon_size, icon_id)
class Mirror(object):
    def __init__(self, ini_file):
        self.ini_file = ini_file
        self.config = Config(ini_file)
        self.config.load()
        deepin_url = self.get_repo_urls()[1]
        self._url_parse = urlparse(deepin_url)
        self._hostname = self._url_parse.scheme + "://" + self._url_parse.netloc
    
    @property
    def host(self):
        return self._url_parse.netloc

    @property
    def hostname(self):
        return self._hostname
    def __init__(self, module_path):
        '''
        init docs
        '''
        self.path = module_path
        self.config = Config(os.path.join(self.path, "config.ini"))
        self.config.load()
        self.id = self.config.get("main", "id")
        # TODO: lihongwu req to support i18n
        self.name = MODULES_NAME_FOR_L18N.get(self.id, "")
        self.default_name = self.config.get("name", "default")

        """
        self.name = self.default_name
        if MAIN_LANG != "en_US":
            self.name = self.config.get("name", MAIN_LANG)
        """

        icon_infos = [self.get_system_icon_info(self.id, 48), 
                      self.get_system_icon_info(self.id, 16),
                     ]
        
        self.icon_pixbuf = None
        self.menu_icon_pixbuf = None
        try:
            self.icon_pixbuf = gtk.gdk.pixbuf_new_from_file(icon_infos[0])
            self.menu_icon_pixbuf = gtk.gdk.pixbuf_new_from_file(icon_infos[1])
        except:
            self.icon_pixbuf = app_theme.get_pixbuf("navigate/none-big.png").get_pixbuf()
            self.menu_icon_pixbuf = app_theme.get_pixbuf("navigate/none-small.png").get_pixbuf()
            
        self.search_keyword = self.config.get("main", "search_keyword")
 def __init__(self, ini_file):
     self.ini_file = ini_file
     self.config = Config(ini_file)
     self.config.load()
     deepin_url = self.get_repo_urls()[1]
     self._url_parse = urlparse(deepin_url)
     self._hostname = self._url_parse.scheme + "://" + self._url_parse.netloc
Exemple #22
0
class Mirror(object):
    def __init__(self, ini_file):
        self.ini_file = ini_file
        self.config = Config(ini_file)
        self.config.load()
        deepin_url = self.get_repo_urls()[1]
        self._url_parse = urlparse(deepin_url)
        self._hostname = self._url_parse.scheme + "://" + self._url_parse.netloc

    @property
    def host(self):
        return self._url_parse.netloc

    @property
    def hostname(self):
        return self._hostname
    def __init__(self, module_config_path, argv=""):
        '''
        init docs
        '''
        # Init.
        gtk.Plug.__init__(self, 0)
        self.module_config_path = module_config_path
        self.module_config = Config(self.module_config_path)
        self.module_config.load()
        self.module_id = self.module_config.get("main", "id")
        self.argv = argv
        
        # WARING: only use once in one process
        DBusGMainLoop(set_as_default=True) 
        
        # Init threads.
        if self.module_id != "bluetooth": # Added by hualet, wonder why? go ask him :)
            gtk.gdk.threads_init()

        # Init dbus.
        self.bus = dbus.SessionBus()
        self.module_dbus_name = "com.deepin.%s_settings" % (self.module_id)
        self.module_object_name = "/com/deepin/%s_settings" % (self.module_id)
        self.module_bus_name = dbus.service.BusName(self.module_dbus_name, bus=self.bus)
        
        # Handle signals.
        self.connect("realize", self.module_frame_realize)
        self.connect("destroy", self.module_frame_exit)

        glib.timeout_add(1000, self.is_exist)
 def __init__(self, ini_file):
     self.config = Config(ini_file)
     self.config.load()
     deepin_url = self.get_repo_urls()[1]
     _url_parse = urlparse(deepin_url)
     self._hostname = _url_parse.scheme + "://" + _url_parse.netloc
     self._priority = int(self.config.get("mirror", "priority")) if self.config.has_option("mirror", "priority") else 100
class ModuleInfo(object):
    '''
    class docs
    '''
	
    def __init__(self, module_path):
        '''
        init docs
        '''
        self.path = module_path
        self.config = Config(os.path.join(self.path, "config.ini"))
        self.config.load()
        self.id = self.config.get("main", "id")
        # TODO: lihongwu req to support i18n
        self.name = MODULES_NAME_FOR_L18N.get(self.id, "")
        self.default_name = self.config.get("name", "default")

        """
        self.name = self.default_name
        if MAIN_LANG != "en_US":
            self.name = self.config.get("name", MAIN_LANG)
        """

        icon_infos = [self.get_system_icon_info(self.id, 48), 
                      self.get_system_icon_info(self.id, 16),
                     ]
        
        self.icon_pixbuf = None
        self.menu_icon_pixbuf = None
        try:
            self.icon_pixbuf = gtk.gdk.pixbuf_new_from_file(icon_infos[0])
            self.menu_icon_pixbuf = gtk.gdk.pixbuf_new_from_file(icon_infos[1])
        except:
            self.icon_pixbuf = app_theme.get_pixbuf("navigate/none-big.png").get_pixbuf()
            self.menu_icon_pixbuf = app_theme.get_pixbuf("navigate/none-small.png").get_pixbuf()
            
        self.search_keyword = self.config.get("main", "search_keyword")
        
    def get_system_icon_info(self, icon_id, icon_size):
        '''
        NOTE: Because dtk.ui.utils.get_system_icon_info need take 20ms every call,
        it will slow down start speed of deepin system settings.
        
        So i return path directly to solve start speed problem.
        '''
        return "/usr/share/icons/Deepin/apps/%s/preferences-%s.png" % (icon_size, icon_id)
Exemple #26
0
    def load_skin_from_package(self, filepath):
        '''
        Load theme from given package.

        @param filepath: The file path of package.
        '''
        # Init.
        skin_dir = os.path.join(self.user_skin_dir, str(uuid.uuid4()))

        # Create skin directory.
        create_directory(skin_dir, True)

        # Extract skin package.
        tar = tarfile.open(filepath, "r:gz")
        tar.extractall(skin_dir)

        # Get skin image file.
        config = Config(os.path.join(skin_dir, "config.ini"))
        config.load()

        # Move theme files to given directory if theme is not in default theme list.
        skin_theme_name = config.get("theme", "theme_name")
        if not skin_theme_name in COLOR_SEQUENCE:
            # Check version when package have special theme that not include in standard themes.
            app_id = config.get("application", "app_id")
            app_version = config.get("application", "app_version")
            if app_id == self.app_given_id and app_version == self.app_given_version:
                # Remove same theme from given directories.
                remove_directory(os.path.join(self.ui_theme_dir, skin_theme_name))
                if self.app_theme_dir != None:
                    remove_directory(os.path.join(self.app_theme_dir, skin_theme_name))

                # Move new theme files to given directories.
                shutil.move(os.path.join(skin_dir, "ui_theme", skin_theme_name), self.ui_theme_dir)
                if self.app_theme_dir != None:
                    shutil.move(os.path.join(skin_dir, "app_theme", skin_theme_name), self.app_theme_dir)

                # Remove temp theme directories under skin directory.
                remove_directory(os.path.join(skin_dir, "ui_theme"))
                remove_directory(os.path.join(skin_dir, "app_theme"))
            else:
                # Remove skin directory if version mismatch.
                remove_directory(skin_dir)

                return False

        # Apply new skin.
        skin_image_file = config.get("background", "image")
        if self.reload_skin(os.path.basename(skin_dir)):
            self.apply_skin()

            return (True, skin_dir, skin_image_file)
        else:
            return (False, skin_dir, skin_image_file)
Exemple #27
0
    def init_skin(self,
                  skin_name,
                  system_skin_dir,
                  user_skin_dir,
                  skin_config_file,
                  app_given_id,
                  app_given_version):
        '''
        Init skin.

        @param skin_name: Skin name.
        @param system_skin_dir: Default skin directory.
        @param user_skin_dir: User's skin directory, generic use ~/.config/project-name/skin
        @param skin_config_file: Skin's config filepath, generic use ~/.config/project-name/skin_config.ini
        @param app_given_id: Project name.
        @param app_given_version: Project version.
        '''
        self.skin_config_file = skin_config_file
        if os.path.exists(skin_config_file):
            # Read skin name from config file.
            skin_config = Config(skin_config_file)
            skin_config.load()

            # Load skin.
            init_skin_name = skin_config.get("skin", "skin_name")
        else:
            # Create skin config if it not exists.
            touch_file(self.skin_config_file)

            init_skin_name = skin_name

        if self.is_skin_exist(init_skin_name, system_skin_dir, user_skin_dir):
            self.load_skin(init_skin_name, system_skin_dir, user_skin_dir)
        else:
            # Try load default skin if user's select skin not exists.
            default_skin_name = self.get_default_skin(system_skin_dir, user_skin_dir)
            assert(default_skin_name != None)
            self.load_skin(default_skin_name, system_skin_dir, user_skin_dir)

        self.app_given_id = app_given_id
        self.app_given_version = app_given_version
Exemple #28
0
def get_config_info_config():
    config_info_config = Config(CONFIG_INFO_PATH)
    if os.path.exists(CONFIG_INFO_PATH):
        config_info_config.load()
    else:
        touch_file(CONFIG_INFO_PATH)
        config_info_config.load()
    return config_info_config
Exemple #29
0
def is_mirror_disabled():
    if os.path.exists(deepin_version_path):
        config = Config(deepin_version_path)
        config.load()
        return config.has_option("Custom", "Mirror") and config.get(
            "Custom", "Mirror") == "False"
    else:
        return True  # not deepin os, disable mirror change
 def scan_plugin_info(self):
     self.word_all_list = []
     self.words_all_list = []
     self.word_dict = {}
     self.words_dict = {}
     
     for plugin_name in os.listdir(self.plugin_dir):
         plugin_config_file = os.path.join(self.plugin_dir, plugin_name, self.plugin_config_name)
         plugin_config = Config(plugin_config_file)
         plugin_config.load()
         
         language = LANGUAGE.replace("_", "-")
         plugin_display_name = plugin_config.get("Plugin Info", "name[%s]" % language) or plugin_config.get("Plugin Info", "name[en]")
         is_support_word = is_true(plugin_config.get("Language Info", "word_translate"))
         is_support_words = is_true(plugin_config.get("Language Info", "words_translate"))
         support_all_language = is_true(plugin_config.get("Language Info", "support_all_language"))
         two_way_translate = is_true(plugin_config.get("Language Info", "two_way_translate"))
         src_language = plugin_config.get("Language Info", "src_language")
         dst_language = plugin_config.get("Language Info", "dst_language")
         need_network = is_true(plugin_config.get("Language Info", "need_network"))
         
         if is_support_word:
             if support_all_language:
                 self.word_all_list.append((plugin_name, plugin_display_name, need_network))
             else:
                 self.update_dict(self.word_dict, src_language, dst_language, plugin_name, plugin_display_name, need_network)
                 
                 if two_way_translate:
                     self.update_dict(self.word_dict, dst_language, src_language, plugin_name, plugin_display_name, need_network)    
                     
         if is_support_words:
             if support_all_language:
                 self.words_all_list.append((plugin_name, plugin_display_name, need_network))
             else:
                 self.update_dict(self.words_dict, src_language, dst_language, plugin_name, plugin_display_name, need_network)
                 
                 if two_way_translate:
                     self.update_dict(self.words_dict, dst_language, src_language, plugin_name, plugin_display_name, need_network)    
Exemple #31
0
def get_vpc_remind_config():
    CONFIG_INFO_PATH = os.path.expanduser(
        "~/.config/deepin-system-settings/tray/config.ini")
    config_info_config = Config(CONFIG_INFO_PATH)
    if os.path.exists(CONFIG_INFO_PATH):
        config_info_config.load()
    else:
        touch_file(CONFIG_INFO_PATH)
        config_info_config.load()
    return config_info_config
Exemple #32
0
def get_last_update_time():
    config = Config(SYS_CONFIG_INFO_PATH)

    if os.path.exists(SYS_CONFIG_INFO_PATH):
        config.load()
        if config.has_option("update", "last_update_time"):
            return config.get("update", "last_update_time")
        else:
            return ""
    else:
        return ""
Exemple #33
0
    def load_skin_from_image(self, filepath):
        '''
        Load theme from given image.

        @param filepath: The file path of image.
        '''
        # Init.
        skin_dir = os.path.join(self.user_skin_dir, str(uuid.uuid4()))
        skin_image_file = os.path.basename(filepath)
        config_file = os.path.join(skin_dir, "config.ini")
        dominant_color = get_dominant_color(filepath)
        similar_color = find_similar_color(dominant_color)[0]
        default_config = [
            ("theme", [("theme_name", similar_color)]),
            ("application", [("app_id", self.app_given_id),
                             ("app_version", self.app_given_version)]),
            ("background", [("image", skin_image_file),
                            ("x", "0"),
                            ("y", "0"),
                            ("scale_x", "1.0"),
                            ("scale_y", "1.0"),
                            ("dominant_color", dominant_color)]),
            ("action", [("deletable", "True"),
                        ("editable", "True"),
                        ("vertical_mirror", "False"),
                        ("horizontal_mirror", "False")])]

        # Create skin directory.
        create_directory(skin_dir, True)

        # Copy skin image file.
        shutil.copy(filepath, skin_dir)

        # Touch skin config file.
        touch_file(config_file)

        # Write default skin config information.
        Config(config_file, default_config).write()

        if self.reload_skin(os.path.basename(skin_dir)):
            self.apply_skin()

            return (True, skin_dir, skin_image_file)
        else:
            return (False, skin_dir, skin_image_file)
class UpdateDataService(dbus.service.Object):
    '''
    class docs
    '''
	
    def __init__(self, system_bus, mainloop):
        '''
        init docs
        '''
        # Init dbus service.
        dbus.service.Object.__init__(self, system_bus, DSC_UPDATER_PATH)
        self.mainloop = mainloop
        
        self.data_origin_dir = os.path.join(DATA_DIR, "origin")
        self.data_newest_dir = os.path.join(DATA_DIR, "newest")
        self.data_patch_dir = os.path.join(DATA_DIR, "patch")
        self.data_patch_config_filepath = os.path.join(DATA_DIR, "patch_status.ini")
        self.data_newest_id_path = os.path.join(DATA_DIR, "data_newest_id.ini")
        
    def get_unique_id(self):
        return str(uuid.uuid4())
        
    def run(self, test):
        # Init ini files.
        if not os.path.exists(self.data_newest_id_path):
            self.newest_data_id_config = Config(self.data_newest_id_path)
            self.newest_data_id_config.load()
            self.newest_data_id_config.set("newest", "data_id", "")
            self.newest_data_id_config.set("newest", "update_date", "")
            self.newest_data_id_config.write()
        else:
            self.newest_data_id_config = Config(self.data_newest_id_path)
            self.newest_data_id_config.load()
            
        try:
            update_date = self.newest_data_id_config.get("newest", "update_date")
        except Exception:
            update_date = ""

        if self.newest_data_id_config.get("newest", "data_id") == "" or update_date != UPDATE_DATE:
            self.clean()
            newest_data_id = self.get_unique_id()
            newest_data_dir = os.path.join(DATA_DIR, "update", newest_data_id)
            
            print "进行第一次数据解压..."
            log("进行第一次数据解压...")
            for data_file in os.listdir(self.data_origin_dir):
                with tarfile.open(os.path.join(self.data_origin_dir, data_file), "r:gz") as tar_file:
                    tar_file.extractall(newest_data_dir)
            print "进行第一次数据解压完成"
            log("进行第一次数据解压完成")
            
            self.newest_data_id_config.set("newest", "data_id", newest_data_id)
            self.newest_data_id_config.set("newest", "update_date", UPDATE_DATE)
            self.newest_data_id_config.write()
            
        if not os.path.exists(self.data_patch_config_filepath):
            self.patch_status_config = Config(self.data_patch_config_filepath)
            self.patch_status_config.load()
            for space_name in DATA_SPACE_NAME:
                self.patch_status_config.set("data_md5", space_name, "")
            self.patch_status_config.write()
        else:
            self.patch_status_config = Config(self.data_patch_config_filepath)
            self.patch_status_config.load()
        
        self.have_update = []
        # Download update data.
        for data_file in os.listdir(self.data_origin_dir):
            self.download_data(data_file, test)
            
        if self.have_update:
            # Apply update data.
            for space_name in self.have_update:
                self.apply_data(space_name)
                
            # Extra data.
            newest_data_id = self.get_unique_id()
            newest_data_dir = os.path.join(DATA_DIR, "update", newest_data_id)

            for space_name in DATA_SPACE_NAME:
                data_filename = "%s.tar.gz" % space_name
                origin_data_file = os.path.join(self.data_origin_dir, data_filename)
                newest_data_file = os.path.join(self.data_newest_dir, data_filename)
                if not os.path.exists(newest_data_file):
                    os.system('cp %s %s' % (origin_data_file, newest_data_file))
            
            print "解压最新数据..."
            log("解压最新数据...")
            for data_file in os.listdir(self.data_newest_dir):
                newest_file = os.path.join(self.data_newest_dir, data_file)
                with tarfile.open(newest_file, "r:gz") as tar_file:
                    tar_file.extractall(newest_data_dir)
            print "解压最新数据完成"
            log("解压最新数据完成")
            
            self.previous_data_id = self.newest_data_id_config.get("newest", "data_id")
            self.newest_data_id_config.set("newest", "data_id", newest_data_id)
            self.newest_data_id_config.write()

        if self.is_fontend_running():
            print 'Frontend is running, clear data next time!'
            log('Frontend is running, clear data next time!')
        else:
            print 'Clear unused data.'
            log('Clear unused data.')
            self.clear_data_folder()

        print 'Done!'
        log("Done!")
        glib.timeout_add(200, self.mainloop.quit)

    def is_fontend_running(self):
        if os.path.exists(DATA_CURRENT_ID_CONFIG_PATH):
            config = Config(DATA_CURRENT_ID_CONFIG_PATH)
            config.load()
            data_id = config.get('current', 'data_id')
            if data_id:
                return True
            else:
                return False
        else:
            False

    def clear_data_folder(self):
        # clear data when ui is not running

        # judge which data is in using
        if os.path.exists(DATA_CURRENT_ID_CONFIG_PATH):
            current_data_id_config = Config(DATA_CURRENT_ID_CONFIG_PATH)
            current_data_id_config.load()
            current_data_id = current_data_id_config.get("current", "data_id")
        else:
            current_data_id = None

        self.newest_data_id_config.load()
        newest_data_id = self.newest_data_id_config.get("newest", "data_id")
        data_file_list = ["newest",
                          "origin",
                          "patch",
                          "update",
                          "data_newest_id.ini",
                          "patch_status.ini",
                          "cache_soft.db",
                          "origin_data_time"
                          ]
        data_id_list = (current_data_id, newest_data_id)
        
        for data_file in os.listdir(DATA_DIR):
            if data_file not in data_file_list:
                remove_directory(os.path.join(DATA_DIR, data_file))
                print ">> remove file: %s" % data_file
                log(">> remove file: %s" % data_file)
            elif data_file == "update":
                for data_id in os.listdir(os.path.join(DATA_DIR, "update")):
                    if data_id not in data_id_list:
                        remove_directory(os.path.join(DATA_DIR, "update", data_id))
                        print '>> remove old data: %s' % data_id
                        log('>> remove old data: %s' % data_id)
        
    def download_data(self, data_file, test):
        origin_data_md5 = md5_file(os.path.join(self.data_origin_dir, data_file))
        space_name = data_file.split(".tar.gz")[0]
        patch_dir = os.path.join(self.data_patch_dir, space_name)
        
        # Create download directory.
        create_directory(patch_dir)
                
        if test:
            remote_url = "http://%s.%s/test" % (space_name, UPDATE_DATA_URL)
        else:
            remote_url = "http://%s.%s/3.1" % (space_name, UPDATE_DATA_URL)
            
        patch_list_url = "%s/patch/%s/patch_md5.json" % (remote_url, origin_data_md5)    

        try:
            patch_list_json = json.load(urllib2.urlopen(patch_list_url))
        except Exception, e:
            patch_list_json = ""
            
        if patch_list_json != "":
            patch_name = patch_list_json["current_patch"][0]["name"].encode("utf-8")
            patch_md5 = patch_list_json["current_patch"][0]["md5"].encode("utf-8")

            local_patch_info = self.patch_status_config.get("data_md5", space_name)
            if local_patch_info == '' or (local_patch_info != '' and eval(local_patch_info)[1] != patch_md5):
                
                # Start download.
                download_url = "%s/patch/%s/%s" % (remote_url, origin_data_md5, patch_name)
                local_patch_file = os.path.join(patch_dir, patch_name)
                
                # TODO: 此处添加下载返回值判断
                os.system("wget %s -t 5 -c -O %s" % (download_url, local_patch_file))
                try:
                    download_md5 = md5_file(local_patch_file)

                    if download_md5 == patch_md5:
                        self.have_update.append(space_name)
                        if local_patch_info:
                            remove_file(os.path.join(self.data_patch_dir, eval(local_patch_info)[0]))
                        self.patch_status_config.set("data_md5", space_name, [patch_name, patch_md5])
                        self.patch_status_config.write()
                        print "%s: 补丁%s下载成功" % (space_name, patch_name)
                        log("%s: 补丁%s下载成功" % (space_name, patch_name))
                    else:
                        print "%s: 补丁%s下载错误" (space_name, patch_name)
                        log("%s: 补丁%s下载错误" (space_name, patch_name))
                except:
                    print "%s: 补丁%s下载失败" (space_name, patch_name)
                    log("%s: 补丁%s下载失败" (space_name, patch_name))
            else:
                print "%s: 当前数据是最新的" % space_name
                log("%s: 当前数据是最新的" % space_name)
        else:
            print "%s: 网络问题或者远端没有任何更新补丁" % space_name
            log("%s: 网络问题或者远端没有任何更新补丁" % space_name)
    def run(self, test):
        # Init ini files.
        if not os.path.exists(self.data_newest_id_path):
            self.newest_data_id_config = Config(self.data_newest_id_path)
            self.newest_data_id_config.load()
            self.newest_data_id_config.set("newest", "data_id", "")
            self.newest_data_id_config.set("newest", "update_date", "")
            self.newest_data_id_config.write()
        else:
            self.newest_data_id_config = Config(self.data_newest_id_path)
            self.newest_data_id_config.load()
            
        try:
            update_date = self.newest_data_id_config.get("newest", "update_date")
        except Exception:
            update_date = ""

        if self.newest_data_id_config.get("newest", "data_id") == "" or update_date != UPDATE_DATE:
            self.clean()
            newest_data_id = self.get_unique_id()
            newest_data_dir = os.path.join(DATA_DIR, "update", newest_data_id)
            
            print "进行第一次数据解压..."
            log("进行第一次数据解压...")
            for data_file in os.listdir(self.data_origin_dir):
                with tarfile.open(os.path.join(self.data_origin_dir, data_file), "r:gz") as tar_file:
                    tar_file.extractall(newest_data_dir)
            print "进行第一次数据解压完成"
            log("进行第一次数据解压完成")
            
            self.newest_data_id_config.set("newest", "data_id", newest_data_id)
            self.newest_data_id_config.set("newest", "update_date", UPDATE_DATE)
            self.newest_data_id_config.write()
            
        if not os.path.exists(self.data_patch_config_filepath):
            self.patch_status_config = Config(self.data_patch_config_filepath)
            self.patch_status_config.load()
            for space_name in DATA_SPACE_NAME:
                self.patch_status_config.set("data_md5", space_name, "")
            self.patch_status_config.write()
        else:
            self.patch_status_config = Config(self.data_patch_config_filepath)
            self.patch_status_config.load()
        
        self.have_update = []
        # Download update data.
        for data_file in os.listdir(self.data_origin_dir):
            self.download_data(data_file, test)
            
        if self.have_update:
            # Apply update data.
            for space_name in self.have_update:
                self.apply_data(space_name)
                
            # Extra data.
            newest_data_id = self.get_unique_id()
            newest_data_dir = os.path.join(DATA_DIR, "update", newest_data_id)

            for space_name in DATA_SPACE_NAME:
                data_filename = "%s.tar.gz" % space_name
                origin_data_file = os.path.join(self.data_origin_dir, data_filename)
                newest_data_file = os.path.join(self.data_newest_dir, data_filename)
                if not os.path.exists(newest_data_file):
                    os.system('cp %s %s' % (origin_data_file, newest_data_file))
            
            print "解压最新数据..."
            log("解压最新数据...")
            for data_file in os.listdir(self.data_newest_dir):
                newest_file = os.path.join(self.data_newest_dir, data_file)
                with tarfile.open(newest_file, "r:gz") as tar_file:
                    tar_file.extractall(newest_data_dir)
            print "解压最新数据完成"
            log("解压最新数据完成")
            
            self.previous_data_id = self.newest_data_id_config.get("newest", "data_id")
            self.newest_data_id_config.set("newest", "data_id", newest_data_id)
            self.newest_data_id_config.write()

        if self.is_fontend_running():
            print 'Frontend is running, clear data next time!'
            log('Frontend is running, clear data next time!')
        else:
            print 'Clear unused data.'
            log('Clear unused data.')
            self.clear_data_folder()

        print 'Done!'
        log("Done!")
        glib.timeout_add(200, self.mainloop.quit)
Exemple #36
0
def data_init():
    global data_init_flag
    global DATA_ID

    if not data_init_flag:
        data_init_flag = True

        data_newest_id_config = Config(DATA_NEWEST_ID_CONFIG_FILE)
        data_newest_id_config.load()
        DATA_ID = data_newest_id_config.get("newest", "data_id")

        if not os.path.exists(DATA_CURRENT_ID_CONFIG_FILE):
            touch_file(DATA_CURRENT_ID_CONFIG_FILE)
            os.chmod(DATA_CURRENT_ID_CONFIG_FILE, 0777)

        data_current_id_config = Config(DATA_CURRENT_ID_CONFIG_FILE)
        data_current_id_config.load()
        data_current_id_config.set("current", "data_id", DATA_ID)
        data_current_id_config.write()
Exemple #37
0
class SkinConfig(gobject.GObject):
    '''
    SkinConfig class.

    @undocumented: update_image_size
    @undocumented: get_skin_file_path
    @undocumented: is_skin_exist
    @undocumented: get_default_skin
    @undocumented: get_skin_dir
    @undocumented: save_skin_name
    @undocumented: reload_skin
    @undocumented: load_skin
    @undocumented: save_skin
    @undocumented: change_theme
    @undocumented: apply_skin
    @undocumented: add_theme
    @undocumented: remove_theme
    @undocumented: wrap_skin_window
    @undocumented: add_skin_window
    @undocumented: remove_skin_window
    @undocumented: reset
    @undocumented: auto_resize
    @undocumented: vertical_mirror_background
    @undocumented: horizontal_mirror_background
    @undocumented: render_background
    @undocumented: export_skin
    @undocumented: load_skin_from_image
    @undocumented: load_skin_from_package
    '''

    __gsignals__ = {
        "theme-changed" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)),
    }

    def __init__(self):
        '''
        Initialize SkinConfig class.
        '''
        # Init.
        gobject.GObject.__init__(self)
        self.cache_pixbuf = CachePixbuf()

        self.theme_list = []
        self.window_list = []

    def set_application_window_size(self, app_window_width, app_window_height):
        '''
        Set application window with given size.

        @param app_window_width: Application window width.
        @param app_window_height: Application window height.
        '''
        self.app_window_width = app_window_width
        self.app_window_height = app_window_height

    def update_image_size(self, x, y, scale_x, scale_y):
        '''
        Internal function to update image size.
        '''
        self.x = x
        self.y = y
        self.scale_x = scale_x
        self.scale_y = scale_y

    def get_skin_file_path(self, filename):
        '''
        Internal function to get skin file path.
        '''
        skin_file_dir = None
        for skin_dir in [self.system_skin_dir, self.user_skin_dir]:
            if os.path.exists(skin_dir):
                if self.skin_name in os.listdir(os.path.expanduser(skin_dir)):
                    skin_file_dir = skin_dir
                    break

        if skin_file_dir:
            return os.path.join(skin_file_dir, self.skin_name, filename)
        else:
            return None

    def is_skin_exist(self, skin_name, system_skin_dir, user_skin_dir):
        '''
        Internal function to is skin exist in skin directories.
        '''
        for skin_dir in [system_skin_dir, user_skin_dir]:
            if os.path.exists(skin_dir):
                if skin_name in os.listdir(os.path.expanduser(skin_dir)):
                    return True

        return False

    def get_default_skin(self, system_skin_dir, user_skin_dir):
        '''
        Internal function to get default skin.
        '''
        for skin_dir in [system_skin_dir, user_skin_dir]:
            if os.path.exists(skin_dir):
                skin_list = os.listdir(os.path.expanduser(skin_dir))
                if len(skin_list) > 0:
                    return skin_list[0]

        return None

    def get_skin_dir(self):
        '''
        Internal function to get skin dir.
        '''
        for skin_dir in [self.system_skin_dir, self.user_skin_dir]:
            if os.path.exists(skin_dir):
                if self.skin_name in os.listdir(os.path.expanduser(skin_dir)):
                    return os.path.join(skin_dir, self.skin_name)

        return None

    def init_skin(self,
                  skin_name,
                  system_skin_dir,
                  user_skin_dir,
                  skin_config_file,
                  app_given_id,
                  app_given_version):
        '''
        Init skin.

        @param skin_name: Skin name.
        @param system_skin_dir: Default skin directory.
        @param user_skin_dir: User's skin directory, generic use ~/.config/project-name/skin
        @param skin_config_file: Skin's config filepath, generic use ~/.config/project-name/skin_config.ini
        @param app_given_id: Project name.
        @param app_given_version: Project version.
        '''
        self.skin_config_file = skin_config_file
        if os.path.exists(skin_config_file):
            # Read skin name from config file.
            skin_config = Config(skin_config_file)
            skin_config.load()

            # Load skin.
            init_skin_name = skin_config.get("skin", "skin_name")
        else:
            # Create skin config if it not exists.
            touch_file(self.skin_config_file)

            init_skin_name = skin_name

        if self.is_skin_exist(init_skin_name, system_skin_dir, user_skin_dir):
            self.load_skin(init_skin_name, system_skin_dir, user_skin_dir)
        else:
            # Try load default skin if user's select skin not exists.
            default_skin_name = self.get_default_skin(system_skin_dir, user_skin_dir)
            assert(default_skin_name != None)
            self.load_skin(default_skin_name, system_skin_dir, user_skin_dir)

        self.app_given_id = app_given_id
        self.app_given_version = app_given_version

    def save_skin_name(self):
        '''
        Internal function to save skin name.
        '''
        skin_config = Config(self.skin_config_file)
        skin_config.load()
        if skin_config.get("skin", "skin_name") != self.skin_name:
            skin_config.set("skin", "skin_name", self.skin_name)
            skin_config.write(self.skin_config_file)

    def reload_skin(self, skin_name=None):
        '''
        Internal function to reload skin.
        '''
        if skin_name:
            return self.load_skin(skin_name)
        else:
            return self.load_skin(self.skin_name)

    def load_skin(self, skin_name, system_skin_dir=None, user_skin_dir=None):
        '''
        Internal function to Load skin.

        @return: Return True if load finish, otherwise return False.
        '''
        try:
            # Save skin dir.
            self.skin_name = skin_name

            if system_skin_dir:
                self.system_skin_dir = system_skin_dir
                create_directory(self.system_skin_dir)

            if user_skin_dir:
                self.user_skin_dir = user_skin_dir
                create_directory(self.user_skin_dir)

            self.skin_dir = self.get_skin_dir()

            # Load config file.
            self.config = Config(self.get_skin_file_path("config.ini"))
            self.config.load()

            # Get theme config.
            self.theme_name = self.config.get("theme", "theme_name")

            # Get application config.
            self.app_id = self.config.get("application", "app_id")
            self.app_version = self.config.getfloat("application", "app_version")

            # Get background config.
            self.image = self.config.get("background", "image")
            self.x = self.config.getfloat("background", "x")
            self.y = self.config.getfloat("background", "y")
            self.scale_x = self.config.getfloat("background", "scale_x")
            self.scale_y = self.config.getfloat("background", "scale_y")
            self.dominant_color = self.config.get("background", "dominant_color")

            # Get action config.
            self.deletable = self.config.getboolean("action", "deletable")
            self.editable = self.config.getboolean("action", "editable")
            self.vertical_mirror = self.config.getboolean("action", "vertical_mirror")
            self.horizontal_mirror = self.config.getboolean("action", "horizontal_mirror")

            # Generate background pixbuf.
            self.background_pixbuf = gtk.gdk.pixbuf_new_from_file(self.get_skin_file_path(self.image))

            # Save skin name.
            self.save_skin_name()

            return True
        except Exception, e:
            print "function load_skin got error: %s" % (e)
            traceback.print_exc(file=sys.stdout)

            return False
    def init_config(self):
        if os.path.exists(CONFIG_INFO_PATH):
            config = Config(CONFIG_INFO_PATH)
            config.load()
            uid = config.get("statistics", 'uid')
            if not uid:
                uid = uuid.uuid4().hex
                config.set("statistics", 'uid', uid)
                config.set("statistics", 'last_date', '')
                config.write()
        else:
            touch_file(CONFIG_INFO_PATH)
            uid = uuid.uuid4().hex
            config = Config(CONFIG_INFO_PATH)
            config.load()
            config.set("statistics", 'uid', uid)
            config.set("statistics", 'last_date', '')
            config.write()

        return config
Exemple #39
0
class SettingConfig(QObject):
    
    def __init__(self):
        QObject.__init__(self)
        self.config_file = get_config_file("config.ini")
        
        if os.path.exists(self.config_file):
            self.config = Config(self.config_file, DEFAULT_CONFIG)
            self.config.load()
        else:
            self.config = Config(self.config_file, DEFAULT_CONFIG)
            self.config.write()
            
    @pyqtSlot(str, bool)        
    def update_trayicon_config(self, config_id, config_value):
        with self.config.save_config():
            self.config.set("trayicon", config_id, config_value)

    @pyqtSlot(str, str)        
    def update_translate_config(self, config_id, config_value):
        with self.config.save_config():
            self.config.set("translate", config_id, config_value)
            
    @pyqtSlot(str, result=bool)        
    def get_trayicon_config(self, option):
        return is_true(self.config.get_config("trayicon", option))
    
    @pyqtSlot(str, result=str)
    def get_translate_config(self, option):
        return self.config.get_config("translate", option)
Exemple #40
0
class ModuleFrame(gtk.Plug):
    '''
    class docs
    '''
    def __init__(self, module_config_path, argv=""):
        '''
        init docs
        '''
        # Init.
        gtk.Plug.__init__(self, 0)
        self.module_config_path = module_config_path
        self.module_config = Config(self.module_config_path)
        self.module_config.load()
        self.module_id = self.module_config.get("main", "id")
        self.argv = argv

        # WARING: only use once in one process
        DBusGMainLoop(set_as_default=True)

        # Init threads.
        if self.module_id != "bluetooth":  # Added by hualet, wonder why? go ask him :)
            gtk.gdk.threads_init()

        # Init dbus.
        self.bus = dbus.SessionBus()
        self.module_dbus_name = "com.deepin.%s_settings" % (self.module_id)
        self.module_object_name = "/com/deepin/%s_settings" % (self.module_id)
        self.module_bus_name = dbus.service.BusName(self.module_dbus_name,
                                                    bus=self.bus)

        # Handle signals.
        self.connect("realize", self.module_frame_realize)
        self.connect("destroy", self.module_frame_exit)

        glib.timeout_add(1000, self.is_exist)

    def is_exist(self):
        if dbus.SessionBus().name_has_owner("com.deepin.system_settings"):
            return True
        else:
            glib.timeout_add(0, gtk.main_quit)
            return False

    def run(self):
        if not hasattr(self, "module_message_handler"):
            raise Exception, "Please customize your own module_message_handler for module_frame"

        # Start dbus service.
        ModuleService(self.module_bus_name, self.module_dbus_name,
                      self.module_object_name, self.module_message_handler)

        # Show.
        self.show_all()

        gtk.main()

    def do_delete_event(self, w):
        #a trick to prevent plug destroyed!.  the  better way is recreate an GtkPlug when need reuse it's content
        return True

    def module_frame_realize(self, widget):
        # Send module information.
        self.send_module_info()

    def exit(self):
        gtk.main_quit()

    def module_frame_exit(self, widget):
        print "%s module exit" % (self.module_id)

        gtk.main_quit()

    def send_message(self, message_type, message_content):
        if is_dbus_name_exists(APP_DBUS_NAME):
            bus_object = self.bus.get_object(APP_DBUS_NAME, APP_OBJECT_NAME)
            method = bus_object.get_dbus_method("message_receiver")
            method(
                message_type,
                message_content,
                reply_handler=self.handle_dbus_reply,  # add reply handler
                error_handler=self.handle_dbus_error  # add error handler
            )

    def handle_dbus_reply(self, *reply):
        # print "%s (reply): %s" % (self.module_dbus_name, str(reply))
        pass

    def handle_dbus_error(self, *error):
        #print "%s (error): %s" % (self.module_dbus_name, str(error))
        pass

    def send_module_info(self):
        module_id = self.module_config.get("main", "id")
        name = MODULES_NAME_FOR_L18N.get(module_id, "")
        self.send_message("send_module_info",
                          (1, (module_id, name), self.argv))
        self.send_message("send_plug_id", (self.module_id, self.get_id()))

    def send_submodule_crumb(self, crumb_index, crumb_name):
        self.send_message("send_submodule_info",
                          (crumb_index, crumb_name, self.module_id))
class ModuleFrame(gtk.Plug):
    '''
    class docs
    '''
	
    def __init__(self, module_config_path, argv=""):
        '''
        init docs
        '''
        # Init.
        gtk.Plug.__init__(self, 0)
        self.module_config_path = module_config_path
        self.module_config = Config(self.module_config_path)
        self.module_config.load()
        self.module_id = self.module_config.get("main", "id")
        self.argv = argv
        
        # WARING: only use once in one process
        DBusGMainLoop(set_as_default=True) 
        
        # Init threads.
        if self.module_id != "bluetooth": # Added by hualet, wonder why? go ask him :)
            gtk.gdk.threads_init()

        # Init dbus.
        self.bus = dbus.SessionBus()
        self.module_dbus_name = "com.deepin.%s_settings" % (self.module_id)
        self.module_object_name = "/com/deepin/%s_settings" % (self.module_id)
        self.module_bus_name = dbus.service.BusName(self.module_dbus_name, bus=self.bus)
        
        # Handle signals.
        self.connect("realize", self.module_frame_realize)
        self.connect("destroy", self.module_frame_exit)

        glib.timeout_add(1000, self.is_exist)

    def is_exist(self):
        if dbus.SessionBus().name_has_owner("com.deepin.system_settings"):
            return True
        else:
            glib.timeout_add(0, gtk.main_quit)
            return False

    def run(self):    
        if not hasattr(self, "module_message_handler"):
            raise Exception, "Please customize your own module_message_handler for module_frame"
        
        # Start dbus service.
        ModuleService(self.module_bus_name, 
                      self.module_dbus_name, 
                      self.module_object_name,
                      self.module_message_handler)
        
        # Show.
        self.show_all()
        
        gtk.main()
        
    def do_delete_event(self, w):
        #a trick to prevent plug destroyed!.  the  better way is recreate an GtkPlug when need reuse it's content
        return True

    def module_frame_realize(self, widget):
        # Send module information.
        self.send_module_info()

    def exit(self):
        gtk.main_quit()

    def module_frame_exit(self, widget):
        print "%s module exit" % (self.module_id)
        
        gtk.main_quit()
        
    def send_message(self, message_type, message_content):    
        if is_dbus_name_exists(APP_DBUS_NAME):
            bus_object = self.bus.get_object(APP_DBUS_NAME, APP_OBJECT_NAME)
            method = bus_object.get_dbus_method("message_receiver")
            method(message_type, 
                   message_content,
                   reply_handler=self.handle_dbus_reply, # add reply handler
                   error_handler=self.handle_dbus_error  # add error handler
                   )
            
    def handle_dbus_reply(self, *reply):
        # print "%s (reply): %s" % (self.module_dbus_name, str(reply))
        pass
        
    def handle_dbus_error(self, *error):
        #print "%s (error): %s" % (self.module_dbus_name, str(error))
        pass
        
    def send_module_info(self):
        module_id = self.module_config.get("main", "id")
        name = MODULES_NAME_FOR_L18N.get(module_id, "")
        self.send_message("send_module_info", 
                          (1, 
                           (module_id,
                            name), 
                           self.argv))
        self.send_message("send_plug_id", (self.module_id, self.get_id()))
        
    def send_submodule_crumb(self, crumb_index, crumb_name):
        self.send_message("send_submodule_info", (crumb_index, crumb_name, self.module_id))
Exemple #42
0
DSC_UPDATER_PATH = "/com/linuxdeepin/softwarecenterupdater"

NOTIFICATIONS_NAME = "org.freedesktop.Notifications"
NOTIFICATIONS_PATH = "/org/freedesktop/Notifications"

LOG_PATH = "/tmp/dsc-update-daemon.log"
DATA_CURRENT_ID_CONFIG_PATH = '/tmp/deepin-software-center/data_current_id.ini'

DELAY_UPDATE_INTERVAL = 600

SERVER_ADDRESS = "http://apis.linuxdeepin.com/dscapi/statistics/?uid="

from constant import NO_NOTIFY_FILE, dsc_root_dir, DEFAULT_UPDATE_INTERVAL, CONFIG_INFO_PATH
if not os.path.exists(CONFIG_INFO_PATH):
    touch_file(CONFIG_INFO_PATH)
config = Config(CONFIG_INFO_PATH)
config.load()

def get_common_image(name):
    return os.path.join(dsc_root_dir, "image", name)

def is_auto_update():
    if config.has_option('update', 'auto'):
        if config.get('update', 'auto') == 'False':
            return False
    return True

def get_update_interval():
    if config.has_option('update', 'interval'):
        return config.get('update', 'interval')
    return DEFAULT_UPDATE_INTERVAL
Exemple #43
0
def run():
    if not os.path.exists(data_newest_id_path):
        newest_data_id_config = Config(data_newest_id_path)
        newest_data_id_config.load()
        newest_data_id_config.set("newest", "data_id", "")
        newest_data_id_config.set("newest", "update_date", "")
        newest_data_id_config.write()
    else:
        newest_data_id_config = Config(data_newest_id_path)
        newest_data_id_config.load()

    try:
        update_date = newest_data_id_config.get("newest", "update_date")
    except Exception:
        update_date = ""

    if newest_data_id_config.get("newest", "data_id") == "" or update_date != UPDATE_DATE:
        clean()
        newest_data_id = str(uuid.uuid4())
        newest_data_dir = os.path.join(DATA_DIR, "update", newest_data_id)
        
        print "进行第一次数据解压..."
        for data_file in os.listdir(data_origin_dir):
            with tarfile.open(os.path.join(data_origin_dir, data_file), "r:gz") as tar_file:
                tar_file.extractall(newest_data_dir)
        print "进行第一次数据解压完成"
        
        newest_data_id_config.set("newest", "data_id", newest_data_id)
        newest_data_id_config.set("newest", "update_date", UPDATE_DATE)
        newest_data_id_config.write()
def data_init():
    global data_init_flag
    global DATA_ID
    
    if not data_init_flag:
        data_init_flag = True
        
        data_newest_id_config = Config(DATA_NEWEST_ID_CONFIG_FILE)
        data_newest_id_config.load()
        DATA_ID = data_newest_id_config.get("newest", "data_id")
        
        if not os.path.exists(DATA_CURRENT_ID_CONFIG_FILE):
            touch_file(DATA_CURRENT_ID_CONFIG_FILE)
            os.chmod(DATA_CURRENT_ID_CONFIG_FILE, 0777)
            
        data_current_id_config = Config(DATA_CURRENT_ID_CONFIG_FILE)
        data_current_id_config.load()
        data_current_id_config.set("current", "data_id", DATA_ID)
        data_current_id_config.write()
def data_exit():
    data_current_id_config = Config(DATA_CURRENT_ID_CONFIG_FILE)
    data_current_id_config.load()
    data_current_id_config.set("current", "data_id", "")
    data_current_id_config.write()
Exemple #46
0
def data_exit():
    data_current_id_config = Config(DATA_CURRENT_ID_CONFIG_FILE)
    data_current_id_config.load()
    data_current_id_config.set("current", "data_id", "")
    data_current_id_config.write()
Exemple #47
0
class SettingConfig(QObject):
    def __init__(self):
        QObject.__init__(self)
        self.config_file = get_config_file("config.ini")

        if os.path.exists(self.config_file):
            self.config = Config(self.config_file, DEFAULT_CONFIG)
            self.config.load()
        else:
            self.config = Config(self.config_file, DEFAULT_CONFIG)
            self.config.write()

    @pyqtSlot(str, bool)
    def update_trayicon_config(self, config_id, config_value):
        with self.config.save_config():
            self.config.set("trayicon", config_id, config_value)

    @pyqtSlot(str, str)
    def update_translate_config(self, config_id, config_value):
        with self.config.save_config():
            self.config.set("translate", config_id, config_value)

    @pyqtSlot(str, result=bool)
    def get_trayicon_config(self, option):
        return is_true(self.config.get_config("trayicon", option))

    @pyqtSlot(str, result=str)
    def get_translate_config(self, option):
        return self.config.get_config("translate", option)
Exemple #48
0
    def scan_plugin_info(self):
        self.word_all_list = []
        self.words_all_list = []
        self.word_dict = {}
        self.words_dict = {}

        for plugin_name in os.listdir(self.plugin_dir):
            plugin_config_file = os.path.join(self.plugin_dir, plugin_name,
                                              self.plugin_config_name)
            plugin_config = Config(plugin_config_file)
            plugin_config.load()

            language = locale.getlocale()[0].replace("_", "-")
            plugin_display_name = plugin_config.get(
                "Plugin Info", "name[%s]" % language) or plugin_config.get(
                    "Plugin Info", "name[en]")
            is_support_word = is_true(
                plugin_config.get("Language Info", "word_translate"))
            is_support_words = is_true(
                plugin_config.get("Language Info", "words_translate"))
            support_all_language = is_true(
                plugin_config.get("Language Info", "support_all_language"))
            two_way_translate = is_true(
                plugin_config.get("Language Info", "two_way_translate"))
            src_language = plugin_config.get("Language Info", "src_language")
            dst_language = plugin_config.get("Language Info", "dst_language")

            if is_support_word:
                if support_all_language:
                    self.word_all_list.append(
                        (plugin_name, plugin_display_name))
                else:
                    self.update_dict(self.word_dict, src_language,
                                     dst_language, plugin_name,
                                     plugin_display_name)

                    if two_way_translate:
                        self.update_dict(self.word_dict, dst_language,
                                         src_language, plugin_name,
                                         plugin_display_name)

            if is_support_words:
                if support_all_language:
                    self.words_all_list.append(
                        (plugin_name, plugin_display_name))
                else:
                    self.update_dict(self.words_dict, src_language,
                                     dst_language, plugin_name,
                                     plugin_display_name)

                    if two_way_translate:
                        self.update_dict(self.words_dict, dst_language,
                                         src_language, plugin_name,
                                         plugin_display_name)