2003-10-13 07:25:56 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham, A. Roitman
|
2009-06-19 03:26:37 +05:30
|
|
|
# Copyright (C) 2007-2009 B. Malengier
|
2008-02-25 13:40:19 +05:30
|
|
|
# Copyright (C) 2008 Lukasz Rymarczyk
|
2008-02-25 15:35:15 +05:30
|
|
|
# Copyright (C) 2008 Raphael Ackermann
|
2008-05-19 00:54:28 +05:30
|
|
|
# Copyright (C) 2008 Brian G. Matherly
|
2003-10-13 07:25:56 +05:30
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
2009-07-04 21:25:43 +05:30
|
|
|
# $Id$
|
2003-10-13 07:25:56 +05:30
|
|
|
|
|
|
|
"""
|
|
|
|
Module responsible for handling the command line arguments for GRAMPS.
|
|
|
|
"""
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import os
|
2007-01-22 09:26:23 +05:30
|
|
|
import sys
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2003-10-13 07:25:56 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-11-25 11:12:31 +05:30
|
|
|
import RecentFiles
|
2006-04-21 09:44:00 +05:30
|
|
|
import Utils
|
2008-09-15 02:48:25 +05:30
|
|
|
import gen
|
2009-06-19 03:26:37 +05:30
|
|
|
from clidbman import CLIDbManager, NAME_FILE, find_locker_name
|
2006-04-21 09:44:00 +05:30
|
|
|
|
2008-10-02 09:32:10 +05:30
|
|
|
from PluginUtils import Tool
|
|
|
|
from gen.plug import PluginManager
|
2008-10-21 09:52:45 +05:30
|
|
|
from ReportBase import CATEGORY_BOOK, CATEGORY_CODE, cl_report
|
2003-10-13 07:25:56 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
# ArgHandler
|
|
|
|
#-------------------------------------------------------------------------
|
2009-05-21 22:49:50 +05:30
|
|
|
class ArgHandler(object):
|
2004-06-21 10:40:27 +05:30
|
|
|
"""
|
2009-08-09 22:39:32 +05:30
|
|
|
This class is responsible for the non GUI handling of commands.
|
2009-06-19 03:26:37 +05:30
|
|
|
The handler is passed a parser object, sanitizes it, and can execute the
|
2009-08-09 22:39:32 +05:30
|
|
|
actions requested working on a DbState.
|
2004-06-21 10:40:27 +05:30
|
|
|
"""
|
2003-10-13 07:25:56 +05:30
|
|
|
|
2009-06-19 03:26:37 +05:30
|
|
|
def __init__(self, dbstate, parser, sessionmanager,
|
|
|
|
errorfunc=None, gui=False):
|
|
|
|
self.dbstate = dbstate
|
|
|
|
self.sm = sessionmanager
|
|
|
|
self.errorfunc = errorfunc
|
|
|
|
self.gui = gui
|
|
|
|
if self.gui:
|
|
|
|
self.actions = []
|
|
|
|
self.list = False
|
|
|
|
self.list_more = False
|
|
|
|
self.open_gui = None
|
|
|
|
else:
|
|
|
|
self.actions = parser.actions
|
|
|
|
self.list = parser.list
|
|
|
|
self.list_more = parser.list_more
|
2009-06-19 14:16:17 +05:30
|
|
|
self.open_gui = parser.open_gui
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
self.imp_db_path = None
|
2009-06-19 14:16:17 +05:30
|
|
|
self.dbman = CLIDbManager(self.dbstate)
|
|
|
|
self.force_unlock = parser.force_unlock
|
|
|
|
self.cl = 0
|
|
|
|
self.imports = []
|
|
|
|
self.exports = []
|
|
|
|
|
|
|
|
self.open = self.__handle_open_option(parser.open)
|
|
|
|
self.sanitize_args(parser.imports, parser.exports)
|
2009-06-19 03:26:37 +05:30
|
|
|
|
2009-06-19 14:16:17 +05:30
|
|
|
def __error(self, string):
|
|
|
|
"""
|
2009-08-09 22:39:32 +05:30
|
|
|
Output an error. Uses errorfunc if given, otherwise a simple print.
|
2009-06-19 14:16:17 +05:30
|
|
|
"""
|
2009-06-19 03:26:37 +05:30
|
|
|
if self.errorfunc:
|
|
|
|
self.errorfunc(string)
|
|
|
|
else:
|
|
|
|
print string
|
2004-06-21 10:40:27 +05:30
|
|
|
|
2004-06-23 02:19:22 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
# Argument parser: sorts out given arguments
|
|
|
|
#-------------------------------------------------------------------------
|
2009-06-19 03:26:37 +05:30
|
|
|
def sanitize_args(self, importlist, exportlist):
|
2004-06-21 10:40:27 +05:30
|
|
|
"""
|
2009-08-09 22:39:32 +05:30
|
|
|
Check the lists with open, exports, imports, and actions options.
|
2004-06-21 10:40:27 +05:30
|
|
|
"""
|
2009-08-09 22:39:32 +05:30
|
|
|
for (value, family_tree_format) in importlist:
|
|
|
|
self.__handle_import_option(value, family_tree_format)
|
|
|
|
for (value, family_tree_format) in exportlist:
|
|
|
|
self.__handle_export_option(value, family_tree_format)
|
2006-05-22 23:37:12 +05:30
|
|
|
|
2008-11-04 09:42:51 +05:30
|
|
|
def __handle_open_option(self, value):
|
2008-09-15 02:48:25 +05:30
|
|
|
"""
|
2009-06-19 14:16:17 +05:30
|
|
|
Handle the "-O" or "--open" option.
|
|
|
|
Only Family trees or a dir with a family tree can be opened.
|
2008-09-15 02:48:25 +05:30
|
|
|
"""
|
2009-06-19 03:26:37 +05:30
|
|
|
if value is None:
|
|
|
|
return None
|
2008-11-04 09:42:51 +05:30
|
|
|
db_path = self.__deduce_db_path(value)
|
2008-09-15 02:48:25 +05:30
|
|
|
|
|
|
|
if db_path:
|
|
|
|
# We have a potential database path.
|
|
|
|
# Check if it is good.
|
2009-06-19 03:26:37 +05:30
|
|
|
if not self.check_db(db_path, self.force_unlock):
|
2008-09-15 02:48:25 +05:30
|
|
|
sys.exit(0)
|
2009-06-19 03:26:37 +05:30
|
|
|
return db_path
|
2008-09-15 02:48:25 +05:30
|
|
|
else:
|
2009-06-19 14:16:17 +05:30
|
|
|
self.__error( _('Error: Input family tree "%s" does not exist.\n'
|
2009-06-19 03:26:37 +05:30
|
|
|
"If gedcom, gramps-xml or grdb, use the -i option to "
|
|
|
|
"import into a family tree instead.") % value)
|
2008-09-15 02:48:25 +05:30
|
|
|
sys.exit(0)
|
2008-11-04 09:42:51 +05:30
|
|
|
|
2009-08-09 22:39:32 +05:30
|
|
|
def __handle_import_option(self, value, family_tree_format):
|
2008-11-04 09:42:51 +05:30
|
|
|
"""
|
2009-06-19 14:16:17 +05:30
|
|
|
Handle the "-i" or "--import" option.
|
2009-08-09 22:39:32 +05:30
|
|
|
Only Files supported by a plugin can be imported, so not Family Trees.
|
2008-11-04 09:42:51 +05:30
|
|
|
"""
|
|
|
|
fname = value
|
|
|
|
fullpath = os.path.abspath(os.path.expanduser(fname))
|
|
|
|
if not os.path.exists(fullpath):
|
2009-06-19 14:16:17 +05:30
|
|
|
self.__error(_('Error: Import file %s not found.') % fname)
|
2009-06-19 03:26:37 +05:30
|
|
|
sys.exit(0)
|
2008-11-04 09:42:51 +05:30
|
|
|
|
2009-08-09 22:39:32 +05:30
|
|
|
if family_tree_format is None:
|
2008-11-04 09:42:51 +05:30
|
|
|
# Guess the file format based on the file extension.
|
|
|
|
# This will get the lower case extension without a period,
|
|
|
|
# or an empty string.
|
2009-08-09 22:39:32 +05:30
|
|
|
family_tree_format = os.path.splitext(fname)[-1][1:].lower()
|
2008-11-04 09:42:51 +05:30
|
|
|
|
|
|
|
pmgr = PluginManager.get_instance()
|
|
|
|
plugin_found = False
|
|
|
|
for plugin in pmgr.get_import_plugins():
|
2009-08-09 22:39:32 +05:30
|
|
|
if family_tree_format == plugin.get_extension():
|
2008-11-04 09:42:51 +05:30
|
|
|
plugin_found = True
|
|
|
|
|
|
|
|
if plugin_found:
|
2009-08-09 22:39:32 +05:30
|
|
|
self.imports.append((fname, family_tree_format))
|
2008-11-04 09:42:51 +05:30
|
|
|
else:
|
2009-06-19 14:16:17 +05:30
|
|
|
self.__error(_('Error: Unrecognized type: "%(format)s" for '
|
2009-06-19 03:26:37 +05:30
|
|
|
'import file: %(filename)s') \
|
2009-08-09 22:39:32 +05:30
|
|
|
% {'format' : family_tree_format,
|
2009-06-19 03:26:37 +05:30
|
|
|
'filename' : fname})
|
|
|
|
sys.exit(0)
|
2008-11-04 09:42:51 +05:30
|
|
|
|
2009-08-09 22:39:32 +05:30
|
|
|
def __handle_export_option(self, value, family_tree_format):
|
2008-11-04 09:42:51 +05:30
|
|
|
"""
|
2009-06-19 03:26:37 +05:30
|
|
|
Handle the "-e" or "--export" option.
|
2009-08-09 22:39:32 +05:30
|
|
|
Note: this can only happen in the CLI version.
|
2008-11-04 09:42:51 +05:30
|
|
|
"""
|
2009-06-19 03:26:37 +05:30
|
|
|
if self.gui:
|
|
|
|
return
|
2008-11-04 09:42:51 +05:30
|
|
|
fname = value
|
|
|
|
fullpath = os.path.abspath(os.path.expanduser(fname))
|
|
|
|
if os.path.exists(fullpath):
|
2009-06-19 14:16:17 +05:30
|
|
|
self.__error(_("WARNING: Output file already exist!\n"
|
2009-06-19 03:26:37 +05:30
|
|
|
"WARNING: It will be overwritten:\n %(name)s") % \
|
|
|
|
{'name' : fullpath})
|
2008-11-04 09:42:51 +05:30
|
|
|
answer = None
|
|
|
|
while not answer:
|
2009-06-19 03:26:37 +05:30
|
|
|
answer = raw_input(_('OK to overwrite? (yes/no) '))
|
2009-06-19 14:16:17 +05:30
|
|
|
if answer.upper() in ('Y', 'YES', _('YES')):
|
|
|
|
self.__error( _("Will overwrite the existing file: %s")
|
2009-06-19 03:26:37 +05:30
|
|
|
% fullpath)
|
2008-11-04 09:42:51 +05:30
|
|
|
else:
|
2009-06-19 03:26:37 +05:30
|
|
|
sys.exit(0)
|
2008-11-04 09:42:51 +05:30
|
|
|
|
2009-08-09 22:39:32 +05:30
|
|
|
if family_tree_format is None:
|
2008-11-04 09:42:51 +05:30
|
|
|
# Guess the file format based on the file extension.
|
|
|
|
# This will get the lower case extension without a period,
|
|
|
|
# or an empty string.
|
2009-08-09 22:39:32 +05:30
|
|
|
family_tree_format = os.path.splitext(fname)[-1][1:].lower()
|
2008-11-04 09:42:51 +05:30
|
|
|
|
|
|
|
pmgr = PluginManager.get_instance()
|
|
|
|
plugin_found = False
|
|
|
|
for plugin in pmgr.get_export_plugins():
|
2009-08-09 22:39:32 +05:30
|
|
|
if family_tree_format == plugin.get_extension():
|
2008-11-04 09:42:51 +05:30
|
|
|
plugin_found = True
|
2008-09-15 02:48:25 +05:30
|
|
|
|
2008-11-04 09:42:51 +05:30
|
|
|
if plugin_found:
|
2009-08-09 22:39:32 +05:30
|
|
|
self.exports.append((fullpath, family_tree_format))
|
2008-11-04 09:42:51 +05:30
|
|
|
else:
|
2009-06-19 14:16:17 +05:30
|
|
|
self.__error(_("ERROR: Unrecognized format for export file %s")
|
2009-06-19 03:26:37 +05:30
|
|
|
% fname)
|
|
|
|
sys.exit(0)
|
2008-11-04 09:42:51 +05:30
|
|
|
|
|
|
|
def __deduce_db_path(self, db_name_or_path):
|
|
|
|
"""
|
|
|
|
Attempt to find a database path for the given parameter.
|
|
|
|
|
|
|
|
@return: The path to a Gramps DB
|
|
|
|
or None if a database can not be deduced.
|
|
|
|
"""
|
|
|
|
# First, check if this is the name of a family tree
|
|
|
|
db_path = self.dbman.get_family_tree_path(db_name_or_path)
|
|
|
|
|
|
|
|
if db_path is None:
|
|
|
|
# This is not a known database name.
|
|
|
|
# Check if the user provided a db path instead.
|
|
|
|
fullpath = os.path.abspath(os.path.expanduser(db_name_or_path))
|
|
|
|
if os.path.isdir(fullpath):
|
|
|
|
# The user provided a directory. Check if it is a valid tree.
|
|
|
|
name_file_path = os.path.join(fullpath, NAME_FILE)
|
|
|
|
if os.path.isfile(name_file_path):
|
|
|
|
db_path = fullpath
|
|
|
|
|
|
|
|
return db_path
|
2009-06-19 03:26:37 +05:30
|
|
|
|
2004-06-23 02:19:22 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
# Overall argument handler:
|
|
|
|
# sorts out the sequence and details of operations
|
|
|
|
#-------------------------------------------------------------------------
|
2009-06-19 14:16:17 +05:30
|
|
|
def handle_args_gui(self):
|
2004-06-21 10:40:27 +05:30
|
|
|
"""
|
2009-06-19 03:26:37 +05:30
|
|
|
method to handle the arguments that can be given for a GUI session.
|
2009-08-09 22:39:32 +05:30
|
|
|
Returns the filename of the family tree that should be opened if
|
2009-06-19 14:16:17 +05:30
|
|
|
user just passed a famtree or a filename
|
2009-06-19 03:26:37 +05:30
|
|
|
1/no options: a family tree can be given, if so, this name is tested
|
|
|
|
and returned. If a filename, it is imported in a new db
|
|
|
|
and name of new db returned
|
2009-06-19 14:16:17 +05:30
|
|
|
2/an open and/or import option can have been given, if so, this
|
|
|
|
is handled, and None is returned
|
2008-11-04 09:42:51 +05:30
|
|
|
|
2009-06-19 03:26:37 +05:30
|
|
|
"""
|
2005-01-30 05:04:09 +05:30
|
|
|
if self.open_gui:
|
2008-11-04 09:42:51 +05:30
|
|
|
# First check if a Gramps database was provided
|
|
|
|
# (either a database path or a database name)
|
|
|
|
db_path = self.__deduce_db_path(self.open_gui)
|
|
|
|
|
|
|
|
if not db_path:
|
|
|
|
# Apparently it is not a database. See if it is a file that
|
|
|
|
# can be imported.
|
|
|
|
db_path, title = self.dbman.import_new_db(self.open_gui, None)
|
|
|
|
|
|
|
|
if db_path:
|
2008-01-28 16:46:54 +05:30
|
|
|
# Test if not locked or problematic
|
2009-06-19 03:26:37 +05:30
|
|
|
if not self.check_db(db_path, self.force_unlock):
|
2008-01-28 16:46:54 +05:30
|
|
|
sys.exit(0)
|
2004-11-29 10:45:41 +05:30
|
|
|
# Add the file to the recent items
|
2008-11-04 09:42:51 +05:30
|
|
|
path = os.path.join(db_path, "name.txt")
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
try:
|
|
|
|
ifile = open(path)
|
|
|
|
title = ifile.readline().strip()
|
|
|
|
ifile.close()
|
|
|
|
except:
|
2008-11-04 09:42:51 +05:30
|
|
|
title = db_path
|
|
|
|
RecentFiles.recent_files(db_path, title)
|
2009-06-19 14:16:17 +05:30
|
|
|
self.open = db_path
|
|
|
|
self.__open_action()
|
2005-06-05 09:31:56 +05:30
|
|
|
else:
|
2009-06-19 03:26:37 +05:30
|
|
|
sys.exit(0)
|
2008-11-04 09:42:51 +05:30
|
|
|
return db_path
|
2009-06-19 03:26:37 +05:30
|
|
|
|
|
|
|
# if not open_gui, parse any command line args. We can only have one
|
|
|
|
# open argument, and perhaps some import arguments
|
|
|
|
self.__open_action()
|
|
|
|
self.__import_action()
|
2009-06-19 14:16:17 +05:30
|
|
|
return None
|
2009-06-19 03:26:37 +05:30
|
|
|
|
2009-08-02 09:01:39 +05:30
|
|
|
def handle_args_cli(self, cleanup=True):
|
2009-06-19 03:26:37 +05:30
|
|
|
"""
|
|
|
|
Depending on the given arguments, import or open data, launch
|
|
|
|
session, write files, and/or perform actions.
|
|
|
|
|
|
|
|
@param: climan: the manager of a CLI session
|
|
|
|
@type: CLIManager object
|
|
|
|
"""
|
2005-01-30 05:04:09 +05:30
|
|
|
|
2009-06-19 03:26:37 +05:30
|
|
|
if self.list:
|
|
|
|
print 'List of known family trees in your database path\n'
|
|
|
|
for name, dirname in self.dbman.family_tree_list():
|
|
|
|
print dirname, ', with name ', name
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
if self.list_more:
|
|
|
|
print 'GRAMPS Family Trees:'
|
|
|
|
summary_list = self.dbman.family_tree_summary()
|
|
|
|
for summary in summary_list:
|
|
|
|
print "Family Tree \"%s\":" % summary["Family tree"]
|
|
|
|
for item in summary:
|
|
|
|
if item != "Family tree":
|
|
|
|
print " %s: %s" % (item, summary[item])
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
self.__open_action()
|
|
|
|
self.__import_action()
|
|
|
|
|
|
|
|
for (action, options_str) in self.actions:
|
|
|
|
print "Performing action: %s." % action
|
|
|
|
if options_str:
|
|
|
|
print "Using options string: %s" % options_str
|
|
|
|
self.cl_action(action, options_str)
|
|
|
|
|
|
|
|
for expt in self.exports:
|
|
|
|
print "Exporting: file %s, format %s." % expt
|
|
|
|
self.cl_export(expt[0], expt[1])
|
|
|
|
|
2009-08-02 09:01:39 +05:30
|
|
|
if cleanup:
|
|
|
|
self.cleanup()
|
|
|
|
print "Exiting."
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
def cleanup(self):
|
2009-06-19 03:26:37 +05:30
|
|
|
print "Cleaning up."
|
|
|
|
# remove files in import db subdir after use
|
|
|
|
self.dbstate.db.close()
|
|
|
|
if self.imp_db_path:
|
|
|
|
Utils.rm_tempdir(self.imp_db_path)
|
|
|
|
|
|
|
|
def __import_action(self):
|
2009-06-19 14:16:17 +05:30
|
|
|
"""
|
|
|
|
Take action for all given to import files. Note: Family trees are not
|
|
|
|
supported.
|
|
|
|
If a fam tree is open, the import happens on top of it. If not open,
|
|
|
|
a new family tree is created, and the import done. If this is CLI,
|
|
|
|
the created tree is deleted at the end (as some action will have
|
|
|
|
happened that is now finished), if this is GUI, it is opened.
|
|
|
|
"""
|
2005-01-30 05:04:09 +05:30
|
|
|
if self.imports:
|
2006-04-10 23:47:00 +05:30
|
|
|
self.cl = bool(self.exports or self.actions or self.cl)
|
2005-01-30 05:04:09 +05:30
|
|
|
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
if not self.open:
|
|
|
|
# Create empty dir for imported database(s)
|
2009-06-19 03:26:37 +05:30
|
|
|
if self.gui:
|
2009-06-19 14:16:17 +05:30
|
|
|
self.imp_db_path, title = self.dbman.create_new_db_cli()
|
2009-06-19 03:26:37 +05:30
|
|
|
else:
|
|
|
|
self.imp_db_path = Utils.get_empty_tempdir("import_dbdir")
|
2008-09-15 02:48:25 +05:30
|
|
|
|
2009-06-19 03:26:37 +05:30
|
|
|
newdb = gen.db.GrampsDBDir()
|
|
|
|
newdb.write_version(self.imp_db_path)
|
2008-09-15 02:48:25 +05:30
|
|
|
|
2009-06-19 03:26:37 +05:30
|
|
|
try:
|
|
|
|
self.sm.open_activate(self.imp_db_path)
|
|
|
|
print "Created empty fam tree successfully"
|
|
|
|
except:
|
|
|
|
print "Error opening the file."
|
|
|
|
print "Exiting..."
|
2008-09-15 02:48:25 +05:30
|
|
|
sys.exit(0)
|
2004-06-21 10:40:27 +05:30
|
|
|
|
|
|
|
for imp in self.imports:
|
2004-06-23 02:19:22 +05:30
|
|
|
print "Importing: file %s, format %s." % imp
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
self.cl_import(imp[0], imp[1])
|
2004-06-23 02:19:22 +05:30
|
|
|
|
2009-06-19 03:26:37 +05:30
|
|
|
def __open_action(self):
|
2009-06-19 14:16:17 +05:30
|
|
|
"""
|
|
|
|
Take action on a Fam tree dir to open. It will be opened in the
|
|
|
|
sessionmanager
|
|
|
|
"""
|
2009-06-19 03:26:37 +05:30
|
|
|
if self.open:
|
|
|
|
# Family Tree to open was given. Open it
|
|
|
|
# Then go on and process the rest of the command line arguments.
|
|
|
|
self.cl = bool(self.exports or self.actions)
|
2006-04-10 23:47:00 +05:30
|
|
|
|
2009-06-19 03:26:37 +05:30
|
|
|
# we load this file for use
|
|
|
|
try:
|
|
|
|
self.sm.open_activate(self.open)
|
|
|
|
print "Opened successfully!"
|
|
|
|
except:
|
|
|
|
print "Error opening the file."
|
|
|
|
print "Exiting..."
|
|
|
|
sys.exit(0)
|
2003-10-13 07:25:56 +05:30
|
|
|
|
2009-06-19 03:26:37 +05:30
|
|
|
def check_db(self, dbpath, force_unlock = False):
|
2009-06-19 14:16:17 +05:30
|
|
|
"""
|
|
|
|
Test a given family tree path if it can be opened.
|
|
|
|
"""
|
2008-01-28 16:46:54 +05:30
|
|
|
# Test if not locked or problematic
|
|
|
|
if force_unlock:
|
|
|
|
self.dbman.break_lock(dbpath)
|
|
|
|
if self.dbman.is_locked(dbpath):
|
2009-06-19 14:16:17 +05:30
|
|
|
self.__error((_("Database is locked, cannot open it!") + '\n' +
|
|
|
|
_(" Info: %s")) % find_locker_name(dbpath))
|
2008-01-28 16:46:54 +05:30
|
|
|
return False
|
|
|
|
if self.dbman.needs_recovery(dbpath):
|
2009-06-19 14:16:17 +05:30
|
|
|
self.__error( _("Database needs recovery, cannot open it!"))
|
2008-01-28 16:46:54 +05:30
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2004-06-23 02:19:22 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Import handler
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-08-09 22:39:32 +05:30
|
|
|
def cl_import(self, filename, family_tree_format):
|
2004-06-21 10:40:27 +05:30
|
|
|
"""
|
2009-08-09 22:39:32 +05:30
|
|
|
Command-line import routine. Try to import filename using the family_tree_format.
|
2004-06-21 10:40:27 +05:30
|
|
|
"""
|
2008-11-04 09:42:51 +05:30
|
|
|
pmgr = PluginManager.get_instance()
|
|
|
|
for plugin in pmgr.get_import_plugins():
|
2009-08-09 22:39:32 +05:30
|
|
|
if family_tree_format == plugin.get_extension():
|
2008-11-04 09:42:51 +05:30
|
|
|
import_function = plugin.get_import_function()
|
2009-06-19 03:26:37 +05:30
|
|
|
import_function(self.dbstate.db, filename, None)
|
2008-11-04 09:42:51 +05:30
|
|
|
|
2006-04-10 23:47:00 +05:30
|
|
|
if not self.cl:
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
if self.imp_db_path:
|
2009-06-19 03:26:37 +05:30
|
|
|
return self.sm.open_activate(self.imp_db_path)
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
else:
|
2009-06-19 03:26:37 +05:30
|
|
|
return self.sm.open_activate(self.open)
|
2003-10-13 07:25:56 +05:30
|
|
|
|
2004-06-23 02:19:22 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Export handler
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-08-09 22:39:32 +05:30
|
|
|
def cl_export(self, filename, family_tree_format):
|
2004-06-21 10:40:27 +05:30
|
|
|
"""
|
|
|
|
Command-line export routine.
|
2009-08-09 22:39:32 +05:30
|
|
|
Try to write into filename using the family_tree_format.
|
2004-06-21 10:40:27 +05:30
|
|
|
"""
|
2008-11-04 09:42:51 +05:30
|
|
|
pmgr = PluginManager.get_instance()
|
|
|
|
for plugin in pmgr.get_export_plugins():
|
2009-08-09 22:39:32 +05:30
|
|
|
if family_tree_format == plugin.get_extension():
|
2008-11-04 09:42:51 +05:30
|
|
|
export_function = plugin.get_export_function()
|
2009-06-19 03:26:37 +05:30
|
|
|
export_function(self.dbstate.db, filename)
|
2003-10-13 07:25:56 +05:30
|
|
|
|
2004-06-23 02:19:22 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Action handler
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-02-18 18:01:31 +05:30
|
|
|
def cl_action(self, action, options_str):
|
2004-06-21 10:40:27 +05:30
|
|
|
"""
|
|
|
|
Command-line action routine. Try to perform specified action.
|
|
|
|
"""
|
2008-05-19 00:54:28 +05:30
|
|
|
pmgr = PluginManager.get_instance()
|
2003-10-13 07:25:56 +05:30
|
|
|
if action == 'check':
|
|
|
|
import Check
|
2009-06-19 20:53:58 +05:30
|
|
|
checker = Check.CheckIntegrity(self.dbstate, None, None)
|
2003-10-13 07:25:56 +05:30
|
|
|
checker.check_for_broken_family_links()
|
|
|
|
checker.cleanup_missing_photos(1)
|
|
|
|
checker.check_parent_relationships()
|
|
|
|
checker.cleanup_empty_families(0)
|
|
|
|
errs = checker.build_report(1)
|
|
|
|
if errs:
|
|
|
|
checker.report(1)
|
|
|
|
elif action == 'summary':
|
2009-06-19 20:53:58 +05:30
|
|
|
## FIXME, this is broken, Summary no longer has build_report !
|
2003-10-13 07:25:56 +05:30
|
|
|
import Summary
|
2009-06-19 03:26:37 +05:30
|
|
|
text = Summary.build_report(self.dbstate.db, None)
|
2008-01-17 17:05:15 +05:30
|
|
|
print text
|
2004-12-22 07:26:37 +05:30
|
|
|
elif action == "report":
|
|
|
|
try:
|
|
|
|
options_str_dict = dict( [ tuple(chunk.split('='))
|
|
|
|
for chunk in options_str.split(',') ] )
|
|
|
|
except:
|
|
|
|
options_str_dict = {}
|
|
|
|
print "Ignoring invalid options string."
|
|
|
|
|
2008-02-18 18:01:31 +05:30
|
|
|
name = options_str_dict.pop('name', None)
|
2008-05-19 00:54:28 +05:30
|
|
|
_cl_list = pmgr.get_cl_list()
|
2008-02-25 15:35:15 +05:30
|
|
|
if name:
|
2008-05-19 00:54:28 +05:30
|
|
|
for item in _cl_list:
|
2008-02-25 15:35:15 +05:30
|
|
|
if name == item[0]:
|
|
|
|
category = item[1]
|
|
|
|
report_class = item[2]
|
|
|
|
options_class = item[3]
|
2008-02-26 10:02:57 +05:30
|
|
|
if category in (CATEGORY_BOOK, CATEGORY_CODE):
|
2009-06-19 03:26:37 +05:30
|
|
|
options_class(self.dbstate.db, name, category,
|
2008-02-25 15:35:15 +05:30
|
|
|
options_str_dict)
|
|
|
|
else:
|
2009-06-19 14:16:17 +05:30
|
|
|
cl_report(self.dbstate.db, name, category,
|
|
|
|
report_class, options_class,
|
|
|
|
options_str_dict)
|
2008-02-25 15:35:15 +05:30
|
|
|
return
|
|
|
|
# name exists, but is not in the list of valid report names
|
|
|
|
msg = "Unknown report name."
|
|
|
|
else:
|
|
|
|
msg = "Report name not given. Please use -p name=reportname."
|
|
|
|
|
|
|
|
print "%s\n Available names are:" % msg
|
2008-05-19 00:54:28 +05:30
|
|
|
for item in _cl_list:
|
2008-02-25 13:40:19 +05:30
|
|
|
# Print cli report name ([item[0]) and GUI report name (item[4])
|
|
|
|
if len(item[0]) <= 25:
|
|
|
|
print " %s%s- %s" % (item[0],
|
|
|
|
" " * (26 - len(item[0])), item[4])
|
|
|
|
else:
|
|
|
|
print " %s\t- %s" % (item[0], item[4])
|
2008-02-25 15:35:15 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
elif action == "tool":
|
|
|
|
try:
|
|
|
|
options_str_dict = dict( [ tuple(chunk.split('=')) for
|
|
|
|
chunk in options_str.split(',') ] )
|
|
|
|
except:
|
|
|
|
options_str_dict = {}
|
|
|
|
print "Ignoring invalid options string."
|
|
|
|
|
2008-02-18 18:01:31 +05:30
|
|
|
name = options_str_dict.pop('name', None)
|
2008-05-19 00:54:28 +05:30
|
|
|
_cli_tool_list = pmgr.get_cl_tool_list()
|
2008-02-25 15:35:15 +05:30
|
|
|
if name:
|
2008-05-19 00:54:28 +05:30
|
|
|
for item in _cli_tool_list:
|
2008-02-25 15:35:15 +05:30
|
|
|
if name == item[0]:
|
|
|
|
category = item[1]
|
|
|
|
tool_class = item[2]
|
|
|
|
options_class = item[3]
|
2009-06-19 03:26:37 +05:30
|
|
|
Tool.cli_tool(self.dbstate, name, category, tool_class,
|
2008-02-25 15:35:15 +05:30
|
|
|
options_class, options_str_dict)
|
|
|
|
return
|
|
|
|
msg = "Unknown tool name."
|
|
|
|
else:
|
|
|
|
msg = "Tool name not given. Please use -p name=toolname."
|
|
|
|
|
|
|
|
print "%s\n Available names are:" % msg
|
2008-05-19 00:54:28 +05:30
|
|
|
for item in _cli_tool_list:
|
2005-12-06 12:08:09 +05:30
|
|
|
print " %s" % item[0]
|
2003-10-13 07:25:56 +05:30
|
|
|
else:
|
|
|
|
print "Unknown action: %s." % action
|
2009-06-19 03:26:37 +05:30
|
|
|
sys.exit(0)
|