Conflicts when register several imports with the same extension

Im trying create some imports. They are registered successfully. But the problem is that always executes the first found xslx import. In current case this is UA Birth Import. I also tried select file type, but it doesnt help.

I can not change types from xlsx to something like death.xslx, because then import openpyxl throws an exception. I also can not register extensions in a way like extension=‘death.xlsx’ because I receive another Gramps error that it doesnt have addons with xlsx extension.

register(IMPORT,
         id='UABirthImport',
         name=_('UA Birth Import'),
         description=_('Imports Birth from xlsx files'),
         version='1.0.0',
         gramps_target_version='5.2',
         status=STABLE,
         fname='UABirthImport.py',
         import_function='import_data',
         extension='xlsx'
)

register(IMPORT,
         id='UAMarriageImport',
         name=_('UA Marriage Import'),
         description=_('Imports Marriage from xlsx files'),
         version='1.0.0',
         gramps_target_version='5.2',
         status=STABLE,
         fname='UAMarriageImport.py',
         import_function='import_data',
         extension='xlsx'
)

register(IMPORT,
         id='UADeathImport',
         name=_('UA Death Import'),
         description=_('Imports Death from xlsx files'),
         version='1.0.0',
         gramps_target_version='5.2',
         status=STABLE,
         fname='UADeathImport.py',
         import_function='import_data',
         extension='xlsx'
)

How can I use 3 separate imports? I beleave there is a valid way because multiple gramplets can use the same extension. But how deny to Gramps autodetecting? Or how would you do this?

In the import_function for the Gramps 5.3 registration for the built-in importer plug-ins, I see mostly "importData". Your registrations have “import_Data”

Harmonizing that is probably a starting point.

Although there is one “impData” (for Gramps package) and one “_importData” (for Pro-Gen)

1 Like

I appreciate your question.

I am curious about the same thing for possibly adapting the vCard importer. (Gramps only supports the version 3 of vCard while my smart phone only exports the 2.1 version.)

It also seems like version support will be an issue when a GEDCOM7 import plug-in is developed.

1 Like

I solved my problem by removing two others registers

register(IMPORT,
         id='UAImport',
         name=_('UA Import'),
         description=_('Imports from xlsx files'),
         version='1.0.0',
         gramps_target_version='5.2',
         status=STABLE,
         fname='UAImport.py',
         import_function='import_data',
         extension='xlsx'
)

Now I check import type inside import_data

def import_data(database, filename, user):
    try:
        workbook = openpyxl.load_workbook(filename)
        sheet = workbook["Main"]

        if "birth" in filename.lower():
            importer = UABirthImport(sheet)
            data = importer.process_data()
        elif "marriage" in filename.lower():
            importer = UAMarriageImport(sheet)
            data = importer.process_data()
        elif "death" in filename.lower():
            importer = UADeathImport(sheet)
            data = importer.process_data()
            pretty_print_data(data)
        else:

But what will happen when I will install another third-party addon with the same xlsx registered extension? which one import will trigger first? I dont understand.

1 Like

I will check also in naming rules have some affect to the current problem, but looks like it doesnt matter. I’ll try, thank you for the answers!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.