2006-05-15 Alex Roitman <shura@gramps-project.org>
* src/GrampsDb/_GrampsXMLDB.py: Use callback, call parent's close() on close. * src/GrampsDb/_GrampsGEDDB.py: Use callback, call parent's close() on close. * src/GrampsDb/_WriteXML.py: Use new callback class. * src/GrampsDb/_WriteGedcom.py: Use new callback class. * src/GrampsDb/_DbUtils.py (db_copy): Update secondary indices for the InMem databases. svn: r6679
This commit is contained in:
parent
392f412261
commit
160ae6fb4f
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
||||
2006-05-15 Alex Roitman <shura@gramps-project.org>
|
||||
* src/GrampsDb/_GrampsXMLDB.py: Use callback, call parent's
|
||||
close() on close.
|
||||
* src/GrampsDb/_GrampsGEDDB.py: Use callback, call parent's
|
||||
close() on close.
|
||||
* src/GrampsDb/_WriteXML.py: Use new callback class.
|
||||
* src/GrampsDb/_WriteGedcom.py: Use new callback class.
|
||||
* src/GrampsDb/_DbUtils.py (db_copy): Update secondary indices for
|
||||
the InMem databases.
|
||||
|
||||
2006-05-15 Don Allingham <don@gramps-project.org>
|
||||
* src/ViewManager.py: new stock icon support
|
||||
* src/gramps_main.py: new stock icon support
|
||||
|
@ -159,47 +159,59 @@ def get_total(db):
|
||||
place_len + source_len + obj_len + repo_len
|
||||
|
||||
def db_copy(from_db,to_db,callback):
|
||||
uc = UpdateCallback(from_db,callback)
|
||||
uc = UpdateCallback(callback)
|
||||
uc.set_total(get_total(from_db))
|
||||
|
||||
primary_tables = {
|
||||
tables = {
|
||||
'Person': {'cursor_func': from_db.get_person_cursor,
|
||||
'table': to_db.person_map },
|
||||
'table': to_db.person_map,
|
||||
'sec_table' : to_db.id_trans },
|
||||
'Family': {'cursor_func': from_db.get_family_cursor,
|
||||
'table': to_db.family_map },
|
||||
'table': to_db.family_map,
|
||||
'sec_table' : to_db.fid_trans },
|
||||
'Event': {'cursor_func': from_db.get_event_cursor,
|
||||
'table': to_db.event_map },
|
||||
'table': to_db.event_map,
|
||||
'sec_table' : to_db.eid_trans },
|
||||
'Place': {'cursor_func': from_db.get_place_cursor,
|
||||
'table': to_db.place_map },
|
||||
'table': to_db.place_map,
|
||||
'sec_table' : to_db.pid_trans },
|
||||
'Source': {'cursor_func': from_db.get_source_cursor,
|
||||
'table': to_db.source_map },
|
||||
'table': to_db.source_map,
|
||||
'sec_table' : to_db.sid_trans },
|
||||
'MediaObject': {'cursor_func': from_db.get_media_cursor,
|
||||
'table': to_db.media_map },
|
||||
'table': to_db.media_map,
|
||||
'sec_table' : to_db.oid_trans },
|
||||
'Repository': {'cursor_func': from_db.get_repository_cursor,
|
||||
'table': to_db.repository_map },
|
||||
'table': to_db.repository_map,
|
||||
'sec_table' : to_db.rid_trans },
|
||||
}
|
||||
|
||||
|
||||
if to_db.__class__.__name__ == 'GrampsBSDDB':
|
||||
if to_db.UseTXN:
|
||||
add_data = add_data_txn
|
||||
else:
|
||||
add_data = add_data_notxn
|
||||
update_secondary = update_secondary_empty
|
||||
else:
|
||||
add_data = add_data_dict
|
||||
# For InMem databases, the secondary indices need to be
|
||||
# created as we copy objects
|
||||
update_secondary = update_secondary_inmem
|
||||
|
||||
# Start batch transaction to use async TXN and other tricks
|
||||
trans = to_db.transaction_begin("",batch=True)
|
||||
|
||||
for table_name in primary_tables.keys():
|
||||
cursor_func = primary_tables[table_name]['cursor_func']
|
||||
table = primary_tables[table_name]['table']
|
||||
for table_name in tables.keys():
|
||||
cursor_func = tables[table_name]['cursor_func']
|
||||
table = tables[table_name]['table']
|
||||
sec_table = tables[table_name]['sec_table']
|
||||
|
||||
cursor = cursor_func()
|
||||
item = cursor.first()
|
||||
while item:
|
||||
(handle,data) = item
|
||||
add_data(to_db,table,handle,data)
|
||||
update_secondary(sec_table,handle,data)
|
||||
item = cursor.next()
|
||||
uc.update()
|
||||
cursor.close()
|
||||
@ -213,6 +225,7 @@ def db_copy(from_db,to_db,callback):
|
||||
data = from_db.metadata.get(handle)
|
||||
to_db.metadata[handle] = data
|
||||
|
||||
|
||||
def add_data_txn(db,table,handle,data):
|
||||
the_txn = db.env.txn_begin()
|
||||
table.put(handle,data,txn=the_txn)
|
||||
@ -223,3 +236,9 @@ def add_data_notxn(db,table,handle,data):
|
||||
|
||||
def add_data_dict(db,table,handle,data):
|
||||
table[handle] = data
|
||||
|
||||
def update_secondary_empty(sec_table,handle,data):
|
||||
pass
|
||||
|
||||
def update_secondary_inmem(sec_table,handle,data):
|
||||
sec_table[str(data[1])] = str(handle)
|
||||
|
@ -28,8 +28,8 @@ of GEDCOM files.
|
||||
from RelLib import *
|
||||
from _GrampsInMemDB import *
|
||||
|
||||
import _ReadGedcom as ReadGedcom
|
||||
import _WriteGedcom as WriteGedcom
|
||||
from _ReadGedcom import importData
|
||||
from _WriteGedcom import GedcomWriter
|
||||
from _DbUtils import db_copy
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -49,7 +49,7 @@ class GrampsGEDDB(GrampsInMemDB):
|
||||
if self.db_is_open:
|
||||
self.close()
|
||||
GrampsInMemDB.load(self,name,callback,mode)
|
||||
ReadGedcom.importData(self,name,callback,use_trans=False)
|
||||
importData(self,name,callback,use_trans=False)
|
||||
|
||||
self.bookmarks = self.metadata.get('bookmarks')
|
||||
if self.bookmarks == None:
|
||||
@ -64,7 +64,8 @@ class GrampsGEDDB(GrampsInMemDB):
|
||||
if self.bookmarks == None:
|
||||
self.bookmarks = []
|
||||
self.db_is_open = True
|
||||
writer = WriteGedcom.GedcomWriter(self,self.get_default_person())
|
||||
writer = GedcomWriter(self,self.get_default_person(),
|
||||
callback=callback)
|
||||
writer.export_data(self.full_name)
|
||||
return 1
|
||||
|
||||
@ -72,6 +73,7 @@ class GrampsGEDDB(GrampsInMemDB):
|
||||
if not self.db_is_open:
|
||||
return
|
||||
if not self.readonly and len(self.undodb) > 0:
|
||||
writer = WriteGedcom.GedcomWriter(self,self.get_default_person())
|
||||
writer = GedcomWriter(self,self.get_default_person())
|
||||
writer.export_data(self.full_name)
|
||||
self.db_is_open = False
|
||||
GrampsInMemDB.close(self)
|
||||
|
@ -28,8 +28,8 @@ of GRAMPS XML format.
|
||||
from RelLib import *
|
||||
from _GrampsInMemDB import *
|
||||
|
||||
import _ReadXML as ReadXML
|
||||
import _WriteXML as WriteXML
|
||||
from _ReadXML import importData
|
||||
from _WriteXML import quick_write
|
||||
from _DbUtils import db_copy
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -51,7 +51,7 @@ class GrampsXMLDB(GrampsInMemDB):
|
||||
GrampsInMemDB.load(self,name,callback,mode)
|
||||
self.id_trans = {}
|
||||
|
||||
ReadXML.importData(self,name,callback,use_trans=False)
|
||||
importData(self,name,callback,use_trans=False)
|
||||
|
||||
self.bookmarks = self.metadata.get('bookmarks')
|
||||
if self.bookmarks == None:
|
||||
@ -67,12 +67,13 @@ class GrampsXMLDB(GrampsInMemDB):
|
||||
if self.bookmarks == None:
|
||||
self.bookmarks = []
|
||||
self.db_is_open = True
|
||||
WriteXML.quick_write(self,self.full_name)
|
||||
quick_write(self,self.full_name,callback)
|
||||
return 1
|
||||
|
||||
def close(self):
|
||||
if not self.db_is_open:
|
||||
return
|
||||
if not self.readonly and len(self.undodb) > 0:
|
||||
WriteXML.quick_write(self,self.full_name)
|
||||
quick_write(self,self.full_name)
|
||||
self.db_is_open = False
|
||||
GrampsInMemDB.close(self)
|
||||
|
@ -69,6 +69,7 @@ import ansel_utf8
|
||||
import Utils
|
||||
import NameDisplay
|
||||
from QuestionDialog import ErrorDialog, WarningDialog
|
||||
from BasicUtils import UpdateCallback
|
||||
|
||||
def keep_utf8(s):
|
||||
return s
|
||||
@ -478,19 +479,16 @@ class GedcomWriterOptionBox:
|
||||
self.nl = self.cnvtxt(self.target_ged.get_endl())
|
||||
|
||||
|
||||
class GedcomWriter:
|
||||
class GedcomWriter(UpdateCallback):
|
||||
def __init__(self,database,person,cl=0,filename="",option_box=None,
|
||||
callback=None):
|
||||
UpdateCallback.__init__(self,callback)
|
||||
|
||||
self.db = database
|
||||
self.person = person
|
||||
self.option_box = option_box
|
||||
self.cl = cl
|
||||
self.filename = filename
|
||||
self.callback = callback
|
||||
if '__call__' in dir(self.callback): # callback is really callable
|
||||
self.update = self.update_real
|
||||
else:
|
||||
self.update = self.update_empty
|
||||
|
||||
self.plist = {}
|
||||
self.slist = {}
|
||||
@ -550,16 +548,6 @@ class GedcomWriter:
|
||||
self.slist,self.option_box.private)
|
||||
self.flist[family_handle] = 1
|
||||
|
||||
def update_empty(self):
|
||||
pass
|
||||
|
||||
def update_real(self):
|
||||
self.count += 1
|
||||
newval = int(100*self.count/self.total)
|
||||
if newval != self.oldval:
|
||||
self.callback(newval)
|
||||
self.oldval = newval
|
||||
|
||||
def cl_setup(self):
|
||||
self.restrict = 0
|
||||
self.private = 0
|
||||
@ -665,10 +653,8 @@ class GedcomWriter:
|
||||
self.writeln('2 CONT Not Provided')
|
||||
|
||||
pkeys = self.plist.keys()
|
||||
self.total = len(pkeys) + len(self.flist.keys()) \
|
||||
+ len(self.slist.keys())
|
||||
self.oldval = 0
|
||||
self.count = 0
|
||||
self.set_total(len(pkeys) + len(self.flist.keys()) \
|
||||
+ len(self.slist.keys()))
|
||||
|
||||
sorted = []
|
||||
for key in pkeys:
|
||||
|
@ -62,6 +62,7 @@ from QuestionDialog import ErrorDialog
|
||||
from _GrampsDbBase import \
|
||||
PERSON_KEY,FAMILY_KEY,SOURCE_KEY,EVENT_KEY,\
|
||||
MEDIA_KEY,PLACE_KEY,REPOSITORY_KEY
|
||||
from BasicUtils import UpdateCallback
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -120,7 +121,7 @@ def quick_write(database, filename,callback=None):
|
||||
#
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class XmlWriter:
|
||||
class XmlWriter(UpdateCallback):
|
||||
"""
|
||||
Writes a database to the XML file.
|
||||
"""
|
||||
@ -137,13 +138,9 @@ class XmlWriter:
|
||||
2: remove leading slash
|
||||
compress - attempt to compress the database
|
||||
"""
|
||||
UpdateCallback.__init__(self,callback)
|
||||
self.compress = compress
|
||||
self.db = db
|
||||
self.callback = callback
|
||||
if '__call__' in dir(self.callback): # callback is really callable
|
||||
self.update = self.update_real
|
||||
else:
|
||||
self.update = self.update_empty
|
||||
self.strip_photos = strip_photos
|
||||
|
||||
def write(self,filename):
|
||||
@ -211,18 +208,17 @@ class XmlWriter:
|
||||
|
||||
date = time.localtime(time.time())
|
||||
owner = self.db.get_researcher()
|
||||
|
||||
person_len = self.db.get_number_of_people()
|
||||
family_len = len(self.db.get_family_handles())
|
||||
event_len = len(self.db.get_event_handles())
|
||||
source_len = len(self.db.get_source_handles())
|
||||
place_len = len(self.db.get_place_handles())
|
||||
repo_len = len(self.db.get_repository_handles())
|
||||
obj_len = len(self.db.get_media_object_handles())
|
||||
family_len = self.db.get_number_of_families()
|
||||
event_len = self.db.get_number_of_events()
|
||||
source_len = self.db.get_number_of_sources()
|
||||
place_len = self.db.get_number_of_places()
|
||||
repo_len = self.db.get_number_of_repositories()
|
||||
obj_len = self.db.get_number_of_media_objects()
|
||||
|
||||
self.total = person_len + family_len + event_len + place_len + \
|
||||
source_len + obj_len + repo_len
|
||||
self.count = 0
|
||||
self.oldval = 0
|
||||
self.set_total(person_len+family_len+event_len+source_len
|
||||
+place_len+repo_len+obj_len)
|
||||
|
||||
self.g.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
||||
self.g.write('<!DOCTYPE database '
|
||||
@ -340,16 +336,6 @@ class XmlWriter:
|
||||
|
||||
self.g.write("</database>\n")
|
||||
|
||||
def update_empty(self):
|
||||
pass
|
||||
|
||||
def update_real(self):
|
||||
self.count += 1
|
||||
newval = int(100*self.count/self.total)
|
||||
if newval != self.oldval:
|
||||
self.callback(newval)
|
||||
self.oldval = newval
|
||||
|
||||
def fix(self,line):
|
||||
l = line.strip()
|
||||
l = l.replace('&','&')
|
||||
|
Loading…
Reference in New Issue
Block a user