* src/ArgHandler.py: Adapt to recent changes.
* src/BasicUtils.py (update_empty): Clean up callback. * src/GrampsDb/_ReadGedcom.py: Clean up callback. svn: r6700
This commit is contained in:
parent
d95f546782
commit
ae8ec93201
@ -1,4 +1,7 @@
|
||||
2006-05-17 Alex Roitman <shura@gramps-project.org>
|
||||
* src/ArgHandler.py: Adapt to recent changes.
|
||||
* src/BasicUtils.py (update_empty): Clean up callback.
|
||||
* src/GrampsDb/_ReadGedcom.py: Clean up callback.
|
||||
* src/GrampsDb/_GrampsDbBase.py (DbState.change_database_noclose):
|
||||
Add new method.
|
||||
* src/Makefile.am (gdir_PYTHON): Ship new file.
|
||||
|
@ -249,21 +249,6 @@ class ArgHandler:
|
||||
options_str = options[opt_ix+1][1]
|
||||
self.actions.append((action,options_str))
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# open data in native format
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
def auto_save_load(self,filename):
|
||||
filename = os.path.normpath(os.path.abspath(filename))
|
||||
filetype = Mime.get_type(filename)
|
||||
if filetype in (const.app_gramps,
|
||||
const.app_gramps_xml,
|
||||
const.app_gedcom):
|
||||
return self.vm.open_native(filename,filetype)
|
||||
else:
|
||||
return 0
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Overall argument handler:
|
||||
@ -292,10 +277,11 @@ class ArgHandler:
|
||||
elif filetype == const.app_gramps_xml:
|
||||
print "Type: GRAMPS XML database"
|
||||
|
||||
if self.auto_save_load(filename):
|
||||
try:
|
||||
self.vm.read_recent_file(filename,filetype)
|
||||
print "Opened successfully!"
|
||||
success = True
|
||||
else:
|
||||
except:
|
||||
print "Cannot open %s. Exiting..."
|
||||
elif filetype in (const.app_gramps_package,):
|
||||
QuestionDialog.OkDialog( _("Opening non-native format"),
|
||||
@ -327,7 +313,8 @@ class ArgHandler:
|
||||
os._exit(1)
|
||||
if success:
|
||||
# Add the file to the recent items
|
||||
RecentFiles.recent_files(filename,filetype)
|
||||
#RecentFiles.recent_files(filename,filetype)
|
||||
pass
|
||||
else:
|
||||
os._exit(1)
|
||||
return
|
||||
@ -344,20 +331,24 @@ class ArgHandler:
|
||||
filename = os.path.abspath(os.path.expanduser(name))
|
||||
|
||||
if format == 'grdb':
|
||||
filetype = const.app_gramps
|
||||
print "Type: GRAMPS database"
|
||||
elif format == 'gedcom':
|
||||
filetype = const.app_gedcom
|
||||
print "Type: GEDCOM"
|
||||
elif format == 'gramps-xml':
|
||||
filetype = const.app_gramps_xml
|
||||
print "Type: GRAMPS XML"
|
||||
else:
|
||||
print "Unknown file type: %s" % format
|
||||
print "Exiting..."
|
||||
os._exit(1)
|
||||
|
||||
if self.auto_save_load(filename):
|
||||
try:
|
||||
self.vm.read_recent_file(filename,filetype)
|
||||
print "Opened successfully!"
|
||||
success = True
|
||||
else:
|
||||
except:
|
||||
print "Error opening the file."
|
||||
print "Exiting..."
|
||||
os._exit(1)
|
||||
@ -385,7 +376,7 @@ class ArgHandler:
|
||||
if os.path.isfile(os.path.join(self.impdir_path,fn)):
|
||||
os.remove(os.path.join(self.impdir_path,fn))
|
||||
|
||||
self.vm.load_database(self.imp_db_path)
|
||||
self.vm.db_loader.read_file(self.imp_db_path,const.app_gramps)
|
||||
|
||||
for imp in self.imports:
|
||||
print "Importing: file %s, format %s." % imp
|
||||
@ -419,7 +410,9 @@ class ArgHandler:
|
||||
## if self.imports:
|
||||
## self.parent.import_tool_callback()
|
||||
elif Config.get(Config.RECENT_FILE) and Config.get(Config.AUTOLOAD):
|
||||
self.auto_save_load(Config.get(Config.RECENT_FILE))
|
||||
rf = Config.get(Config.RECENT_FILE)
|
||||
filetype = Mime.get_type(rf)
|
||||
self.vm.read_recent_file(rf,filetype)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -435,20 +428,16 @@ class ArgHandler:
|
||||
filename = os.path.normpath(os.path.abspath(filename))
|
||||
try:
|
||||
GrampsDb.gramps_db_reader_factory(const.app_gramps)(
|
||||
self.state.db,filename,None)
|
||||
self.state.db,filename,empty)
|
||||
except:
|
||||
print "Error importing %s" % filename
|
||||
os._exit(1)
|
||||
elif format == 'gedcom':
|
||||
from GrampsDb import GedcomParser
|
||||
filename = os.path.normpath(os.path.abspath(filename))
|
||||
try:
|
||||
np = ReadGedcom.NoteParser(filename, False, None)
|
||||
g = ReadGedcom.GedcomParser(self.parent.db,filename,None,None,
|
||||
np.get_map(),np.get_lines())
|
||||
g = GedcomParser(self.state.db,filename,None)
|
||||
g.parse_gedcom_file()
|
||||
del g
|
||||
# Cheating here to use default encoding
|
||||
from GrampsDb._ReadGedcom import import2
|
||||
import2(self.state.db,filename,None,None,False)
|
||||
except:
|
||||
print "Error importing %s" % filename
|
||||
os._exit(1)
|
||||
@ -521,7 +510,7 @@ class ArgHandler:
|
||||
print "Invalid format: %s" % format
|
||||
os._exit(1)
|
||||
if not self.cl:
|
||||
return self.vm.post_load(self.imp_db_path)
|
||||
return self.vm.post_load()
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -769,3 +758,6 @@ def add_grdb_filter(chooser):
|
||||
|
||||
def read_pkg(filename):
|
||||
print "FIXME: This is not re-implemented yet."
|
||||
|
||||
def empty(val):
|
||||
pass
|
||||
|
@ -67,7 +67,7 @@ class UpdateCallback:
|
||||
def set_total(self,total):
|
||||
self.total = total
|
||||
|
||||
def update_empty(self):
|
||||
def update_empty(self,count=None):
|
||||
pass
|
||||
|
||||
def update_real(self,count=None):
|
||||
|
@ -92,33 +92,10 @@ class DbLoader:
|
||||
|
||||
format_list = [const.app_gramps,const.app_gramps_xml,const.app_gedcom]
|
||||
|
||||
# Add more data type selections if opening existing db
|
||||
for data in import_list:
|
||||
mime_filter = data[1]
|
||||
mime_type = data[2]
|
||||
native_format = data[2]
|
||||
format_name = data[3]
|
||||
|
||||
if not native_format:
|
||||
choose.add_filter(mime_filter)
|
||||
format_list.append(mime_type)
|
||||
_KNOWN_FORMATS[mime_type] = format_name
|
||||
|
||||
(box, type_selector) = format_maker(format_list)
|
||||
choose.set_extra_widget(box)
|
||||
|
||||
# Suggested folder: try last open file, last import, last export,
|
||||
# then home.
|
||||
default_dir = os.path.split(Config.get(Config.RECENT_FILE))[0] \
|
||||
+ os.path.sep
|
||||
if len(default_dir)<=1:
|
||||
default_dir = Config.get(Config.RECENT_IMPORT_DIR)
|
||||
if len(default_dir)<=1:
|
||||
default_dir = Config.get(Config.RECENT_EXPORT_DIR)
|
||||
if len(default_dir)<=1:
|
||||
default_dir = '~/'
|
||||
|
||||
choose.set_current_folder(default_dir)
|
||||
choose.set_current_folder(get_default_dir())
|
||||
response = choose.run()
|
||||
if response == gtk.RESPONSE_OK:
|
||||
filename = choose.get_filename()
|
||||
@ -157,16 +134,7 @@ class DbLoader:
|
||||
add_all_files_filter(choose)
|
||||
add_grdb_filter(choose)
|
||||
|
||||
# Suggested folder: try last open file, import, then last export,
|
||||
# then home.
|
||||
default_dir = os.path.split(Config.get(Config.RECENT_FILE))[0] + os.path.sep
|
||||
if len(default_dir)<=1:
|
||||
default_dir = Config.get(Config.RECENT_IMPORT_DIR)
|
||||
if len(default_dir)<=1:
|
||||
default_dir = Config.get(Config.RECENT_EXPORT_DIR)
|
||||
if len(default_dir)<=1:
|
||||
default_dir = '~/'
|
||||
|
||||
default_dir = get_default_dir()
|
||||
new_filename = Utils.get_new_filename('grdb', default_dir)
|
||||
|
||||
choose.set_current_folder(default_dir)
|
||||
@ -213,17 +181,7 @@ class DbLoader:
|
||||
(box, type_selector) = format_maker(format_list)
|
||||
choose.set_extra_widget(box)
|
||||
|
||||
# Suggested folder: try last open file, import, then last export,
|
||||
# then home.
|
||||
default_dir = os.path.split(Config.get(Config.RECENT_FILE))[0] \
|
||||
+ os.path.sep
|
||||
if len(default_dir)<=1:
|
||||
default_dir = Config.get(Config.RECENT_IMPORT_DIR)
|
||||
if len(default_dir)<=1:
|
||||
default_dir = Config.get(Config.RECENT_EXPORT_DIR)
|
||||
if len(default_dir)<=1:
|
||||
default_dir = '~/'
|
||||
|
||||
default_dir = get_default_dir()
|
||||
new_filename = Utils.get_new_filename('grdb', default_dir)
|
||||
|
||||
choose.set_current_folder(default_dir)
|
||||
@ -313,17 +271,15 @@ class DbLoader:
|
||||
# then home.
|
||||
default_dir = Config.get(Config.RECENT_IMPORT_DIR)
|
||||
if len(default_dir)<=1:
|
||||
base_path = os.path.split(Config.get(Config.RECENT_FILE))[0]
|
||||
default_dir = base_path + os.path.sep
|
||||
if len(default_dir)<=1:
|
||||
default_dir = Config.get(Config.RECENT_EXPORT_DIR)
|
||||
if len(default_dir)<=1:
|
||||
default_dir = '~/'
|
||||
default_dir = get_default_dir()
|
||||
|
||||
choose.set_current_folder(default_dir)
|
||||
response = choose.run()
|
||||
if response == gtk.RESPONSE_OK:
|
||||
filename = choose.get_filename()
|
||||
if self.check_errors(filename):
|
||||
return False
|
||||
|
||||
filetype = type_selector.get_value()
|
||||
if filetype == 'auto':
|
||||
try:
|
||||
@ -408,15 +364,14 @@ class DbLoader:
|
||||
|
||||
def read_file(self, filename, filetype):
|
||||
"""
|
||||
This method takes care of enabling/disabling/emittin signals,
|
||||
changing database, and loading the data.
|
||||
This method takes care of changing database, and loading the data.
|
||||
|
||||
This method should only return on success.
|
||||
Returning on failure makes no sense, because we cannot recover,
|
||||
since database has already beeen changed.
|
||||
Therefore, any errors should raise exceptions.
|
||||
|
||||
We return with the disabled signals. The post-load routine
|
||||
On success, return with the disabled signals. The post-load routine
|
||||
should enable signals, as well as finish up with other UI goodies.
|
||||
"""
|
||||
|
||||
@ -428,8 +383,8 @@ class DbLoader:
|
||||
else:
|
||||
mode = "w"
|
||||
|
||||
factory = GrampsDb.gramps_db_factory
|
||||
self.dbstate.change_database(factory(db_type = filetype)())
|
||||
dbclass = GrampsDb.gramps_db_factory(db_type = filetype)
|
||||
self.dbstate.change_database(dbclass())
|
||||
self.dbstate.db.disable_signals()
|
||||
|
||||
self.uistate.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
|
||||
@ -447,7 +402,6 @@ class DbLoader:
|
||||
old_database = self.dbstate.db
|
||||
|
||||
self.dbstate.change_database_noclose(new_database)
|
||||
# self.dbstate.emit('database-changed', (new_database,) )
|
||||
old_database.disable_signals()
|
||||
new_database.disable_signals()
|
||||
|
||||
@ -466,7 +420,30 @@ class DbLoader:
|
||||
dialog.destroy()
|
||||
self.uistate.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
|
||||
self.uistate.progress.show()
|
||||
importer(self.dbstate.db, filename, self.uistate.pulse_progressbar)
|
||||
|
||||
try:
|
||||
importer(self.dbstate.db, filename, self.uistate.pulse_progressbar)
|
||||
dirname = os.path.dirname(filename) + os.path.sep
|
||||
Config.set(Config.RECENT_IMPORT_DIR,dirname)
|
||||
except Exception:
|
||||
log.error("Failed to import database.", exc_info=True)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# default dir selection
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
def get_default_dir():
|
||||
# Suggested folder: try last open file, last import, last export,
|
||||
# then home.
|
||||
default_dir = os.path.dirname(Config.get(Config.RECENT_FILE)) + os.path.sep
|
||||
if len(default_dir)<=1:
|
||||
default_dir = Config.get(Config.RECENT_IMPORT_DIR)
|
||||
if len(default_dir)<=1:
|
||||
default_dir = Config.get(Config.RECENT_EXPORT_DIR)
|
||||
if len(default_dir)<=1:
|
||||
default_dir = '~/'
|
||||
return default_dir
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
|
@ -613,7 +613,6 @@ class GedcomParser(UpdateCallback):
|
||||
|
||||
self.error_count = 0
|
||||
amap = Utils.personalConstantAttributes
|
||||
self.current = self.interval
|
||||
|
||||
self.attrs = amap.values()
|
||||
self.gedattr = {}
|
||||
@ -735,8 +734,6 @@ class GedcomParser(UpdateCallback):
|
||||
t = time.time() - t
|
||||
msg = _('Import Complete: %d seconds') % t
|
||||
|
||||
if self.callback:
|
||||
self.callback(100)
|
||||
self.db.transaction_commit(self.trans,_("GEDCOM import"))
|
||||
self.db.enable_signals()
|
||||
self.db.request_rebuild()
|
||||
|
@ -721,6 +721,10 @@ class ViewManager:
|
||||
self.window.window.set_cursor(None)
|
||||
|
||||
def post_load_newdb(self, filename, filetype):
|
||||
|
||||
if not filename:
|
||||
return
|
||||
|
||||
# This method is for UI stuff when the database has changed.
|
||||
# Window title, recent files, etc related to new file.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user