Esempio n. 1
0
def import_as_dict(filename, user=None):
    """
    Import the filename into a InMemoryDB and return it.
    """
    if user is None:
        user = User()
    db = make_database("inmemorydb")
    db.load(None)
    db.set_feature("skip-import-additions", True)
    dbstate = DbState()
    climanager = CLIManager(dbstate, setloader=False, user=user)
    climanager.do_reg_plugins(dbstate, None)
    pmgr = BasePluginManager.get_instance()
    (name, ext) = os.path.splitext(os.path.basename(filename))
    format = ext[1:].lower()
    import_list = pmgr.get_reg_importers()
    for pdata in import_list:
        if format == pdata.extension:
            mod = pmgr.load_plugin(pdata)
            if not mod:
                for item in pmgr.get_fail_list():
                    name, error_tuple, pdata = item
                    # (filename, (exception-type, exception, traceback), pdata)
                    etype, exception, traceback = error_tuple
                    #print("ERROR:", name, exception)
                return False
            import_function = getattr(mod, pdata.import_function)
            results = import_function(db, filename, user)
            if results is None:
                return None
            return db
    return None
Esempio n. 2
0
def import_as_dict(filename, user=None):
    """
    Import the filename into a InMemoryDB and return it.
    """
    if user is None:
        user = User()
    db = make_database("inmemorydb")
    db.load(None)
    db.set_feature("skip-import-additions", True)
    dbstate = DbState()
    climanager = CLIManager(dbstate, setloader=False, user=user)
    climanager.do_reg_plugins(dbstate, None)
    pmgr = BasePluginManager.get_instance()
    (name, ext) = os.path.splitext(os.path.basename(filename))
    format = ext[1:].lower()
    import_list = pmgr.get_reg_importers()
    for pdata in import_list:
        if format == pdata.extension:
            mod = pmgr.load_plugin(pdata)
            if not mod:
                for item in pmgr.get_fail_list():
                    name, error_tuple, pdata = item
                    # (filename, (exception-type, exception, traceback), pdata)
                    etype, exception, traceback = error_tuple
                    #print("ERROR:", name, exception)
                return False
            import_function = getattr(mod, pdata.import_function)
            results = import_function(db, filename, user)
            if results is None:
                return None
            return db
    return None
Esempio n. 3
0
    def setUp(self):
        db = make_database("inmemorydb")
        db.load(None)
        with db.get_transaction_class()("Test", db) as trans:
            # Add some people:
            person1 = Person()
            person1.primary_name = Name()
            person1.primary_name.surname_list.append(Surname())
            person1.primary_name.surname_list[0].surname = "Smith"
            person1.gramps_id = "I0001"
            db.add_person(person1, trans)  # person gets a handle

            # Add some families:
            family1 = Family()
            family1.father_handle = person1.handle
            family1.gramps_id = "F0001"
            db.add_family(family1, trans)
        self.db = db
Esempio n. 4
0
    def setUp(self):
        db = make_database("inmemorydb")
        db.load(None)
        with db.get_transaction_class()("Test", db) as trans:
            # Add some people:
            person1 = Person()
            person1.primary_name = Name()
            person1.primary_name.surname_list.append(Surname())
            person1.primary_name.surname_list[0].surname = "Smith"
            person1.gramps_id = "I0001"
            db.add_person(person1, trans) # person gets a handle

            # Add some families:
            family1 = Family()
            family1.father_handle = person1.handle
            family1.gramps_id = "F0001"
            db.add_family(family1, trans)
        self.db = db
Esempio n. 5
0
 def setUpClass(cls):
     cls.db = make_database("inmemorydb")
     cls.db.load(None)