Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
def listing(LANG):
    """
    Listing files ../listing/{lang}.fr
    """

    if 'GRAMPSPATH' in os.environ:
        GRAMPSPATH = os.environ['GRAMPSPATH']
    else:
        GRAMPSPATH = '../../../..'

    try:
        sys.path.insert(0, GRAMPSPATH)
        os.environ['GRAMPS_RESOURCES'] = os.path.abspath(GRAMPSPATH)
        from gramps.gen.const import GRAMPS_LOCALE as glocale
        from gramps.gen.plug import make_environment, PTYPE_STR
    except ImportError:
        raise ValueError("Where is 'GRAMPSPATH' or 'GRAMPS_RESOURCES'?")

    LOCALE = glocale.get_language_list()

    compilation_all('ALL')

    listings = []
    need = False

    # change the method

    fp = open('../listings/addons-%s.txt' % LANG, 'w')

    for addon in sorted(ADDONS):

        tgz_file = '%s.addon.tgz' % addon
        tgz_exists = os.path.isfile('../download/' + tgz_file)
        gprs = glob.glob('%(addon)s/*gpr.py' % {'addon': addon})
        for gpr in gprs:
            gpr_file = gpr
            print(gpr_file, gprs)
            gpr_exists = os.path.isfile(gpr_file)

        mo_file = "%s/locale/%s/LC_MESSAGES/addon.mo" % (addon, LANG)
        mo_exists = os.path.isfile(mo_file)

        if tgz_exists and gpr_exists:
            gpr = open(gpr_file.encode('utf-8', errors='backslashreplace'))

            plug = dict([file.strip(), None] for file in gpr if file.strip())

            name = ident = ptype = description = version = target = ''

            if mo_exists:
                LANGUAGE = LANG + ".UTF-8"
            else:
                LANGUAGE = os.environ['LANGUAGE']

            # print(plug)

            for p in plug:

                # print(repr(p))

                if repr(p).startswith("'register("):
                    ptype = p.replace("register(", "")
                    ptype = ptype.replace(",", "")

                    # incomplete dirty hack!

                    print(glocale._get_translation(), LANG + ".UTF-8")

                    if LANG != LOCALE[0]:
                        # mixup between LOCALE[0] and 'en' (avoid corruption)
                        # need 'en.UTF-8' !
                        local_gettext = glocale.get_addon_translator(
                            gpr_file, languages=[LANGUAGE]).ugettext
                        #return
                    else:
                        local_gettext = glocale.get_addon_translator(
                            gpr_file, languages=[LANG, "en"]).ugettext
                        ptype = make_environment(_=local_gettext)[ptype]

                    # need to match translations build by Gramps program

                    try:
                        ptype = PTYPE_STR[ptype]
                    except:
                        # fallback and corruption with LOCALE[0]
                        print(' wrong PTYPE: %s' % ptype)
                        print(local_gettext(
                            'Tool'))  # always corrupted by the locale
                        print(
                            "LANGUAGE='%(language)s', LANG='%(lang)s'" % {
                                'language': os.environ['LANGUAGE'],
                                'lang': os.environ['LANG']
                            })
                        return

                if not (repr(p).startswith("'include_in_listing = False,")
                        or repr(p).startswith("'status = UNSTABLE,")):
                    need = True
                else:
                    print("Ignoring: '%s'" % addon)

                if repr(p).startswith("'id") or repr(p).startswith('"id'):
                    ident = p.replace('id', '')
                    ident = ident.replace('=', '')
                    ident = ident.replace(',', '')
                    ident = ident.strip()
                    #ident = repr(ident)

                if repr(p).startswith("'name") \
                    or repr(p).startswith('"name'):
                    name = p.replace('name', '')
                    name = name.replace('=', '')
                    name = name.replace(',', '')
                    name = name.strip()
                    name = name.replace('_(', '')
                    name = name.replace(')', '')
                    name = name.replace('"', '')
                    name = glocale._get_translation().ugettext(name)
                    try:
                        if name == local_gettext(name):
                            print(addon, name, local_gettext(name))
                        name = repr(local_gettext(name))
                    except:
                        print('Cannot use local_gettext on', repr(p))
                    # ugly workaround for name_accell (Export GEDCOM Extensions)
                    name = name.replace('_accell   ', '')
                    name = name.replace('(GED2', '(GED2)')

                if repr(p).startswith("'description"):
                    description = p.replace('description', '')
                    description = description.replace('=', '')
                    description = description.replace(',', '')
                    description = description.strip()
                    description = description.replace('_(', '')
                    description = description.replace(')', '')
                    description = description.replace('"', '')
                    description = glocale._get_translation().ugettext(
                        description)
                    try:
                        if description == local_gettext(description):
                            print(addon, description,
                                  local_gettext(description))
                        description = repr(local_gettext(description))
                    except:
                        print('Cannot use local_gettext on', repr(p))

                if repr(p).startswith('"version'):
                    version = p.replace('version', '')
                    version = version.replace('=', '')
                    version = version.replace(',', '')
                    version = version.replace("'", "")
                    version = version.replace('"', '')
                    version = version.strip()
                    version = repr(version)

            # workaround #7395~c38994
            if description == '':
                description = "''"
                print(description, addon)

            if need:
                plugin = {
                    'n': name,
                    'i': ident,
                    't': repr(ptype),
                    'd': description,
                    'v': version,
                    'g': "'4.2'",
                    'z': repr(tgz_file),
                }

                #if name or ident or version or target == "":
                #print(plugin)

                fp.write(
                    '{"t":%(t)s,"i":%(i)s,"n":%(n)s,"v":%(v)s,"g":%(g)s,"d":%(d)s,"z":%(z)s}\n'
                    % plugin)

                # print(plugin)

                listings.append(plugin)

        # for plugin in sorted(listings, key=lambda p: p["z"]):
        # fp.write('{"t":%(t)s,"i":%(i)s,"n":%(n)s,"v":%(v)s,"g":%(g)s,"d":%(d)s,"z":%(z)s}\n' % plugin)

    fp.close()
Esempio n. 4
0
def listing(LANG):
    """
    Listing files ../listing/{lang}.fr
    """

    if 'GRAMPSPATH' in os.environ:
        GRAMPSPATH = os.environ['GRAMPSPATH']
    else:
        GRAMPSPATH = '../../../..'

    try:
        sys.path.insert(0, GRAMPSPATH)
        os.environ['GRAMPS_RESOURCES'] = os.path.abspath(GRAMPSPATH)
        from gramps.gen.const import GRAMPS_LOCALE as glocale
        from gramps.gen.plug import make_environment, PTYPE_STR
    except ImportError:
        raise ValueError("Where is 'GRAMPSPATH' or 'GRAMPS_RESOURCES'?")

    LOCALE = glocale.get_language_list()

    compilation_all('ALL')

    listings = []
    need = False

    # change the method

    fp = open('../listings/addons-%s.txt' % LANG, 'w')

    for addon in sorted(ADDONS):

        tgz_file = '%s.addon.tgz' % addon
        tgz_exists = os.path.isfile('../download/' + tgz_file)
        gprs = glob.glob('%(addon)s/*gpr.py' % {'addon': addon})
        for gpr in gprs:
            gpr_file = gpr
            print(gpr_file, gprs)
            gpr_exists = os.path.isfile(gpr_file)

        mo_file = "%s/locale/%s/LC_MESSAGES/addon.mo" % (addon, LANG)
        mo_exists = os.path.isfile(mo_file)

        if tgz_exists and gpr_exists:
            gpr = open(gpr_file.encode('utf-8',
                       errors='backslashreplace'))

            plug = dict([file.strip(), None] for file in gpr
                        if file.strip())

            name = ident = ptype = description = version = target = ''

            if mo_exists:
                LANGUAGE = LANG +".UTF-8"
            else:
                LANGUAGE = os.environ['LANGUAGE']

            # print(plug)

            for p in plug:

                # print(repr(p))

                if repr(p).startswith("'register("):
                    ptype = p.replace("register(", "")
                    ptype = ptype.replace(",", "")

                    # incomplete dirty hack!

                    print(glocale._get_translation(), LANG+".UTF-8")

                    if LANG != LOCALE[0]:
                        # mixup between LOCALE[0] and 'en' (avoid corruption)
                        # need 'en.UTF-8' !
                        local_gettext = glocale.get_addon_translator(gpr_file, languages=[LANGUAGE]).ugettext
                        #return
                    else:
                        local_gettext = glocale.get_addon_translator(gpr_file, languages=[LANG, "en"]).ugettext
                        ptype = make_environment(_ = local_gettext)[ptype]

                    # need to match translations build by Gramps program

                    try:
                        ptype = PTYPE_STR[ptype]
                    except:
                        # fallback and corruption with LOCALE[0]
                        print(' wrong PTYPE: %s' % ptype)
                        print(local_gettext('Tool')) # always corrupted by the locale
                        print("LANGUAGE='%(language)s', LANG='%(lang)s'" % {'language': os.environ['LANGUAGE'], 'lang': os.environ['LANG']})
                        return

                if not (repr(p).startswith("'include_in_listing = False,"
                        ) or repr(p).startswith("'status = UNSTABLE,")):
                    need = True
                else:
                    print("Ignoring: '%s'" % addon)

                if repr(p).startswith("'id") or repr(p).startswith('"id'
                        ):
                    ident = p.replace('id', '')
                    ident = ident.replace('=', '')
                    ident = ident.replace(',', '')
                    ident = ident.strip()
                    #ident = repr(ident)

                if repr(p).startswith("'name") \
                    or repr(p).startswith('"name'):
                    name = p.replace('name', '')
                    name = name.replace('=', '')
                    name = name.replace(',', '')
                    name = name.strip()
                    name = name.replace('_(', '')
                    name = name.replace(')', '')
                    name = name.replace('"', '')
                    name = glocale._get_translation().ugettext(name)
                    try:
                        if name == local_gettext(name):
                            print(addon, name, local_gettext(name))
                        name = repr(local_gettext(name))
                    except:
                        print('Cannot use local_gettext on', repr(p))
                    # ugly workaround for name_accell (Export GEDCOM Extensions)
                    name = name.replace('_accell   ', '')
                    name = name.replace('(GED2', '(GED2)')

                if repr(p).startswith("'description"):
                    description = p.replace('description', '')
                    description = description.replace('=', '')
                    description = description.replace(',', '')
                    description = description.strip()
                    description = description.replace('_(', '')
                    description = description.replace(')', '')
                    description = description.replace('"', '')
                    description = glocale._get_translation().ugettext(description)
                    try:
                        if description == local_gettext(description):
                            print(addon, description, local_gettext(description))
                        description = repr(local_gettext(description))
                    except:
                        print('Cannot use local_gettext on', repr(p))

                if repr(p).startswith('"version'):
                    version = p.replace('version', '')
                    version = version.replace('=', '')
                    version = version.replace(',', '')
                    version = version.replace("'", "")
                    version = version.replace('"', '')
                    version = version.strip()
                    version = repr(version)

            # workaround #7395~c38994
            if description == '':
                description = "''"
                print(description, addon)

            if need:
                plugin = {
                    'n': name,
                    'i': ident,
                    't': repr(ptype),
                    'd': description,
                    'v': version,
                    'g': "'4.2'",
                    'z': repr(tgz_file),
                    }

                #if name or ident or version or target == "":
                    #print(plugin)

                fp.write('{"t":%(t)s,"i":%(i)s,"n":%(n)s,"v":%(v)s,"g":%(g)s,"d":%(d)s,"z":%(z)s}\n'
                          % plugin)

                # print(plugin)

                listings.append(plugin)

        # for plugin in sorted(listings, key=lambda p: p["z"]):
            # fp.write('{"t":%(t)s,"i":%(i)s,"n":%(n)s,"v":%(v)s,"g":%(g)s,"d":%(d)s,"z":%(z)s}\n' % plugin)

    fp.close()