Example #1
0
    def collect_unused(self):
        # Run through all requested tables and check all objects
        # for being referenced some place. If not, add_results on them.

        db = self.db
        tables = (
            ('events', db.get_event_cursor, db.get_number_of_events),
            ('sources', db.get_source_cursor, db.get_number_of_sources),
            ('places', db.get_place_cursor, db.get_number_of_places),
            ('media', db.get_media_cursor, db.get_number_of_media_objects),
            ('repos', db.get_repository_cursor, db.get_number_of_repositories),
            ('notes', db.get_note_cursor, db.get_number_of_notes),
        )

        for (the_type, cursor_func, total_func) in tables:
            if not self.options.handler.options_dict[the_type]:
                # This table was not requested. Skip it.
                continue

            with cursor_func() as cursor:
                self.set_total(total_func())
                fbh = db.find_backlink_handles
                for handle, data in cursor:
                    if not any(h for h in fbh(handle)):
                        self.add_results(
                            (the_type, handle2internal(handle), data))
                    self.update()
            self.reset()
Example #2
0
def run(database, document, person):
    """
    Loops through the families that the person is a child in, and display
    the information about the other children.
    """
    global cache
    cache = {}
    # setup the simple access functions
    sdb = SimpleAccess(database)
    sdoc = SimpleDoc(document)
    stab = QuickTable(sdb)
    # display the title
    sdoc.title(_("Descendant Count"))
    sdoc.paragraph("")
    stab.columns(_("Person"), _("Number of Descendants"))
    people = database.get_person_handles(sort_handles=True)
    for person_handle in people:
        result = countem(database, handle2internal(person_handle))
        cache[person_handle] = len(result)
    matches = 0
    for person_handle in cache:
        person = database.get_person_from_handle(person_handle)
        stab.row(person, cache[person_handle])
        matches += 1
    sdoc.paragraph(_("There are %d people.\n") % matches)
    stab.write(sdoc)
Example #3
0
def run(database, document, person):
    """
    Loops through the families that the person is a child in, and display
    the information about the other children.
    """
    global cache
    cache = {}
    # setup the simple access functions
    sdb = SimpleAccess(database)
    sdoc = SimpleDoc(document)
    stab = QuickTable(sdb)
    # display the title
    sdoc.title(_("Descendant Count"))
    sdoc.paragraph("")
    stab.columns(_("Person"), _("Number of Descendants"))
    people = database.get_person_handles(sort_handles=True)
    for person_handle in people:
        result = countem(database, handle2internal(person_handle))
        cache[person_handle] = len(result)
    matches = 0
    for person_handle in cache:
        person = database.get_person_from_handle(person_handle)
        stab.row(person, cache[person_handle])
        matches += 1
    sdoc.paragraph(_("There are %d people.\n") % matches)
    stab.write(sdoc)
Example #4
0
    def collect_unused(self):
        # Run through all requested tables and check all objects
        # for being referenced some place. If not, add_results on them.

        db = self.db
        tables = (
            ('events', db.get_event_cursor, db.get_number_of_events),
            ('sources', db.get_source_cursor, db.get_number_of_sources),
            ('places', db.get_place_cursor, db.get_number_of_places),
            ('media', db.get_media_cursor, db.get_number_of_media_objects),
            ('repos', db.get_repository_cursor, db.get_number_of_repositories),
            ('notes', db.get_note_cursor, db.get_number_of_notes),
            )

        for (the_type, cursor_func, total_func) in tables:
            if not self.options.handler.options_dict[the_type]:
                # This table was not requested. Skip it.
                continue

            with cursor_func() as cursor:
                self.set_total(total_func())
                fbh = db.find_backlink_handles
                for handle, data in cursor:
                    if not any(h for h in fbh(handle)):
                        self.add_results((the_type, handle2internal(handle),
                                          data))
                    self.update()
            self.reset()
Example #5
0
    def undo_data(self, data, handle, db_map, emit, signal_root):
        """
        Helper method to undo/redo the changes made
        """
        try:
            if data is None:
                emit(signal_root + '-delete', ([handle2internal(handle)], ))
                db_map.delete(handle, txn=self.txn)
            else:
                ex_data = db_map.get(handle, txn=self.txn)
                if ex_data:
                    signal = signal_root + '-update'
                else:
                    signal = signal_root + '-add'
                db_map.put(handle, data, txn=self.txn)
                emit(signal, ([handle2internal(handle)], ))

        except DBERRS as msg:
            self.db._log_error()
            raise DbError(msg)
Example #6
0
    def undo_data(self, data, handle, db_map, emit, signal_root):
        """
        Helper method to undo/redo the changes made
        """
        try:
            if data is None:
                emit(signal_root + '-delete', ([handle2internal(handle)],))
                db_map.delete(handle, txn=self.txn)
            else:
                ex_data = db_map.get(handle, txn=self.txn)
                if ex_data:
                    signal = signal_root + '-update'
                else:
                    signal = signal_root + '-add'
                db_map.put(handle, data, txn=self.txn)
                emit(signal, ([handle2internal(handle)],))

        except DBERRS as msg:
            self.db._log_error()
            raise DbError(msg)
Example #7
0
 def __add_place(self, name, type_num, parent, title, trans):
     """
     Add a missing place to the database.
     """
     place = Place()
     place.name = name
     place.title = title
     place.place_type = PlaceType(7 - type_num)
     if parent is not None:
         placeref = PlaceRef()
         placeref.ref = handle2internal(parent)
         place.set_placeref_list([placeref])
     handle = self.db.add_place(place, trans)
     self.db.commit_place(place, trans)
     return handle
Example #8
0
 def __add_place(self, name, type_num, parent, title, trans):
     """
     Add a missing place to the database.
     """
     place = Place()
     place_name = PlaceName()
     place_name.set_value(name)
     place.name = place_name
     place.title = title
     place.place_type = PlaceType(7-type_num)
     if parent is not None:
         placeref = PlaceRef()
         placeref.ref = handle2internal(parent)
         place.set_placeref_list([placeref])
     handle = self.db.add_place(place, trans)
     self.db.commit_place(place, trans)
     return handle
Example #9
0
    def generate_hierarchy(self, trans):
        """
        Generate missing places in the place hierarchy.
        """
        for handle, location in self.handle2loc.items():

            # find title and type
            for type_num, name in enumerate(location):
                if name:
                    break
            
            loc = list(location)
            loc[type_num] = ''

            # find top parent
            parent = None
            for n in range(7):
                if loc[n]:
                    tup = tuple([''] * n + loc[n:])
                    parent = self.loc2handle.get(tup)
                    if parent:
                        break

            # create missing parent places
            if parent:
                n -= 1
            while n > type_num:
                if loc[n]:
                    title = ', '.join([item for item in loc[n:] if item])
                    parent = self.__add_place(loc[n], n, parent, title, trans)
                    self.loc2handle[tuple([''] * n + loc[n:])] = parent
                n -= 1

            # link to existing place
            if parent:
                place = self.db.get_place_from_handle(handle)
                placeref = PlaceRef()
                placeref.ref = handle2internal(parent)
                place.set_placeref_list([placeref])
                self.db.commit_place(place, trans, place.get_change_time())