def fetch_screenshot(self): screenshot_dir = os.path.join(SCREENSHOT_DOWNLOAD_DIR, self.pkg_name) screenshot_md5_path = os.path.join(screenshot_dir, "screenshot_md5.txt") remote_screenshot_md5_url = "%s/zh_CN/%s/screenshot_md5.txt" % (SCREENSHOT_HOST, self.pkg_name) remote_screenshot_zip_url = "%s/zh_CN/%s/screenshot.zip" % (SCREENSHOT_HOST, self.pkg_name) try: remote_md5 = urllib2.urlopen(remote_screenshot_md5_url).read() need_download = False if os.path.exists(screenshot_dir): if os.path.exists(screenshot_md5_path): local_md5 = read_file(screenshot_md5_path) if remote_md5 != local_md5: need_download = True else: need_download = True else: need_download = True if need_download: write_file(screenshot_md5_path, remote_md5, True) try: urllib.urlretrieve(remote_screenshot_zip_url, os.path.join(SCREENSHOT_DOWNLOAD_DIR, self.pkg_name, "screenshot.zip") ) global_event.emit("download-screenshot-finish", self.pkg_name) except Exception, e: global_logger.logerror("Download screenshot error: %s" % e) except Exception, e: global_logger.logerror("fetch_screenshot got error: %s" % e)
def add_no_notify_pkg(self, info): pkg_name, path = info no_notify_config = self.read_no_notify_config(path) if pkg_name not in no_notify_config: pkg_name = str(pkg_name) no_notify_config.append(pkg_name) write_file(path, str(no_notify_config))
def remove_no_notify_pkg(self, info): pkg_name, path = info pkg_name = str(pkg_name) path = str(path) no_notify_config = self.read_no_notify_config(path) if pkg_name in no_notify_config: write_file(path, str(filter(lambda config_pkg_name: config_pkg_name != pkg_name, no_notify_config)))
def remove_no_notify_pkg(self, info): pkg_name, path = info pkg_name = str(pkg_name) path = str(path) no_notify_config = self.read_no_notify_config(path) if pkg_name in no_notify_config: write_file( path, str( filter(lambda config_pkg_name: config_pkg_name != pkg_name, no_notify_config)))
def vote_send_success_callback(infos, window): pkg_name = infos[0] grade_config_path, grade_config = get_grade_config() global_event.emit("show-message", _("Rated successfully. Thanks for your involvement."), 5000) tool_tip.hide_all() current_time = time.time() grade_config[pkg_name] = current_time write_file(grade_config_path, str(grade_config)) if infos[1] != None: obj = infos[1] star = float(infos[2][pkg_name][0]) if isinstance(obj, StarView): obj.set_star_level(int(star)) elif isinstance(obj, DscStarBuffer): obj.update_star(star)
def fetch_screenshot(self): screenshot_dir = os.path.join(SCREENSHOT_DOWNLOAD_DIR, self.pkg_name) screenshot_md5_path = os.path.join(screenshot_dir, "screenshot_md5.txt") remote_screenshot_md5_url = "%s/zh_CN/%s/screenshot_md5.txt" % ( SCREENSHOT_HOST, self.pkg_name) remote_screenshot_zip_url = "%s/zh_CN/%s/screenshot.zip" % ( SCREENSHOT_HOST, self.pkg_name) try: remote_md5 = urllib2.urlopen(remote_screenshot_md5_url).read() need_download = False if os.path.exists(screenshot_dir): if os.path.exists(screenshot_md5_path): local_md5 = read_file(screenshot_md5_path) if remote_md5 != local_md5: need_download = True else: need_download = True else: need_download = True if need_download: write_file(screenshot_md5_path, remote_md5, True) try: urllib.urlretrieve( remote_screenshot_zip_url, os.path.join(SCREENSHOT_DOWNLOAD_DIR, self.pkg_name, "screenshot.zip")) global_event.emit("download-screenshot-finish", self.pkg_name) except Exception, e: global_logger.error("Download screenshot error: %s" % e) except Exception, e: global_logger.error("fetch_screenshot got error: %s" % e)
def write_file(filepath, content, mkdir=False): print "Please import deepin_utils.file.write_file, this function will departed in next release version." return file.write_file(filepath, content, mkdir=False)