def check_for_next_version(*args, **kwargs): '''Attempt to fetch the __init__.py file from github, and check if it corresponds to a new release. If so, warn the user (exactly once per version). This function is called on exit.''' def is_newer(a, b): 'compares version strings in the form "0.7.3"' version_re = r"(\d+)\.(\d+)\.(\d+).*" ra = re.search(version_re, a) rb = re.search(version_re, b) if int(ra.group(1))>int(rb.group(1)): return True elif int(ra.group(2))>int(rb.group(2)): return True elif int(ra.group(3))>int(rb.group(3)): return True else: return False try: #fetch the latest release on Github. This means github must be updated *after* Ankiweb latest_data = urllib2.urlopen('https://raw.github.com/ttempe/chinese-support-addon/master/chinese/__init__.py', timeout=7).read() latest_version = re.search(r"__version__\s*=\s*\"\"\"(.*?)\"\"\"", latest_data).group(1) latest_comment = re.search(r"release_info\s*=\s*\"\"\"(.*?)\"\"\"", latest_data, re.S).group(1) import __init__ local_version = __init__.__version__ if is_newer(latest_version, local_version): if chinese_support_config.options["latest_available_version"] <> latest_version: chinese_support_config.set_option("latest_available_version", latest_version) chinese_support_config.set_option("next_version_message", "A new version of <b>Chinese Support Add-on</b> is available.<br>You can download it through <tt>Tools->Add-ons->Browse and install</tt>.<br> <br><b>Version "+latest_version+":</b><br>"+latest_comment) except: pass
def set_dict(dict_name): #First, try out the designated dictionary, then save. #If it fails, offer the user to install dict global installing_dict try: init_dict(dict_name) chinese_support_config.set_option('dictionary', dict_name) return True except ValueError: try: if askUser(_("This dictionary will be downloaded from the Internet now.<br>This will take a few minutes<br>Do you want to continue?")): installing_dict = dict_name install_dict(dict_name) except: pass return False
def set_dict(dict_name): #First, try out the designated dictionary, then save. #If it fails, offer the user to install dict global installing_dict try: init_dict(dict_name) chinese_support_config.set_option('dictionary', dict_name) return True except ValueError: try: if askUser(_("This dictionary will be downloaded from the Internet now.<br>This will take a few minutes<br>Do you want to continue?")): installing_dict = dict_name install_dict(dict_name) except: pass return False
def display_new_version_message(): #Only show message on next startup if chinese_support_config.options["next_version_message"]: if offer_auto_module_upgrade: if askUser(chinese_support_config.options["next_version_message"]): if do_upgrade(): #success chinese_support_config.set_option("next_version_message", None) else: #User does not want to be bothered with upgrades chinese_support_config.set_option("next_version_message", None) else: #no auto upgrade showInfo(chinese_support_config.options["next_version_message"]) chinese_support_config.set_option("next_version_message", None)
def display_new_version_message(): #Only show message on next startup if chinese_support_config.options["next_version_message"]: if offer_auto_module_upgrade: if askUser(chinese_support_config.options["next_version_message"]): if do_upgrade(): #success chinese_support_config.set_option("next_version_message", None) else: #User does not want to be bothered with upgrades chinese_support_config.set_option("next_version_message", None) else: #no auto upgrade showInfo(chinese_support_config.options["next_version_message"]) chinese_support_config.set_option("next_version_message", None)
def set_option(): chinese_support_config.set_option(option, value) update_dict_action_checkboxes()
def set_dict(): chinese_support_config.set_option("dictionary", dict) update_dict_action_checkboxes()
def install_finished(): mw.progress.finish() showInfo(_("Install succeeded<br>Please restart Anki now for your dictionary settings to take effect.")) chinese_support_config.set_option('dictionary', installing_dict) ui.update_dict_action_checkboxes()
def update_config(): chinese_support_config.set_option("add-on version", __version__) chinese_support_config.set_option("edit_behavior_model.py hash", md5.new(open(edit_behavior_model).read()).hexdigest())
self.emit(SIGNAL('install_failed')) def install_failed(): mw.progress.finish() showWarning(_("There was an error during dictionary download.<br>Please try again later.")) def install_finished(): mw.progress.finish() showInfo(_("Install succeeded<br>Please restart Anki now for your dictionary settings to take effect.")) chinese_support_config.set_option('dictionary', installing_dict) ui.update_dict_action_checkboxes() t = None def install_dict(dict): global t mw.progress.start(immediate=True) t = installerThread(dict) QObject.connect(t, SIGNAL('install_finished'), install_finished, QtCore.Qt.QueuedConnection) QObject.connect(t, SIGNAL('install_failed'), install_failed, QtCore.Qt.QueuedConnection) t.start() try: init_dict(chinese_support_config.options["dictionary"]) except: showWarning(_("The current dictionary for Chinese Support Add-on does not seem to be properly installed. Please re-select your dictionary from the list.")) chinese_support_config.set_option('dictionary', "None")
def toggleButtonClick(): global enable enable = not enable config.set_option(config_file_key, enable) updateToggleButton(editor_instance)
def set_dict(): chinese_support_config.set_option("dictionary", dict) update_dict_action_checkboxes()
def update_config(): chinese_support_config.set_option("add-on version", __version__) chinese_support_config.set_option( "edit_behavior_model.py hash", md5.new(open(edit_behavior_model).read()).hexdigest())
def install_finished(): mw.progress.finish() showInfo(_("Install succeeded<br>Please restart Anki now for your dictionary settings to take effect.")) chinese_support_config.set_option('dictionary', installing_dict) ui.update_dict_action_checkboxes()
self.emit(SIGNAL('install_failed')) def install_failed(): mw.progress.finish() showWarning(_("There was an error during dictionary download.<br>Please try again later.")) def install_finished(): mw.progress.finish() showInfo(_("Install succeeded<br>Please restart Anki now for your dictionary settings to take effect.")) chinese_support_config.set_option('dictionary', installing_dict) ui.update_dict_action_checkboxes() t = None def install_dict(dict): global t mw.progress.start(immediate=True) t = installerThread(dict) QObject.connect(t, SIGNAL('install_finished'), install_finished, QtCore.Qt.QueuedConnection) QObject.connect(t, SIGNAL('install_failed'), install_failed, QtCore.Qt.QueuedConnection) t.start() try: init_dict(chinese_support_config.options["dictionary"]) except: showWarning(_("The current dictionary for Chinese Support Add-on does not seem to be properly installed. Please re-select your dictionary from the list.")) chinese_support_config.set_option('dictionary', "None")
def toggleButtonClick(): global enable enable = not enable config.set_option(config_file_key, enable) updateToggleButton(editor_instance)
def display_new_version_message(): #Only show message on next startup #Only show message once for each version if chinese_support_config.options["next_version_message"]: showInfo(chinese_support_config.options["next_version_message"]) chinese_support_config.set_option("next_version_message", None)
def set_option(): chinese_support_config.set_option(option, value) update_dict_action_checkboxes()