2007-03-24 Don Allingham <don@gramps-project.org>
* src/ViewManager.py: add support for new directory type * src/GrampsDb/_GrampsDbBase.py: use normal pickle encoding * src/GrampsDb/_GrampsDBDir.py: new directory based type * src/GrampsDb/_GrampsDbFactories.py: add support for new directory type * src/Editors/_EditNote.py: only update on save * src/Selectors/_SelectPerson.py: use normal columns * src/GrampsDbUtils/_ReadGedcom.py: add support for new directory type * src/GrampsDbUtils/__init__.py: add support for new directory type * src/GrampsDbUtils/_Backup.py: fast pickle based backup * src/ArgHandler.py: add support for new directory type svn: r8313
This commit is contained in:
parent
be30e422b9
commit
d20b4833f9
12
ChangeLog
12
ChangeLog
@ -1,3 +1,15 @@
|
||||
2007-03-24 Don Allingham <don@gramps-project.org>
|
||||
* src/ViewManager.py: add support for new directory type
|
||||
* src/GrampsDb/_GrampsDbBase.py: use normal pickle encoding
|
||||
* src/GrampsDb/_GrampsDBDir.py: new directory based type
|
||||
* src/GrampsDb/_GrampsDbFactories.py: add support for new directory type
|
||||
* src/Editors/_EditNote.py: only update on save
|
||||
* src/Selectors/_SelectPerson.py: use normal columns
|
||||
* src/GrampsDbUtils/_ReadGedcom.py: add support for new directory type
|
||||
* src/GrampsDbUtils/__init__.py: add support for new directory type
|
||||
* src/GrampsDbUtils/_Backup.py: fast pickle based backup
|
||||
* src/ArgHandler.py: add support for new directory type
|
||||
|
||||
2007-03-24 Zsolt Foldvari <zfoldvar@users.sourceforge.net>
|
||||
* src/Editors/_EditAddress.py:
|
||||
* src/Editors/_EditLdsOrd.py:
|
||||
|
@ -299,7 +299,7 @@ class ArgHandler:
|
||||
filename = os.path.abspath(os.path.expanduser(self.open_gui))
|
||||
filetype = Mime.get_type(filename)
|
||||
if filetype in (const.app_gramps,const.app_gedcom,
|
||||
const.app_gramps_xml):
|
||||
const.app_gramps_xml, 'x-directory/normal'):
|
||||
# Say the type outloud
|
||||
if filetype == const.app_gramps:
|
||||
print "Type: GRAMPS database"
|
||||
@ -309,11 +309,12 @@ class ArgHandler:
|
||||
print "Type: GRAMPS XML database"
|
||||
|
||||
try:
|
||||
self.vm.read_recent_file(filename,filetype)
|
||||
self.vm.read_recent_file(filename, filetype)
|
||||
print "Opened successfully!"
|
||||
success = True
|
||||
except:
|
||||
print "Cannot open %s. Exiting..."
|
||||
|
||||
elif filetype in (const.app_gramps_package,):
|
||||
QuestionDialog.OkDialog( _("Opening non-native format"),
|
||||
_("New GRAMPS database has to be set up "
|
||||
@ -370,13 +371,16 @@ class ArgHandler:
|
||||
elif format == 'gramps-xml':
|
||||
filetype = const.app_gramps_xml
|
||||
print "Type: GRAMPS XML"
|
||||
elif format == 'x-directory/normal':
|
||||
filetype = 'x-directory/normal'
|
||||
print "Type: GRAMPS DIR"
|
||||
else:
|
||||
print "Unknown file type: %s" % format
|
||||
print "Exiting..."
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
self.vm.read_recent_file(filename,filetype)
|
||||
self.vm.read_recent_file(filename, filetype)
|
||||
print "Opened successfully!"
|
||||
success = True
|
||||
except:
|
||||
|
@ -150,6 +150,7 @@ class EditNote(EditPrimary):
|
||||
]
|
||||
|
||||
buffer = EditorBuffer()
|
||||
self.buffer = buffer
|
||||
|
||||
self.text = self.top.get_widget('text')
|
||||
self.text.set_editable(not self.dbstate.db.readonly)
|
||||
@ -193,9 +194,10 @@ class EditNote(EditPrimary):
|
||||
self.empty = True
|
||||
|
||||
# connection to buffer signals must be after the initial values are set
|
||||
buffer.connect('changed', self.update_note)
|
||||
buffer.connect_after('apply-tag', self.update_note)
|
||||
buffer.connect_after('remove-tag', self.update_note)
|
||||
#buffer.connect('changed', self.update_note)
|
||||
self.sig_list = []
|
||||
self.sig_list.append(buffer.connect_after('apply-tag', self.update_note))
|
||||
self.sig_list.append(buffer.connect_after('remove-tag', self.update_note))
|
||||
|
||||
def update_note(self, buffer, *args):
|
||||
"""Update the Note object with current value.
|
||||
@ -207,6 +209,7 @@ class EditNote(EditPrimary):
|
||||
start = buffer.get_start_iter()
|
||||
stop = buffer.get_end_iter()
|
||||
text = buffer.get_text(start, stop)
|
||||
print text
|
||||
self.obj.set(text)
|
||||
else:
|
||||
log.debug("NOTE OBJ DOES NOT EXIST")
|
||||
@ -222,7 +225,13 @@ class EditNote(EditPrimary):
|
||||
"""
|
||||
Save the data.
|
||||
"""
|
||||
for i in self.sig_list:
|
||||
self.buffer.disconnect(i)
|
||||
|
||||
trans = self.db.transaction_begin()
|
||||
|
||||
self.update_note(self.text.get_buffer())
|
||||
|
||||
if self.obj.get_handle():
|
||||
self.db.commit_note(self.obj,trans)
|
||||
else:
|
||||
|
1568
src/GrampsDb/_GrampsDBDir.py
Normal file
1568
src/GrampsDb/_GrampsDBDir.py
Normal file
File diff suppressed because it is too large
Load Diff
@ -2469,12 +2469,8 @@ class Transaction:
|
||||
is the object's database handle, and the data is the tuple returned
|
||||
by the object's serialize method.
|
||||
"""
|
||||
self.last = self.db.append(cPickle.dumps((obj_type,
|
||||
handle,
|
||||
old_data,
|
||||
new_data),
|
||||
1)
|
||||
)
|
||||
self.last = self.db.append(
|
||||
cPickle.dumps((obj_type, handle, old_data, new_data)))
|
||||
if self.first == None:
|
||||
self.first = self.last
|
||||
|
||||
|
@ -70,6 +70,9 @@ def gramps_db_factory(db_type):
|
||||
elif db_type == const.app_gedcom:
|
||||
from _GrampsGEDDB import GrampsGEDDB
|
||||
cls = GrampsGEDDB
|
||||
elif db_type == 'x-directory/normal':
|
||||
from _GrampsDBDir import GrampsDBDir
|
||||
cls = GrampsDBDir
|
||||
else:
|
||||
raise GrampsDbException("Attempt to create unknown "
|
||||
"database backend class: "
|
||||
|
126
src/GrampsDbUtils/_Backup.py
Normal file
126
src/GrampsDbUtils/_Backup.py
Normal file
@ -0,0 +1,126 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2006 Donald N. Allingham
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
# $Id: _WriteXML.py 8144 2007-02-17 22:12:56Z hippy $
|
||||
|
||||
"""
|
||||
Contains the interface to allow a database to get written using
|
||||
GRAMPS' XML file format.
|
||||
"""
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# load standard python libraries
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from gettext import gettext as _
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Gramps libs
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
from QuestionDialog import ErrorDialog
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Set up logging
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
import logging
|
||||
import os
|
||||
import cPickle as pickle
|
||||
import time
|
||||
|
||||
LOG = logging.getLogger(".Backukp")
|
||||
|
||||
def __base_dir(database):
|
||||
return os.path.dirname(database.get_save_path())
|
||||
|
||||
def export(database):
|
||||
try:
|
||||
do_export(database)
|
||||
except (OSError, IOError), msg:
|
||||
ErrorDialog(
|
||||
_("Error saving backup data"),
|
||||
str(msg))
|
||||
|
||||
def do_export(database):
|
||||
|
||||
t = time.time()
|
||||
|
||||
tables = [
|
||||
('person', database.person_map.db),
|
||||
('family', database.family_map.db),
|
||||
('place', database.place_map.db),
|
||||
('source', database.place_map.db),
|
||||
('repo', database.repository_map.db),
|
||||
('note', database.note_map.db),
|
||||
('media', database.media_map.db),
|
||||
('event', database.media_map.db),
|
||||
]
|
||||
|
||||
for (base, db) in tables:
|
||||
backup_name = os.path.join(__base_dir(database), base + ".gbkp")
|
||||
print backup_name
|
||||
backup_table = open(backup_name, 'w')
|
||||
|
||||
cursor = db.cursor()
|
||||
d = cursor.first()
|
||||
while d:
|
||||
backup_table.write(d[1])
|
||||
d = cursor.next()
|
||||
cursor.close()
|
||||
backup_table.close()
|
||||
print time.time() - t
|
||||
|
||||
def restore(database):
|
||||
try:
|
||||
do_restore(database)
|
||||
except (OSError, IOError), msg:
|
||||
ErrorDialog(
|
||||
_("Error restoring backup data"),
|
||||
str(msg))
|
||||
|
||||
def do_restore(database):
|
||||
|
||||
t = time.time()
|
||||
|
||||
tables = [
|
||||
('person', database.person_map),
|
||||
('family', database.family_map),
|
||||
('place', database.place_map),
|
||||
('source', database.place_map),
|
||||
('repo', database.repository_map),
|
||||
('note', database.note_map),
|
||||
('media', database.media_map),
|
||||
('event', database.media_map),
|
||||
]
|
||||
|
||||
for (base, db) in tables:
|
||||
backup_name = os.path.join(__base_dir(database), base + ".gbkp")
|
||||
backup_table = open(backup_name, 'r')
|
||||
|
||||
for line in backup_table:
|
||||
data = pickle.loads(line)
|
||||
db[data[0]] = data
|
||||
backup_table.close()
|
||||
print time.time() - t
|
||||
|
@ -46,3 +46,5 @@ from _WriteGedcom import GedcomWriter
|
||||
|
||||
from _WriteXML import XmlWriter
|
||||
|
||||
import _Backup as Backup
|
||||
|
||||
|
@ -44,6 +44,18 @@ import const
|
||||
from DisplayModels import PeopleModel
|
||||
import ManagedWindow
|
||||
|
||||
column_names = [
|
||||
_('Name'),
|
||||
_('ID') ,
|
||||
_('Gender'),
|
||||
_('Birth Date'),
|
||||
_('Birth Place'),
|
||||
_('Death Date'),
|
||||
_('Death Place'),
|
||||
_('Spouse'),
|
||||
_('Last Change'),
|
||||
]
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# SelectPerson
|
||||
@ -62,7 +74,7 @@ class SelectPerson(ManagedWindow.ManagedWindow):
|
||||
|
||||
self.renderer = gtk.CellRendererText()
|
||||
self.renderer.set_property('ellipsize',pango.ELLIPSIZE_END)
|
||||
self.db = dbstate.db
|
||||
self.dbstate = dbstate
|
||||
self.glade = gtk.glade.XML(const.gladeFile,"select_person","gramps")
|
||||
self.plist = self.glade.get_widget('plist')
|
||||
self.showall = self.glade.get_widget('showall')
|
||||
@ -78,7 +90,7 @@ class SelectPerson(ManagedWindow.ManagedWindow):
|
||||
|
||||
self.skip = skip
|
||||
|
||||
self.model = PeopleModel(self.db,
|
||||
self.model = PeopleModel(self.dbstate.db,
|
||||
(PeopleModel.FAST, filter),
|
||||
skip=skip)
|
||||
|
||||
@ -93,33 +105,47 @@ class SelectPerson(ManagedWindow.ManagedWindow):
|
||||
else:
|
||||
filt = self.filter
|
||||
|
||||
self.model = PeopleModel(self.db,
|
||||
self.model = PeopleModel(self.dbstate.db,
|
||||
(PeopleModel.FAST, filt),
|
||||
skip=self.skip)
|
||||
self.plist.set_model(self.model)
|
||||
|
||||
def build_menu_names(self,obj):
|
||||
def build_menu_names(self, obj):
|
||||
return (self.title, None)
|
||||
|
||||
def add_columns(self,tree):
|
||||
tree.set_fixed_height_mode(True)
|
||||
column = gtk.TreeViewColumn(_('Name'), self.renderer, text=0)
|
||||
def add_columns(self, tree):
|
||||
|
||||
try:
|
||||
column = gtk.TreeViewColumn(
|
||||
_('Name'),
|
||||
self.renderer,
|
||||
text=0,
|
||||
foreground=self.model.marker_color_column)
|
||||
|
||||
except AttributeError:
|
||||
column = gtk.TreeViewColumn(_('Name'), self.renderer, text=0)
|
||||
|
||||
column.set_resizable(True)
|
||||
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
||||
column.set_fixed_width(225)
|
||||
column.set_resizable(True)
|
||||
tree.append_column(column)
|
||||
|
||||
column = gtk.TreeViewColumn(_('ID'), self.renderer, text=1)
|
||||
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
||||
column.set_fixed_width(75)
|
||||
column.set_resizable(True)
|
||||
tree.append_column(column)
|
||||
|
||||
column = gtk.TreeViewColumn(_('Birth date'), self.renderer, markup=3)
|
||||
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
||||
column.set_fixed_width(160)
|
||||
column.set_resizable(True)
|
||||
tree.append_column(column)
|
||||
for pair in self.dbstate.db.get_person_column_order():
|
||||
if not pair[0]:
|
||||
continue
|
||||
name = column_names[pair[1]]
|
||||
try:
|
||||
column = gtk.TreeViewColumn(
|
||||
name, self.renderer, markup=pair[1],
|
||||
foreground=self.model.marker_color_column)
|
||||
except AttributeError:
|
||||
column = gtk.TreeViewColumn(
|
||||
name, self.renderer, markup=pair[1])
|
||||
|
||||
column.set_resizable(True)
|
||||
column.set_fixed_width(pair[2])
|
||||
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
||||
tree.append_column(column)
|
||||
|
||||
def select_function(self,store,path,iter,id_list):
|
||||
id_list.append(self.model.get_value(iter,PeopleModel.COLUMN_INT_ID))
|
||||
@ -135,7 +161,7 @@ class SelectPerson(ManagedWindow.ManagedWindow):
|
||||
idlist = self.get_selected_ids()
|
||||
self.close()
|
||||
if idlist and idlist[0]:
|
||||
return_value = self.db.get_person_from_handle(idlist[0])
|
||||
return_value = self.dbstate.db.get_person_from_handle(idlist[0])
|
||||
else:
|
||||
return_value = None
|
||||
return return_value
|
||||
|
@ -533,32 +533,13 @@ class ViewManager:
|
||||
import GrampsDbUtils
|
||||
|
||||
if self.state.db.undoindex > 0:
|
||||
self.uistate.set_busy_cursor(1)
|
||||
self.uistate.progress.show()
|
||||
self.uistate.push_message(self.state, _("Autobackup..."))
|
||||
writer = GrampsDbUtils.Backup.export(self.state.db)
|
||||
self.uistate.set_busy_cursor(0)
|
||||
self.uistate.progress.hide()
|
||||
|
||||
# build backup path name
|
||||
bpath = self.state.db.get_save_path()
|
||||
backup = os.path.splitext(bpath)[0] + ".backup.gramps"
|
||||
|
||||
# check to see if the old file exists
|
||||
if os.path.exists(backup):
|
||||
if os.path.exists(backup + ".old"):
|
||||
os.remove(backup + ".old")
|
||||
os.rename(backup, backup + ".old")
|
||||
|
||||
try:
|
||||
self.uistate.set_busy_cursor(1)
|
||||
self.uistate.progress.show()
|
||||
self.uistate.push_message(self.state, _("Autobackup..."))
|
||||
writer = GrampsDbUtils.XmlWriter(
|
||||
self.state.db, self.uistate.pulse_progressbar, 0, 1)
|
||||
writer.write(backup)
|
||||
self.uistate.set_busy_cursor(0)
|
||||
self.uistate.progress.hide()
|
||||
except:
|
||||
# the backup failed, so we assume that the autobackup file was corrupted,
|
||||
# so restore the old file
|
||||
if os.path.exists(backup + ".old"):
|
||||
os.rename(backup+".old", backup)
|
||||
|
||||
def abort(self, obj=None):
|
||||
"""
|
||||
Abandon changes and quit.
|
||||
|
Loading…
Reference in New Issue
Block a user