* src/plugins/WebPage.py: media reference fixes

* src/plugins/ReadGedcom.py: media reference fixes
* src/plugins/IndivSummary.py: media reference fixes
* src/plugins/IndivComplete.py: media reference fixes
* src/plugins/DetAncestralReport.py: media reference fixes
* src/plugins/DetDescendantReport.py: media reference fixes
* src/plugins/Check.py: media reference fixes
* src/gramps_main.py: media reference fixes
* src/Utils.py: gnome.vfs vs. grampslib
* src/RelLib.py: single db file, media reference fixes
* src/MediaView.py: media reference fixes


svn: r2911
This commit is contained in:
Don Allingham 2004-02-25 03:25:57 +00:00
parent bbe933fd73
commit ebed4e0f5f
11 changed files with 85 additions and 58 deletions

View File

@ -253,7 +253,7 @@ class MediaView:
object_keys = self.db.get_object_keys()
for src_key in object_keys:
src = self.db.get_object(src_key)
src = self.db.find_object_from_id(src_key)
title = src.get_description()
id = src.get_id()
type = Utils.get_mime_description(src.get_mime_type())
@ -307,22 +307,22 @@ class MediaView:
def is_object_used(self,mobj):
for p in self.db.get_family_id_map().values():
for o in p.get_media_list():
if o.get_reference() == mobj:
if o.get_reference_id() == mobj.get_id():
return 1
for key in self.db.get_person_keys():
p = self.db.get_person(key)
for o in p.get_media_list():
if o.get_reference() == mobj:
if o.get_reference_id() == mobj.get_id():
return 1
for key in self.db.get_source_keys():
p = self.db.get_source(key)
for o in p.get_media_list():
if o.get_reference() == mobj:
if o.get_reference_id() == mobj.get_id():
return 1
for key in self.db.get_place_id_keys():
p = self.db.get_place_id(key)
for o in p.get_media_list():
if o.get_reference() == mobj:
if o.get_reference_id() == mobj.get_id():
return 1
return 0

View File

@ -691,10 +691,10 @@ class MediaRef:
"""Returns the privacy level of the data"""
return self.private
def set_reference(self,obj):
self.ref = obj
def set_reference_id(self,obj_id):
self.ref = obj_id
def get_reference(self):
def get_reference_id(self):
return self.ref
def set_note(self,text):
@ -2258,6 +2258,10 @@ try: # First try python2.3 and later: this is the future
except ImportError: # try python2.2
from bsddb3 import dbshelve, db
def find_surname(key,data):
return str(data[2].get_surname())
class GrampsDB:
"""GRAMPS database object. This object is a base class for other
objects."""
@ -2265,14 +2269,24 @@ class GrampsDB:
def __init__(self):
"""creates a new GrampsDB"""
self.person_map = dbshelve.open('person.db', dbname="people", filetype=db.DB_BTREE)
self.family_map = dbshelve.open('family.db', dbname="family", filetype=db.DB_BTREE)
self.place_map = dbshelve.open('place.db', dbname="places", filetype=db.DB_BTREE)
self.source_map = dbshelve.open('source.db', dbname="sources",filetype=db.DB_BTREE)
self.media_map = dbshelve.open('media.db', dbname="media", filetype=db.DB_BTREE)
self.event_map = dbshelve.open('event.db', dbname="events", filetype=db.DB_BTREE)
self.env = db.DBEnv()
flags = db.DB_CREATE|db.DB_INIT_MPOOL
self.env.open(".", flags)
self.person_map = dbshelve.open('person.db', dbname="person", dbenv=self.env)
self.family_map = dbshelve.open('person.db', dbname="family", dbenv=self.env)
self.place_map = dbshelve.open('person.db', dbname="places", dbenv=self.env)
self.source_map = dbshelve.open('person.db', dbname="sources",dbenv=self.env)
self.media_map = dbshelve.open('person.db', dbname="media", dbenv=self.env)
self.event_map = dbshelve.open('person.db', dbname="events", dbenv=self.env)
self.surnames = db.DB(self.env)
self.surnames.set_flags(db.DB_DUP)
self.surnames.open("person.db", "surnames", db.DB_HASH, flags=db.DB_CREATE)
self.person_map.associate(self.surnames, find_surname, db.DB_CREATE)
self.surnames = []
self.iprefix = "I%04d"
self.sprefix = "S%04d"
self.oprefix = "O%04d"
@ -2283,6 +2297,15 @@ class GrampsDB:
self.added_files = []
self.genderStats = GenderStats ()
def close(self):
self.person_map.close()
self.family_map.close()
self.place_map.close()
self.source_map.close()
self.media_map.close()
self.event_map.close()
self.surnames.close()
def get_added_media_objects(self):
return self.added_files
@ -2292,9 +2315,6 @@ class GrampsDB:
def get_type(self):
return 'GrampsDB'
def close(self):
pass
def get_base(self):
return ""
@ -2431,7 +2451,6 @@ class GrampsDB:
def new(self):
"""initializes the GrampsDB to empty values"""
self.surnames = []
self.smap_index = 0
self.emap_index = 0
self.pmap_index = 0
@ -2448,15 +2467,17 @@ class GrampsDB:
#EARNEY, may eventually be able to use secondary indexes for this
#that way we will not have to track these with code.
def get_surnames(self):
return self.surnames
return []
# return self.surnames.keys()
#this function may eventually become obsolete.. if we use
#secondary indexes.
def add_surname(self,name):
if name and name not in self.surnames:
self.surnames.append(name)
self.surnames.sort()
pass
# if name and name not in self.surnames:
# self.surnames.append(name)
# self.surnames.sort()
def get_bookmarks(self):
"""returns the list of Person instances in the bookmarks"""
return self.bookmarks
@ -2820,12 +2841,11 @@ class GrampsDB:
"""finds an Object in the database from the passed gramps' ID.
If no such Source exists, a new Source is added to the database."""
val = str(idVal)
object = MediaObject()
if self.media_map.get(str(val)):
object.unserialize(self.media_map.get(str(val)))
if self.media_map.get(str(idVal)):
object.unserialize(self.media_map.get(str(idVal)))
else:
self.add_object_no_map(object,val)
self.add_object_no_map(object,idVal)
return object
def add_place(self,place):

View File

@ -35,6 +35,7 @@ import locale
#
#-------------------------------------------------------------------------
import gtk
import gnome.vfs
import grampslib
#-------------------------------------------------------------------------
@ -427,13 +428,13 @@ def find_icon(mtype):
return const.icon
def get_mime_type(file):
type = grampslib.gnome_vfs_mime_type_from_name(file)
type = gnome.vfs.get_mime_type(file)
if type:
return type
return "unknown"
def get_mime_description(type):
value = grampslib.gnome_vfs_mime_get_description(type)
value = gnome.vfs.mime_get_description(type)
if value:
return value
return ""

View File

@ -1084,32 +1084,32 @@ class Gramps:
#-------------------------------------------------------------------------
def remove_clicked():
# File is lost => remove all references and the object itself
mobj = ObjectMap[ObjectId]
mobj = self.db.find_object_from_id(ObjectId)
for p in self.db.get_family_id_map().values():
nl = p.get_media_list()
for o in nl:
if o.get_reference() == mobj:
if o.get_reference_id() == ObjectId:
nl.remove(o)
p.set_media_list(nl)
for key in self.db.get_person_keys():
p = self.db.get_person(key)
nl = p.get_media_list()
for o in nl:
if o.get_reference() == mobj:
if o.get_reference_id() == ObjectId:
nl.remove(o)
p.set_media_list(nl)
for key in self.db.get_source_keys():
p = self.db.get_source(key)
nl = p.get_media_list()
for o in nl:
if o.get_reference() == mobj:
if o.get_reference_id() == ObjectId:
nl.remove(o)
p.set_media_list(nl)
for key in self.db.get_place_id_keys():
p = self.db.get_place_id(key)
nl = p.get_media_list()
for o in nl:
if o.get_reference() == mobj:
if o.get_reference_id() == ObjectId:
nl.remove(o)
p.set_media_list(nl)
self.db.remove_object(ObjectId)
@ -1127,7 +1127,8 @@ class Gramps:
name = fs_top.get_filename()
if os.path.isfile(name):
RelImage.import_media_object(name,filename,base)
ObjectMap[ObjectId].set_path(newfile)
object = self.db.find_object_from_id(ObjectId)
object.set_path(newfile)
Utils.destroy_passed_object(fs_top)
fs_top = gtk.FileSelection("%s - GRAMPS" % _("Select file"))
@ -1138,13 +1139,13 @@ class Gramps:
fs_top.run()
#-------------------------------------------------------------------------
ObjectMap = self.db.get_object_map()
for ObjectId in ObjectMap.keys():
if ObjectMap[ObjectId].get_local():
oldfile = ObjectMap[ObjectId].get_path()
for ObjectId in self.db.get_object_keys():
object = self.db.find_object_from_id(ObjectId)
if object.get_local():
oldfile = object.get_path()
(base,ext) = os.path.splitext(os.path.basename(oldfile))
newfile = os.path.join(filename,os.path.basename(oldfile))
ObjectMap[ObjectId].set_path(newfile)
object.set_path(newfile)
if os.path.isfile(oldfile):
RelImage.import_media_object(oldfile,filename,base)
else:

View File

@ -118,35 +118,34 @@ class CheckIntegrity:
#-------------------------------------------------------------------------
def remove_clicked():
# File is lost => remove all references and the object itself
mobj = ObjectMap[ObjectId]
for p in self.db.get_family_id_map().values():
nl = p.get_media_list()
for o in nl:
if o.get_reference() == mobj:
if o.get_reference_id() == ObjectId:
nl.remove(o)
p.set_media_list(nl)
for key in self.db.get_person_keys():
p = self.db.get_person(key)
nl = p.get_media_list()
for o in nl:
if o.get_reference() == mobj:
if o.get_reference_id() == ObjectId:
nl.remove(o)
p.set_media_list(nl)
for key in self.db.get_source_keys():
p = self.db.get_source(key)
nl = p.get_media_list()
for o in nl:
if o.get_reference() == mobj:
if o.get_reference_id() == ObjectId:
nl.remove(o)
p.set_media_list(nl)
for key in self.db.get_place_id_keys():
p = self.db.get_place_id(key)
nl = p.get_media_list()
for o in nl:
if o.get_reference() == mobj:
if o.get_reference_id() == ObjectId:
nl.remove(o)
p.set_media_list(nl)
self.removed_photo.append(ObjectMap[ObjectId])
self.removed_photo.append(ObjectId)
self.db.remove_object(ObjectId)
Utils.modified()

View File

@ -564,7 +564,8 @@ class DetAncestorReport(Report.Report):
photos = person.get_media_list()
for photo in photos :
object = photo.get_reference()
object_id = photo.get_reference_id()
object = self.database.find_object_from_id(object_id)
if object.get_mime_type()[0:5] == "image":
file = object.get_path()
self.doc.add_media_object(file,"row",4.0,4.0)

View File

@ -557,7 +557,8 @@ class DetDescendantReport(Report.Report):
photos = person.get_media_list()
for photo in photos :
object = photo.get_reference()
object_id = photo.get_reference_id()
object = self.find_object_from_id(object_id)
if object.get_mime_type()[0:5] == "image":
file = object.get_path()
self.doc.add_media_object(file,"row",4.0,4.0)

View File

@ -382,7 +382,8 @@ class IndivComplete(Report.Report):
self.d.end_paragraph()
if len(media_list) > 0:
object = media_list[0].get_reference()
object_id = media_list[0].get_reference_id()
object = self.database.find_object_from_id(object_id)
if object.get_mime_type()[0:5] == "image":
file = object.get_path()
self.d.start_paragraph("IDS-Normal")

View File

@ -220,7 +220,8 @@ class IndivSummary(Report.Report):
self.d.end_paragraph()
if len(media_list) > 0:
object = media_list[0].get_reference()
object_id = media_list[0].get_reference_id()
object = self.database.find_object_from_id(object_id)
if object.get_mime_type()[0:5] == "image":
file = object.get_path()
self.d.start_paragraph("IVS-Normal")

View File

@ -504,7 +504,6 @@ class GedcomParser:
self.indi_count = self.indi_count + 1
id = matches[1]
id = id[1:-1]
print id
self.person = self.find_or_create_person(id)
self.added[self.person.get_id()] = self.person
self.parse_individual()
@ -971,7 +970,7 @@ class GedcomParser:
photo.set_mime_type(Utils.get_mime_type(path))
self.db.add_object(photo)
oref = RelLib.MediaRef()
oref.set_reference(photo)
oref.set_reference_id(photo.get_id())
self.person.add_media_reference(oref)
def parse_family_object(self,level):
@ -1009,7 +1008,7 @@ class GedcomParser:
photo.set_mime_type(Utils.get_mime_type(path))
self.db.add_object(photo)
oref = RelLib.MediaRef()
oref.set_reference(photo)
oref.set_reference_id(photo.get_id())
self.family.add_media_reference(photo)
self.db.commit_family(self.family)

View File

@ -312,7 +312,8 @@ class IndividualPage:
# into the document.
if self.photos and len(media_list) > 0:
object = media_list[0].get_reference()
object_id = media_list[0].get_reference_id()
object = self.database.find_object_from_id(object_id)
if object.get_mime_type()[0:5] == "image":
file = object.get_path()
if os.path.isfile(file):
@ -394,8 +395,9 @@ class IndividualPage:
my_list = []
index = 0
for object in self.person.get_media_list():
if object.get_reference().get_mime_type()[0:5] == "image":
for object_ref in self.person.get_media_list():
object = self.database.find_object_from_id(object_ref.get_ref())
if object.get_mime_type()[0:5] == "image":
if object.get_privacy() == 0 and index != 0:
my_list.append(object)
index = 1
@ -413,8 +415,9 @@ class IndividualPage:
self.doc.end_paragraph()
self.doc.start_table("gallery","IndTable")
for obj in my_list:
for obj_id in my_list:
try:
obj = self.database.find_object_from_id(obj_id)
src = obj.get_reference().get_path()
junk,ext = os.path.splitext(src)
base = '%s%s' % (obj.get_reference().get_id(),ext)