2006-07-27 Alex Roitman <shura@gramps-project.org>

* src/GrampsDb/_GrampsBSDDB.py (_load_metadata): Upgrade custom
	name formats.
	* src/GrampsDb/_ReadXML.py (start_format): Attempt parsing the
	active state for the custom name format.
	* src/GrampsDb/_WriteXML.py (write_name_formats): Write 4-tuple
	custom name formats; 
	(_xml_version): Output as version 1.1.1.
	* data/grampsxml.rng: Update XML description for 1.1.1.
	* data/grampsxml.dtd: Update XML description for 1.1.1.
	* src/ViewManager.py (post_load_newdb): Revert changes (done on
	the lower level).
	* src/NameDisplay.py (register_custom_formats): Revert changes (done on
	the lower level).



svn: r7085
This commit is contained in:
Alex Roitman 2006-07-27 17:44:02 +00:00
parent 1d9e6da05a
commit 787fe452e1
8 changed files with 66 additions and 28 deletions

View File

@ -1,3 +1,18 @@
2006-07-27 Alex Roitman <shura@gramps-project.org>
* src/GrampsDb/_GrampsBSDDB.py (_load_metadata): Upgrade custom
name formats.
* src/GrampsDb/_ReadXML.py (start_format): Attempt parsing the
active state for the custom name format.
* src/GrampsDb/_WriteXML.py (write_name_formats): Write 4-tuple
custom name formats;
(_xml_version): Output as version 1.1.1.
* data/grampsxml.rng: Update XML description for 1.1.1.
* data/grampsxml.dtd: Update XML description for 1.1.1.
* src/ViewManager.py (post_load_newdb): Revert changes (done on
the lower level).
* src/NameDisplay.py (register_custom_formats): Revert changes (done on
the lower level).
2006-07-27 Zsolt Foldvari <zfoldvar@users.sourceforge.net>
* src/ViewManager.py (post_load_newdb): Upgrade path for different
grdb custom name format table versions

View File

@ -24,15 +24,15 @@
-->
<!--
This is the Document Type Definition file for v1.1.0
This is the Document Type Definition file for v1.1.1
of the GRAMPS XML genealogy data format.
Please use the following formal public identifier to identify it:
"-//GRAMPS//DTD GRAMPS XML V1.1.0//EN"
"-//GRAMPS//DTD GRAMPS XML V1.1.1//EN"
For example:
<!DOCTYPE database PUBLIC "-//GRAMPS//DTD GRAMPS XML V1.1.0//EN"
"http://gramps-project.org/xml/1.1.0/grampsxml.dtd"
<!DOCTYPE database PUBLIC "-//GRAMPS//DTD GRAMPS XML V1.1.1//EN"
"http://gramps-project.org/xml/1.1.1/grampsxml.dtd"
[...]>
-->
@ -51,9 +51,9 @@ DATABASE
bookmarks
-->
<!ELEMENT database (header, events?, people?, families?, sources?,
places?, objects?, repositories?, bookmarks?)>
<!ATTLIST database xmlns CDATA #FIXED "http://gramps-project.org/xml/1.1.0/">
<!ELEMENT database (header, events?, people?, families?, sources?, places?,
objects?, repositories?, bookmark?, name-formats?)>
<!ATTLIST database xmlns CDATA #FIXED "http://gramps-project.org/xml/1.1.1/">
<!-- ************************************************************
HEADER
@ -312,6 +312,19 @@ BOOKMARKS
hlink IDREF #REQUIRED
>
<!-- ************************************************************
NAME FORMATS
-->
<!ELEMENT name-formats (format)*>
<!ELEMENT format EMPTY>
<!ATTLIST format
number CDATA #REQUIRED
name CDATA #REQUIRED
fmt_str CDATA #REQUIRED
active (0|1) #IMPLIED
>
<!-- ************************************************************
SHARED ELEMENTS
-->

View File

@ -31,7 +31,7 @@
<grammar
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
ns="http://gramps-project.org/xml/1.1.0/"
ns="http://gramps-project.org/xml/1.1.1/"
xmlns="http://relaxng.org/ns/structure/1.0">
<start><element name="database">
@ -98,6 +98,11 @@
</element></zeroOrMore>
</element></optional>
<optional><element name="name-formats">
<zeroOrMore><element name="format">
<ref name="format-content"/>
</element></zeroOrMore>
</element></optional>
</element></start>
<define name="researcher-content">
@ -431,6 +436,16 @@
<attribute name="hlink"><data type="IDREF"/></attribute>
</define>
<define name="format-content">
<attribute name="number"><text/></attribute>
<attribute name="name"><text/></attribute>
<attribute name="fmt_str"><text/></attribute>
<optional><attribute name="active"><choice>
<value>0</value>
<value>1</value>
</choice></attribute></optional>
</define>
<define name="note-content">
<optional><attribute name="format"><choice>
<value>0</value>

View File

@ -384,6 +384,12 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
def _load_metadata(self):
# name display formats
self.name_formats = self.metadata.get('name_formats',[])
# upgrade formats if they were saved in the old way
for format_ix in range(len(self.name_formats)):
format = self.name_formats[format_ix]
if len(format) == 3:
format = format + (True,)
self.name_formats[format_ix] = format
# bookmarks
self.bookmarks = self.metadata.get('bookmarks',[])
self.family_bookmarks = self.metadata.get('family_bookmarks',[])

View File

@ -844,7 +844,8 @@ class GrampsParser(UpdateCallback):
number = int(attrs['number'])
name = attrs['name']
fmt_str = attrs['fmt_str']
self.db.name_formats.append((number,name,fmt_str))
active = bool(attrs.get('active',True))
self.db.name_formats.append((number,name,fmt_str,active))
def start_person(self,attrs):
self.update(self.p.CurrentLineNumber)

View File

@ -70,7 +70,7 @@ except:
_gzip_ok = 0
_xml_version = "1.1.0"
_xml_version = "1.1.1"
#-------------------------------------------------------------------------
#
@ -356,9 +356,10 @@ class XmlWriter(UpdateCallback):
def write_name_formats(self):
if len(self.db.name_formats) > 0:
self.g.write(" <name-formats>\n")
for number,name,fmt_str in self.db.name_formats:
self.g.write('%s<format number="%d" name="%s" fmt_str="%s"/>\n'
% (' ',number,name,fmt_str) )
for number,name,fmt_str,active in self.db.name_formats:
self.g.write('%s<format number="%d" name="%s" '
'fmt_str="%s" active="%d"/>\n'
% (' ',number,name,fmt_str,int(active)) )
self.g.write(" </name-formats>\n")
def fix(self,line):

View File

@ -119,19 +119,8 @@ class NameDisplay:
self.raw_fn_array[0] = self.raw_fn_array[idx]
def register_custom_formats(self,formats):
# magic is needed due to different name format table structure
# in different revisions:
# r <= 7082: (number, name, format_string)
# r >= 7083: (number, name, format_string, active)
self.CUSTOM_FORMATS = []
changed = False
for format in formats:
if len(format) == 3:
format = format + (1,)
changed = True
self.CUSTOM_FORMATS.append(format)
self.CUSTOM_FORMATS = formats[:]
self.set_format_fn()
return changed
def update_custom_formats(self,num,name,str,act):
i = 0

View File

@ -768,9 +768,7 @@ class ViewManager:
self.state.db.set_researcher(owner)
self.setup_bookmarks()
if NameDisplay.displayer.register_custom_formats(self.state.db.name_formats):
self.state.db.name_formats = NameDisplay.displayer.CUSTOM_FORMATS
NameDisplay.displayer.register_custom_formats(self.state.db.name_formats)
fmt_default = Config.get(Config.NAME_FORMAT)
if fmt_default < 0:
NameDisplay.displayer.set_format_default(fmt_default)