Example #1
0
def update_listings():
    def register(ptype, **kwargs):
        #global plugins
        # need to take care of translated types
        kwargs["ptype"] = PTYPE_STR[ptype]
        plugins.append(SimpleNamespace(**kwargs))

    listings = defaultdict(list)
    for addon in get_addons():
        gprfile = find_gprfile(addon)
        for lang in languages:
            plugins = []
            local_gettext = glocale.get_addon_translator(
                gprfile, languages=[lang, "en.UTF-8"]).gettext
            with open(gprfile) as f:
                code = compile(f.read(), gprfile, 'exec')
                exec(code, make_environment(_=local_gettext), {
                    "register": register,
                    "build_script": True
                })
            for p in plugins:
                #print(p)
                for gver, grampsver in grampsversions:
                    if addon.startswith("_") and gver == "5.0":
                        continue
                    tgz = get_tgz(addon, grampsver)
                    tgzfile = f"{addon}.addon.tgz"
                    d = dict(
                        t=p.ptype,
                        i=p.id,
                        n=p.name,
                        v=p.version,
                        g=gver,  # p.gramps_target_version,
                        d=p.description,
                        z=tgzfile)
                    #print(d)
                    listings[(grampsver, lang)].append(d)

    for gver, grampsver in grampsversions:
        print()
        print(grampsver)
        for lang in languages:
            listing = listings[(grampsver, lang)]
            listing_file = get_listing(grampsver, lang)
            print("-", listing_file)
            with open(listing_file, "w") as f:
                for d in listing:
                    print(d, file=f)
Example #2
0
    for line in fp_in:
        dictionary = eval(line)
        if dictionary["i"] in addons:
            print("Repeated addon ID:", dictionary["i"])
        else:
            addons[dictionary["i"]] = dictionary
    # go through all gpr's, check their build versions
    for gpr in glob.glob(r('''*/*.gpr.py''')):
        local_gettext = glocale.get_addon_translator(
            gpr, languages=["en", "en.UTF-8"]).gettext
        plugins = []
        with open(gpr.encode("utf-8", errors="backslashreplace")) as f:
            code = compile(f.read(),
                           gpr.encode("utf-8", errors="backslashreplace"),
                           'exec')
            exec(code, make_environment(_=local_gettext),
                 {"register": register})
        for p in plugins:
            gpr_version = p.get("version", None)
            id = p.get("id", None)
            if id not in addons:
                print("Missing in listing:", id)
            else:
                add_version = addons[id]["v"]
                if gpr_version != add_version:
                    print("Different versions:", id, gpr_version, add_version)
                    # if number diff from gpr, report it
elif command == "listing":
    try:
        sys.path.insert(0, GRAMPSPATH)
        os.environ['GRAMPS_RESOURCES'] = os.path.abspath(GRAMPSPATH)
Example #3
0
            plugins.append(kwargs)

        for addon in dirs:
            fnames = glob.glob("%s/*.py" % addon)
            if not fnames:
                continue
            # check if we need to initialize based on listing
            listed = False
            for gpr in glob.glob(r('''%(addon)s/*.gpr.py''')):
                plugins = []
                with open(gpr.encode("utf-8", errors="backslashreplace")) as f:
                    code = compile(
                        f.read(), gpr.encode("utf-8",
                                             errors="backslashreplace"),
                        'exec')
                    exec(code, make_environment(_=lambda x: x), {
                        "register": register,
                        "build_script": True
                    })
                for p in plugins:
                    if p.get("include_in_listing", True):
                        listed = True  # got at least one listable plugin
            if not listed:
                continue  # skip this one if not listed

            mkdir("%(addon)s/po")
            system('''xgettext --language=Python --keyword=_ --keyword=N_'''
                   ''' --from-code=UTF-8'''
                   ''' -o "%(addon)s/po/template.pot" "%(addon)s"/*.py ''')
            fnames = glob.glob("%s/*.glade" % addon)
            if fnames:
Example #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()
Example #5
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()