def available_updates(): whattypes = config.get('behavior.check-for-addon-update-types') do_not_show_prev = config.get( 'behavior.do-not-show-previously-seen-addon-updates') prev_seen = config.get('behavior.previously-seen-addon-updates') LOG.debug("Checking for updated addons...") langs = glocale.get_language_list() langs.append("en") # now we have a list of languages to try: f_ptr = None for lang in langs: url = ("%s/listings/addons-%s.txt" % (config.get("behavior.addons-url"), lang)) LOG.debug(" trying: %s", url) try: f_ptr = urlopen_maybe_no_check_cert(url) except: try: url = ("%s/listings/addons-%s.txt" % (config.get("behavior.addons-url"), lang[:2])) f_ptr = urlopen_maybe_no_check_cert(url) except Exception as err: # some error LOG.warning("Failed to open addon metadata for %s %s: %s", lang, url, err) f_ptr = None if f_ptr and f_ptr.getcode() == 200 or f_ptr.file: # ok break try: wfp = open(os.path.join(VERSION_DIR, "new_addons.txt"), mode='wt', encoding='utf-8') except Exception as err: LOG.warning("Failed to open addon status file: %s", err) pmgr = BasePluginManager.get_instance() addon_update_list = [] if f_ptr and f_ptr.getcode() == 200 or f_ptr.file: lines = list(f_ptr.readlines()) count = 0 for line in lines: line = line.decode('utf-8') try: plugin_dict = safe_eval(line) if type(plugin_dict) != type({}): raise TypeError("Line with addon metadata is not " "a dictionary") except: LOG.warning("Skipped a line in the addon listing: " + str(line)) continue if wfp: wfp.write(str(plugin_dict) + '\n') pid = plugin_dict["i"] plugin = pmgr.get_plugin(pid) if plugin: LOG.debug("Comparing %s > %s", version_str_to_tup(plugin_dict["v"], 3), version_str_to_tup(plugin.version, 3)) if (version_str_to_tup(plugin_dict["v"], 3) > version_str_to_tup(plugin.version, 3)): LOG.debug(" Downloading '%s'...", plugin_dict["z"]) if "update" in whattypes: if (not do_not_show_prev or plugin_dict["i"] not in prev_seen): addon_update_list.append( (_("Updated"), "%s/download/%s" % (config.get("behavior.addons-url"), plugin_dict["z"]), plugin_dict)) else: LOG.debug(" '%s' is ok", plugin_dict["n"]) else: LOG.debug(" '%s' is not installed", plugin_dict["n"]) if "new" in whattypes: if (not do_not_show_prev or plugin_dict["i"] not in prev_seen): addon_update_list.append( (_("updates|New"), "%s/download/%s" % (config.get("behavior.addons-url"), plugin_dict["z"]), plugin_dict)) config.set("behavior.last-check-for-addon-updates", datetime.date.today().strftime("%Y/%m/%d")) count += 1 if f_ptr: f_ptr.close() if wfp: wfp.close() else: LOG.debug("Checking Addons Failed") LOG.debug("Done checking!") return addon_update_list
def available_updates(): whattypes = config.get('behavior.check-for-addon-update-types') do_not_show_prev = config.get( 'behavior.do-not-show-previously-seen-addon-updates') prev_seen = config.get('behavior.previously-seen-addon-updates') LOG.debug("Checking for updated addons...") langs = glocale.get_language_list() langs.append("en") # now we have a list of languages to try: f_ptr = None for lang in langs: url = ("%s/listings/addons-%s.txt" % (config.get("behavior.addons-url"), lang)) LOG.debug(" trying: %s", url) try: f_ptr = urlopen_maybe_no_check_cert(url) except: try: url = ("%s/listings/addons-%s.txt" % (config.get("behavior.addons-url"), lang[:2])) f_ptr = urlopen_maybe_no_check_cert(url) except Exception as err: # some error LOG.warning("Failed to open addon metadata for %s %s: %s", lang, url, err) f_ptr = None if f_ptr and f_ptr.getcode() == 200: # ok break try: wfp = open(os.path.join(VERSION_DIR, "new_addons.txt"), mode='wt', encoding='utf-8') except Exception as err: LOG.warning("Failed to open addon status file: %s", err) pmgr = BasePluginManager.get_instance() addon_update_list = [] if f_ptr and f_ptr.getcode() == 200: lines = list(f_ptr.readlines()) count = 0 for line in lines: line = line.decode('utf-8') try: plugin_dict = safe_eval(line) if type(plugin_dict) != type({}): raise TypeError("Line with addon metadata is not " "a dictionary") except: LOG.warning("Skipped a line in the addon listing: " + str(line)) continue if wfp: wfp.write(str(plugin_dict) + '\n') pid = plugin_dict["i"] plugin = pmgr.get_plugin(pid) if plugin: LOG.debug("Comparing %s > %s", version_str_to_tup(plugin_dict["v"], 3), version_str_to_tup(plugin.version, 3)) if (version_str_to_tup(plugin_dict["v"], 3) > version_str_to_tup(plugin.version, 3)): LOG.debug(" Downloading '%s'...", plugin_dict["z"]) if "update" in whattypes: if (not do_not_show_prev or plugin_dict["i"] not in prev_seen): addon_update_list.append( (_("Updated"), "%s/download/%s" % (config.get("behavior.addons-url"), plugin_dict["z"]), plugin_dict)) else: LOG.debug(" '%s' is ok", plugin_dict["n"]) else: LOG.debug(" '%s' is not installed", plugin_dict["n"]) if "new" in whattypes: if (not do_not_show_prev or plugin_dict["i"] not in prev_seen): addon_update_list.append( (_("updates|New"), "%s/download/%s" % (config.get("behavior.addons-url"), plugin_dict["z"]), plugin_dict)) config.set("behavior.last-check-for-addon-updates", datetime.date.today().strftime("%Y/%m/%d")) count += 1 if f_ptr: f_ptr.close() if wfp: wfp.close() else: LOG.debug("Checking Addons Failed") LOG.debug("Done checking!") return addon_update_list
def __populate_reg_list(self): """ Build list of plugins""" self.addons = [] new_addons_file = os.path.join(VERSION_DIR, "new_addons.txt") if not os.path.isfile(new_addons_file) and not static.check_done: if QuestionDialog2(TITLE, _("3rd party addons are not shown until the " "addons update list is downloaded. Would " "you like to check for updated addons now?"), _("Yes"), _("No"), parent=self.window).run(): self._check_for_updates() else: static.check_done = True try: with open(new_addons_file, encoding='utf-8') as filep: for line in filep: try: plugin_dict = safe_eval(line) if not isinstance(plugin_dict, dict): raise TypeError("Line with addon metadata is not " "a dictionary") except: # pylint: disable=bare-except LOG.warning("Skipped a line in the addon listing: " + str(line)) continue self.addons.append(plugin_dict) except FileNotFoundError: pass except Exception as err: # pylint: disable=broad-except LOG.warning("Failed to open addon status file: %s", err) addons = [] updateable = [] for plugin_dict in self.addons: pid = plugin_dict["i"] plugin = self._pmgr.get_plugin(pid) if plugin: # check for an already registered plugin LOG.debug("Comparing %s > %s", version_str_to_tup(plugin_dict["v"], 3), version_str_to_tup(plugin.version, 3)) # Check for a update if (version_str_to_tup(plugin_dict["v"], 3) > version_str_to_tup(plugin.version, 3)): LOG.debug("Update for '%s'...", plugin_dict["z"]) updateable.append(pid) else: # current plugin is up to date. LOG.debug(" '%s' is up to date", plugin_dict["n"]) else: # new addon LOG.debug(" '%s' is not installed", plugin_dict["n"]) hidden = pid in self.hidden status_str = _("*Available") status = AVAILABLE if hidden: status_str = "<s>%s</s>" % status_str status |= HIDDEN row = [_(plugin_dict["t"]), status_str, markup_escape_text(plugin_dict["n"]), markup_escape_text(plugin_dict["d"]), plugin_dict["i"], status] addons.append(row) fail_list = self._pmgr.get_fail_list() for (_type, typestr) in PTYPE_STR.items(): for pdata in self._preg.type_plugins(_type): # model: plugintype, hidden, pluginname, plugindescr, pluginid if 'gramps/plugins' in pdata.fpath.replace('\\', '/'): status_str = _("Built-in") status = BUILTIN if not self._show_builtins: continue else: status_str = _("*Installed") status = INSTALLED # i = (filename, (exception-type, exception, traceback), pdata) for i in fail_list: if pdata == i[2]: status_str += ', ' + '<span color="red">%s</span>' % \ _("Failed") break if pdata.id in updateable: status_str += ', ' + _("Update Available") status |= UPDATE hidden = pdata.id in self.hidden if hidden: status_str = "<s>%s</s>" % status_str status |= HIDDEN addons.append([typestr, status_str, markup_escape_text(pdata.name), markup_escape_text(pdata.description), pdata.id, status]) for row in sorted(addons, key=itemgetter(R_TYPE, R_NAME)): if self._show_hidden or (row[R_ID] not in self.hidden): self._model_reg.append(row) self._selection_reg.select_path('0')
def __populate_reg_list(self): """ Build list of plugins""" self.addons = [] new_addons_file = os.path.join(VERSION_DIR, "new_addons.txt") if not os.path.isfile(new_addons_file) and not static.check_done: if QuestionDialog2(TITLE, _("3rd party addons are not shown until the " "addons update list is downloaded. Would " "you like to check for updated addons now?"), _("Yes"), _("No"), parent=self.window).run(): self._check_for_updates() else: static.check_done = True try: with open(new_addons_file, encoding='utf-8') as filep: for line in filep: try: plugin_dict = safe_eval(line) if not isinstance(plugin_dict, dict): raise TypeError("Line with addon metadata is not " "a dictionary") except: # pylint: disable=bare-except LOG.warning("Skipped a line in the addon listing: " + str(line)) continue self.addons.append(plugin_dict) except FileNotFoundError: pass except Exception as err: # pylint: disable=broad-except LOG.warning("Failed to open addon status file: %s", err) addons = [] updateable = [] for plugin_dict in self.addons: pid = plugin_dict["i"] plugin = self._pmgr.get_plugin(pid) if plugin: # check for an already registered plugin LOG.debug("Comparing %s > %s", version_str_to_tup(plugin_dict["v"], 3), version_str_to_tup(plugin.version, 3)) # Check for a update if (version_str_to_tup(plugin_dict["v"], 3) > version_str_to_tup(plugin.version, 3)): LOG.debug("Update for '%s'...", plugin_dict["z"]) updateable.append(pid) else: # current plugin is up to date. LOG.debug(" '%s' is up to date", plugin_dict["n"]) else: # new addon LOG.debug(" '%s' is not installed", plugin_dict["n"]) hidden = pid in self.hidden status_str = _("*Available") status = AVAILABLE if hidden: status_str = "<s>%s</s>" % status_str status |= HIDDEN row = [_(plugin_dict["t"]), status_str, plugin_dict["n"], plugin_dict["d"], plugin_dict["i"], status] addons.append(row) fail_list = self._pmgr.get_fail_list() for (_type, typestr) in PTYPE_STR.items(): for pdata in self._preg.type_plugins(_type): # model: plugintype, hidden, pluginname, plugindescr, pluginid if 'gramps/plugins' in pdata.fpath.replace('\\', '/'): status_str = _("Built-in") status = BUILTIN if not self._show_builtins: continue else: status_str = _("*Installed") status = INSTALLED # i = (filename, (exception-type, exception, traceback), pdata) for i in fail_list: if pdata == i[2]: status_str += ', ' + '<span color="red">%s</span>' % \ _("Failed") break if pdata.id in updateable: status_str += ', ' + _("Update Available") status |= UPDATE hidden = pdata.id in self.hidden if hidden: status_str = "<s>%s</s>" % status_str status |= HIDDEN addons.append([typestr, status_str, pdata.name, pdata.description, pdata.id, status]) for row in sorted(addons, key=itemgetter(R_TYPE, R_NAME)): if self._show_hidden or (row[R_ID] not in self.hidden): self._model_reg.append(row) self._selection_reg.select_path('0')