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 __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()
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 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 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 __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
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 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 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 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 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 = get_language() 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)
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
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 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)
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 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 ""
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)
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 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 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()
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