def set_cookie_star(appid, star): domain = GAME_CENTER_SERVER_ADDRESS.split('/')[2].split(':')[0] path = '/game/details/%s' % appid m = cookielib.MozillaCookieJar() try: m.load(COOKIE_FILE) except: pass expires = int(time.time() + ONE_DAY_SECONDS) c = cookielib.Cookie( version=0, name='star', value=str(star), port=None, port_specified=False, domain=domain, domain_specified=False, domain_initial_dot=False, path=path, path_specified=False, secure=False, expires=expires, discard=False, comment=None, comment_url=None, rest={}, rfc2109=False, ) m.set_cookie(c) if not os.path.exists(COOKIE_FILE): touch_file(COOKIE_FILE) m.save(COOKIE_FILE)
def export_skin(self, filepath): ''' Internal function to export skin. ''' # Build temp config file. config_filepath = os.path.join("/tmp/%s", str(uuid.uuid4())) touch_file(config_filepath) self.save_skin(config_filepath) # Build skin package. with tarfile.open("%s.tar.gz" % filepath, "w:gz") as tar: # Add config file. tar.add(config_filepath, "config.ini", False) # Add background image file. tar.add(self.get_skin_file_path(self.image), self.image, False) # Copy theme files is theme is not standard theme. if not self.theme_name in COLOR_SEQUENCE: tar.add(os.path.join(self.ui_theme_dir, self.theme_name), os.path.join("ui_theme", self.theme_name)) if self.app_theme_dir != None: tar.add(os.path.join(self.app_theme_dir, self.theme_name), os.path.join("app_theme", self.theme_name)) # Remove temp config file. remove_file(config_filepath)
def set_running_lock(running): if running: touch_file(BACKEND_PID) with open(BACKEND_PID, "w") as file_handler: file_handler.write(str(os.getpid())) else: if os.path.exists(BACKEND_PID): os.remove(BACKEND_PID)
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
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 __init__(self): QObject.__init__(self) self.video_db_path = os.path.join(CONFIG_DIR, "video_db") touch_file(self.video_db_path) self.video_db_connect = sqlite3.connect(self.video_db_path) self.video_db_cursor = self.video_db_connect.cursor() self.video_db_cursor.execute( "CREATE TABLE IF NOT EXISTS settings(key PRIMARY KEY NOT NULL, value)" )
def get_grade_config(): grade_config_path = os.path.join(CONFIG_DIR, "grade_pkgs") if not os.path.exists(grade_config_path): touch_file(grade_config_path) grade_config_str = read_file(grade_config_path) try: grade_config = eval(grade_config_str) if type(grade_config).__name__ != "dict": grade_config = {} except Exception: grade_config = {} return (grade_config_path, grade_config)
def __init__(self): QObject.__init__(self) self.video_db_path = os.path.join(CONFIG_DIR, "video_db") touch_file(self.video_db_path) self.video_db_connect = sqlite3.connect(self.video_db_path) self.video_db_cursor = self.video_db_connect.cursor() self.video_db_cursor.execute( "CREATE TABLE IF NOT EXISTS settings(key PRIMARY KEY NOT NULL, value)" ) self._commit_timer = QTimer() self._commit_timer.setInterval(500) self._commit_timer.setSingleShot(True) self._commit_timer.timeout.connect(lambda: self.video_db_connect.commit())
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 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 run(self): json_data = {} query = urllib.urlencode(self.data) request_url = ("%s?%s") % (self.home_data_url, query) try: connection = urllib2.urlopen( request_url, timeout=POST_TIMEOUT, ) json_data = json.loads(connection.read()) touch_file(HOME_CACHE_DATA_PATH) with open(HOME_CACHE_DATA_PATH, "wb") as fp: json.dump(json_data, fp) except Exception, e: traceback.print_exc(file=sys.stdout) print "Fetch home data failed: %s." % (e) print "url:", request_url if os.path.exists(HOME_CACHE_DATA_PATH): with open(HOME_CACHE_DATA_PATH) as fp: json_data = json.load(fp)
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
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
DSC_UPDATER_NAME = "com.linuxdeepin.softwarecenterupdater" 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')
def touch_file(filepath): print "Please import deepin_utils.file.touch_file, this function will departed in next release version." return file.touch_file(filepath)