* data/grampsxml.dtd: Update for new bookmarks.

* data/grampsxml.rng: Update for new bookmarks.
	* src/GrampsDb/_WriteXML.py (write_bookmarks): Add method to write
	new bookmarks.
	* src/GrampsDb/_ReadXML.py (start_bmark): Parse new bookmarks


svn: r6714
This commit is contained in:
Alex Roitman 2006-05-18 22:17:51 +00:00
parent a265eac5e4
commit addf03a616
5 changed files with 95 additions and 13 deletions

View File

@ -1,4 +1,9 @@
2006-05-18 Alex Roitman <shura@gramps-project.org>
* data/grampsxml.dtd: Update for new bookmarks.
* data/grampsxml.rng: Update for new bookmarks.
* src/GrampsDb/_WriteXML.py (write_bookmarks): Add method to write
new bookmarks.
* src/GrampsDb/_ReadXML.py (start_bmark): Parse new bookmarks
* INSTALL: Clarify; list build-dependencies.
* src/GrampsDb/_ReadGrdb.py: Update progress.

View File

@ -47,6 +47,7 @@ DATABASE
sources
places
objects
repositories
bookmarks
-->
@ -306,7 +307,10 @@ BOOKMARKS
<!ELEMENT bookmarks (bookmark)*>
<!ELEMENT bookmark EMPTY>
<!ATTLIST bookmark hlink IDREF #REQUIRED>
<!ATTLIST bookmark
target (person|family|event|source|place|media|repository) #REQUIRED
hlink IDREF #REQUIRED
>
<!-- ************************************************************
SHARED ELEMENTS

View File

@ -419,6 +419,15 @@
</define>
<define name="bookmark-content">
<attribute name="target"><choice>
<value>person</value>
<value>family</value>
<value>event</value>
<value>source</value>
<value>place</value>
<value>media</value>
<value>repository</value>
</choice></attribute>
<attribute name="hlink"><data type="IDREF"/></attribute>
</define>

View File

@ -805,14 +805,43 @@ class GrampsParser(UpdateCallback):
self.address.private = bool(attrs.get("priv"))
def start_bmark(self,attrs):
try:
handle = attrs['hlink'].replace('_','')
target = attrs.get('target')
if not target:
# Old XML. Can be either handle or id reference
# and this is guaranteed to be a person bookmark
try:
handle = attrs['hlink'].replace('_','')
self.db.check_person_from_handle(handle,self.trans)
except KeyError:
gramps_id = self.map_gid(attrs["ref"])
person = self.find_person_by_gramps_id(gramps_id)
handle = person.handle
self.db.bookmarks.append(handle)
return
# This is new XML, so we are guaranteed to have a handle ref
handle = attrs['hlink'].replace('_','')
if target == 'person':
self.db.check_person_from_handle(handle,self.trans)
except KeyError:
gramps_id = self.map_gid(attrs["ref"])
person = self.find_person_by_gramps_id(gramps_id)
handle = person.handle
self.db.bookmarks.append(handle)
self.db.bookmarks.append(handle)
elif target == 'family':
self.db.check_family_from_handle(handle,self.trans)
self.db.family_bookmarks.append(handle)
elif target == 'event':
self.db.check_event_from_handle(handle,self.trans)
self.db.event_bookmarks.append(handle)
elif target == 'source':
self.db.check_source_from_handle(handle,self.trans)
self.db.source_bookmarks.append(handle)
elif target == 'place':
self.db.check_place_from_handle(handle,self.trans)
self.db.place_bookmarks.append(handle)
elif target == 'media':
self.db.check_object_from_handle(handle,self.trans)
self.db.media_bookmarks.append(handle)
elif target == 'repository':
self.db.check_repository_from_handle(handle,self.trans)
self.db.repo_bookmarks.append(handle)
def start_person(self,attrs):
self.update(self.p.CurrentLineNumber)

View File

@ -321,11 +321,8 @@ class XmlWriter(UpdateCallback):
self.update()
self.g.write(" </repositories>\n")
if len(self.db.get_bookmarks()) > 0:
self.g.write(" <bookmarks>\n")
for person_handle in self.db.get_bookmarks():
self.g.write(' <bookmark hlink="_%s"/>\n' % person_handle)
self.g.write(" </bookmarks>\n")
# Data is written, now write bookmarks.
self.write_bookmarks()
if len(self.db.name_group) > 0:
self.g.write(' <groups>\n')
@ -336,6 +333,44 @@ class XmlWriter(UpdateCallback):
self.g.write("</database>\n")
def write_bookmarks(self):
bm_person_len = len(self.db.bookmarks)
bm_family_len = len(self.db.family_bookmarks)
bm_event_len = len(self.db.event_bookmarks)
bm_source_len = len(self.db.source_bookmarks)
bm_place_len = len(self.db.place_bookmarks)
bm_repo_len = len(self.db.repo_bookmarks)
bm_obj_len = len(self.db.media_bookmarks)
bm_len = bm_person_len + bm_family_len + bm_event_len \
+ bm_source_len + bm_place_len + bm_repo_len + bm_obj_len
if bm_len > 0:
self.g.write(" <bookmarks>\n")
for handle in self.db.get_bookmarks():
self.g.write(' <bookmark target="person" hlink="_%s"/>\n'
% handle )
for handle in self.db.get_family_bookmarks():
self.g.write(' <bookmark target="family" hlink="_%s"/>\n'
% handle )
for handle in self.db.get_event_bookmarks():
self.g.write(' <bookmark target="event" hlink="_%s"/>\n'
% handle )
for handle in self.db.get_source_bookmarks():
self.g.write(' <bookmark target="source" hlink="_%s"/>\n'
% handle )
for handle in self.db.get_place_bookmarks():
self.g.write(' <bookmark target="place" hlink="_%s"/>\n'
% handle )
for handle in self.db.get_media_bookmarks():
self.g.write(' <bookmark target="media" hlink="_%s"/>\n'
% handle )
for handle in self.db.get_repo_bookmarks():
self.g.write(' <bookmark target="repository" hlink="_%s"/>\n'
% handle )
self.g.write(" </bookmarks>\n")
def fix(self,line):
l = line.strip()
l = l.replace('&','&amp;')