def check_push_update(): global update_content, update_dict try: opener = get_opener() req_url = update_url + "?uuid=" + get_uuid() \ + "&version=" + update_from_github.current_version() \ + "&platform=" + platform.platform() try: update_content = opener.open(req_url).read() except Exception as e: xlog.warn("check_update fail:%r", e) return False update_dict = json.loads(update_content) return True for module in update_dict["modules"]: new_version = str(update_dict["modules"][module]["last_version"]) describe = update_dict["modules"][module]["versions"][new_version]["describe"] if update_dict["modules"][module]["versions"][new_version]["notify"] != "true": continue if not module in config.config["modules"]: ignore_version = 0 current_version = 0 config.config["modules"][module] = {} config.config["modules"][module]["current_version"] = '0.0.0' else: current_version = config.get(["modules", module, "current_version"]) if "ignore_version" in config.config["modules"][module]: ignore_version = config.config["modules"][module]["ignore_version"] else: ignore_version = current_version if version_to_bin(new_version) <= version_to_bin(ignore_version): continue if version_to_bin(new_version) > version_to_bin(current_version): xlog.info("new %s version:%s", module, new_version) if sys.platform == "linux" or sys.platform == "linux2": from gtk_tray import sys_tray msg = "Module %s new version: %s, Download?\nNew:%s" % (module, new_version, describe) data_download = "%s|%s|download" % (module, new_version) data_ignore = "%s|%s|ignore" % (module, new_version) buttons = {1: {"data":data_download, "label":"Download", 'callback':general_gtk_callback}, 2: {"data":data_ignore, "label":"Ignore", 'callback':general_gtk_callback}} sys_tray.notify_general(msg=msg, title="New Version", buttons=buttons) elif sys.platform == "win32": from win_tray import sys_tray msg = "Module %s new version: %s, Download?" % (module, new_version) if sys_tray.dialog_yes_no(msg, u"Download", None, None) == 1: download_module(module, new_version) else: ignore_module(module, new_version) elif sys.platform == "darwin": from mac_tray import sys_tray msg = "Module %s new version: %s, Download?" % (module, new_version) if sys_tray.presentAlert_withTitle_(msg, "Download"): download_module(module, new_version) else: ignore_module(module, new_version) else: download_module(module, new_version) except Exception as e: xlog.exception("check_update except:%s", e) return
def check_push_update(): global update_content, update_dict try: opener = get_opener() req_url = update_url + "?uuid=" + get_uuid() \ + "&version=" + update_from_github.current_version() \ + "&platform=" + platform.platform() try: update_content = opener.open(req_url).read() except Exception as e: xlog.warn("check_update fail:%r", e) return False update_dict = json.loads(update_content) return True for module in update_dict["modules"]: new_version = str(update_dict["modules"][module]["last_version"]) describe = update_dict["modules"][module]["versions"][new_version][ "describe"] if update_dict["modules"][module]["versions"][new_version][ "notify"] != "true": continue if not module in config.config["modules"]: ignore_version = 0 current_version = 0 config.config["modules"][module] = {} config.config["modules"][module]["current_version"] = '0.0.0' else: current_version = config.get( ["modules", module, "current_version"]) if "ignore_version" in config.config["modules"][module]: ignore_version = config.config["modules"][module][ "ignore_version"] else: ignore_version = current_version if version_to_bin(new_version) <= version_to_bin(ignore_version): continue if version_to_bin(new_version) > version_to_bin(current_version): xlog.info("new %s version:%s", module, new_version) if sys.platform == "linux" or sys.platform == "linux2": from gtk_tray import sys_tray msg = "Module %s new version: %s, Download?\nNew:%s" % ( module, new_version, describe) data_download = "%s|%s|download" % (module, new_version) data_ignore = "%s|%s|ignore" % (module, new_version) buttons = { 1: { "data": data_download, "label": "Download", 'callback': general_gtk_callback }, 2: { "data": data_ignore, "label": "Ignore", 'callback': general_gtk_callback } } sys_tray.notify_general(msg=msg, title="New Version", buttons=buttons) elif sys.platform == "win32": from win_tray import sys_tray msg = "Module %s new version: %s, Download?" % ( module, new_version) if sys_tray.dialog_yes_no(msg, u"Download", None, None) == 1: download_module(module, new_version) else: ignore_module(module, new_version) elif sys.platform == "darwin": from mac_tray import sys_tray msg = "Module %s new version: %s, Download?" % ( module, new_version) if sys_tray.presentAlert_withTitle_(msg, "Download"): download_module(module, new_version) else: ignore_module(module, new_version) else: download_module(module, new_version) except Exception as e: xlog.exception("check_update except:%s", e) return
def download_module(module, new_version): import os global update_content, update_dict current_path = os.path.dirname(os.path.abspath(__file__)) download_path = os.path.abspath( os.path.join(current_path, os.pardir, os.pardir, 'data', 'downloads')) if not os.path.isdir(download_path): os.mkdir(download_path) try: for source in update_dict["modules"][module]["versions"][new_version]["sources"]: url = source["url"] filename = module + "-" + new_version + ".zip" file_path = os.path.join(download_path, filename) if os.path.isfile(file_path) and sha1_file(file_path) == update_dict["modules"][module]["versions"][new_version]["sha1"]: pass elif not download_file(url, file_path): xlog.warn("download %s fail", url) continue sha1 = sha1_file(file_path) if update_dict["modules"][module]["versions"][new_version]["sha1"] != sha1: xlog.warn("download %s sha1 wrong", url) continue module_path = os.path.abspath( os.path.join(current_path, os.pardir, os.pardir, module)) if not os.path.isdir(module_path): os.path.mkdir(module_path, "755") version_path = os.path.join(module_path, new_version) if os.path.isdir(version_path): xlog.error("module dir exist:%s, download exist.", version_path) return with zipfile.ZipFile(file_path, "r") as dz: dz.extractall(module_path) dz.close() import shutil unzip_path = os.path.abspath(os.path.join(module_path, module + "-" + new_version)) tag_path = os.path.abspath(os.path.join(module_path, new_version)) shutil.move(unzip_path, tag_path) msg = "Module %s new version %s downloaded, Install?" % (module, new_version) if sys.platform == "linux" or sys.platform == "linux2": from gtk_tray import sys_tray data_install = "%s|%s|install" % (module, new_version) data_ignore = "%s|%s|ignore" % (module, new_version) buttons = {1: {"data":data_install, "label":"Install", 'callback':general_gtk_callback}, 2: {"data":data_ignore, "label":"Ignore", 'callback':general_gtk_callback}} sys_tray.notify_general(msg=msg, title="Install", buttons=buttons) elif sys.platform == "win32": from win_tray import sys_tray if sys_tray.dialog_yes_no(msg, u"Install", None, None) == 1: install_module(module, new_version) else: ignore_module(module, new_version) elif sys.platform == "darwin": from mac_tray import sys_tray if sys_tray.presentAlert_withTitle_(msg, "Install"): install_module(module, new_version) else: ignore_module(module, new_version) else: install_module(module, new_version) break except Exception as e: xlog.warn("get gae_proxy source fail, content:%s err:%s", update_content, e)
def download_module(module, new_version): import os global update_content, update_dict current_path = os.path.dirname(os.path.abspath(__file__)) download_path = os.path.abspath( os.path.join(current_path, os.pardir, os.pardir, 'data', 'downloads')) if not os.path.isdir(download_path): os.mkdir(download_path) try: for source in update_dict["modules"][module]["versions"][new_version][ "sources"]: url = source["url"] filename = module + "-" + new_version + ".zip" file_path = os.path.join(download_path, filename) if os.path.isfile(file_path) and sha1_file( file_path) == update_dict["modules"][module]["versions"][ new_version]["sha1"]: pass elif not download_file(url, file_path): xlog.warn("download %s fail", url) continue sha1 = sha1_file(file_path) if update_dict["modules"][module]["versions"][new_version][ "sha1"] != sha1: xlog.warn("download %s sha1 wrong", url) continue module_path = os.path.abspath( os.path.join(current_path, os.pardir, os.pardir, module)) if not os.path.isdir(module_path): os.path.mkdir(module_path, "755") version_path = os.path.join(module_path, new_version) if os.path.isdir(version_path): xlog.error("module dir exist:%s, download exist.", version_path) return with zipfile.ZipFile(file_path, "r") as dz: dz.extractall(module_path) dz.close() import shutil unzip_path = os.path.abspath( os.path.join(module_path, module + "-" + new_version)) tag_path = os.path.abspath(os.path.join(module_path, new_version)) shutil.move(unzip_path, tag_path) msg = "Module %s new version %s downloaded, Install?" % ( module, new_version) if sys.platform == "linux" or sys.platform == "linux2": from gtk_tray import sys_tray data_install = "%s|%s|install" % (module, new_version) data_ignore = "%s|%s|ignore" % (module, new_version) buttons = { 1: { "data": data_install, "label": "Install", 'callback': general_gtk_callback }, 2: { "data": data_ignore, "label": "Ignore", 'callback': general_gtk_callback } } sys_tray.notify_general(msg=msg, title="Install", buttons=buttons) elif sys.platform == "win32": from win_tray import sys_tray if sys_tray.dialog_yes_no(msg, u"Install", None, None) == 1: install_module(module, new_version) else: ignore_module(module, new_version) elif sys.platform == "darwin": from mac_tray import sys_tray if sys_tray.presentAlert_withTitle_(msg, "Install"): install_module(module, new_version) else: ignore_module(module, new_version) else: install_module(module, new_version) break except Exception as e: xlog.warn("get gae_proxy source fail, content:%s err:%s", update_content, e)