diff --git a/po/POTFILES.in b/po/POTFILES.in index 663e21c7f..012612a1a 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -204,12 +204,6 @@ src/GrampsDbUtils/_GedcomStageOne.py #src/GrampsDbUtils/_GedcomLex.py src/GrampsDbUtils/_GedcomParse.py src/GrampsDbUtils/_GedcomTokens.py -src/GrampsDbUtils/_GrampsDbWriteXML.py -src/GrampsDbUtils/_GrampsDbWRFactories.py -src/GrampsDbUtils/_ReadGedcom.py -src/GrampsDbUtils/_ReadXML.py -src/GrampsDbUtils/_WriteGedcom.py -src/GrampsDbUtils/_WriteXML.py src/GrampsDbUtils/__init__.py # GrampsLocale package @@ -242,12 +236,11 @@ src/Selectors/_SelectorFactory.py src/Selectors/__init__.py # plugins directory +src/plugins/AgeOnDate.py src/plugins/all_events.py src/plugins/all_relations.py -src/plugins/siblings.py -src/plugins/AgeOnDate.py -src/plugins/AncestorTree.py src/plugins/AncestorReport.py +src/plugins/AncestorTree.py src/plugins/BookReport.py src/plugins/CalculateEstimatedDates.py src/plugins/Calendar.py @@ -267,9 +260,15 @@ src/plugins/EndOfLineReport.py src/plugins/Eval.py src/plugins/EventCmp.py src/plugins/EventNames.py -src/plugins/ExportCSV.py +src/plugins/ExportCd.py +src/plugins/ExportCsv.py +src/plugins/ExportFtree.py +src/plugins/ExportGedcom.py +src/plugins/ExportGeneWeb.py +src/plugins/ExportPkg.py src/plugins/ExportVCalendar.py src/plugins/ExportVCard.py +src/plugins/ExportXml.py src/plugins/ExtractCity.py src/plugins/FamilyGroup.py src/plugins/FanChart.py @@ -278,11 +277,14 @@ src/plugins/FindDupes.py src/plugins/GVFamilyLines.py src/plugins/GVHourGlass.py src/plugins/GVRelGraph.py -src/plugins/ImportCSV.py +src/plugins/ImportCsv.py +src/plugins/ImportGedcom.py src/plugins/ImportGeneWeb.py src/plugins/ImportGpkg.py src/plugins/ImportGrdb.py +src/plugins/ImportProGen.py src/plugins/ImportvCard.py +src/plugins/ImportXml.py src/plugins/IndivComplete.py src/plugins/KinshipReport.py src/plugins/Leak.py @@ -297,6 +299,7 @@ src/plugins/OwnerEditor.py src/plugins/PatchNames.py src/plugins/PlaceReport.py src/plugins/Rebuild.py +src/plugins/RebuildRefMap.py src/plugins/References.py src/plugins/RelCalc.py src/plugins/rel_da.py @@ -315,6 +318,7 @@ src/plugins/rel_pl.py src/plugins/RemoveUnused.py src/plugins/ReorderIds.py src/plugins/SameSurnames.py +src/plugins/siblings.py src/plugins/SimpleBookTitle.py src/plugins/SoundGen.py src/plugins/StatisticsChart.py @@ -322,11 +326,6 @@ src/plugins/Summary.py src/plugins/TimeLine.py src/plugins/Verify.py src/plugins/WebCal.py -src/plugins/WriteCD.py -src/plugins/WriteFtree.py -src/plugins/WriteGeneWeb.py -src/plugins/WritePkg.py -src/plugins/RebuildRefMap.py # PluginUtils package src/PluginUtils/_GuiOptions.py @@ -337,6 +336,7 @@ src/PluginUtils/_Tool.py src/gen/utils/dbutils.py src/gen/utils/progressmon.py src/gen/plug/__init__.py +src/gen/plug/_export.py src/gen/plug/_import.py src/gen/plug/_manager.py src/gen/plug/_plugin.py @@ -693,7 +693,6 @@ src/widgets/validatedmaskedentry.py # Glade files # src/docgen/gtkprintpreview.glade -src/GrampsDbUtils/gedcomimport.glade src/glade/edit_person.glade src/glade/gramps.glade src/glade/mergedata.glade @@ -703,14 +702,12 @@ src/glade/scratchpad.glade src/glade/paper_settings.glade src/plugins/NotRelated.glade src/plugins/book.glade -src/plugins/cdexport.glade src/plugins/changenames.glade src/plugins/changetype.glade -src/plugins/csvexport.glade src/plugins/desbrowse.glade src/plugins/eval.glade src/plugins/eventcmp.glade -src/plugins/genewebexport.glade +src/plugins/ImportGedcom.glade src/plugins/leak.glade src/plugins/merge.glade src/plugins/ownereditor.glade @@ -719,10 +716,12 @@ src/plugins/relcalc.glade src/plugins/soundex.glade src/plugins/summary.glade src/plugins/unused.glade -src/plugins/vcalendarexport.glade -src/plugins/vcardexport.glade +src/plugins/ExportCsv.glade +src/plugins/ExportFtree.glade +src/plugins/ExportGeneWeb.glade +src/plugins/ExportVCard.glade +src/plugins/ExportVCalendar.glade src/plugins/verify.glade -src/plugins/writeftree.glade # # Files to extract from and then merge into # diff --git a/src/ArgHandler.py b/src/ArgHandler.py index 01d677d8b..d9b543315 100644 --- a/src/ArgHandler.py +++ b/src/ArgHandler.py @@ -45,13 +45,9 @@ import logging # #------------------------------------------------------------------------- import const -import GrampsDbUtils -import Mime -from QuestionDialog import ErrorDialog import Config import RecentFiles import Utils -import gen.db.exceptions as GX import gen from DbManager import CLIDbManager, NAME_FILE, find_locker_name @@ -59,10 +55,6 @@ from PluginUtils import Tool from gen.plug import PluginManager from ReportBase import CATEGORY_BOOK, CATEGORY_CODE, cl_report -IMPORT_TYPES = (const.APP_GRAMPS_XML, const.APP_GEDCOM, - const.APP_GRAMPS_PKG, const.APP_GENEWEB, - const.APP_GRAMPS) - _help = """ Usage: gramps.py [OPTION...] --load-modules=MODULE1,MODULE2,... Dynamic modules to load @@ -74,7 +66,7 @@ Help options Application options -O, --open=FAMILY_TREE Open family tree -i, --import=FILENAME Import file - -o, --output=FILENAME Write file + -e, --export=FILENAME Export file -f, --format=FORMAT Specify format -a, --action=ACTION Specify action -p, --options=OPTIONS_STRING Specify options @@ -96,7 +88,7 @@ class ArgHandler: All following arguments will be ignored. -O, --open=FAMTREE : Family tree or family tree database dir to open. -i, --import=FILE : filename to import. - -o, --output=FILE : filename to export. + -e, --export=FILE : filename to export. -f, --format=FORMAT : format of the file preceding this option. If the filename (no flags) is specified, the interactive session is @@ -148,11 +140,9 @@ class ArgHandler: 1/ Just the family tree (name or database dir) 2/ -O, Open of a family tree 3/ -i, Import of any format understood by an importer, optionally provide - -f to indicate format (possible: 'gedcom','gramps-xml','gramps-pkg', - 'grdb','geneweb' - 4/ -o, output a family tree in required format, optionally provide - -f to indicate format (possible: 'gedcom', - 'gramps-xml','gramps-pkg','iso','wft','geneweb') + -f to indicate format + 4/ -e, export a family tree in required format, optionally provide + -f to indicate format 5/ -a, --action: An action (possible: 'check', 'summary', 'report', 'tool') 6/ -u, --force-unlock: A locked database can be unlocked by given this @@ -187,84 +177,19 @@ class ArgHandler: for opt_ix in range(len(options)): option, value = options[opt_ix] if option in ( '-O', '--open'): - self.handle_open_option(value) + self.__handle_open_option(value) elif option in ( '-i', '--import'): - fname = value - fullpath = os.path.abspath(os.path.expanduser(fname)) - format = None - ftype = Mime.get_type(fullpath) - if opt_ix -> # To get a Gedcom reader -> GrampsDb.gramps_db_reader_factory(db_type = const.APP_GEDCOM) - -""" -import const - -import logging -log = logging.getLogger(".GrampDb") - -from gen.db import GrampsDbException -from gen.plug import PluginManager - -def gramps_db_reader_factory(db_type): - """Factory class for obtaining a Gramps database importer. - - @param db_type: the type of backend required. - @type db_type: one of the app_* constants in const.py - - Raises GrampsDbException if the db_type is not recognised. - """ - if db_type == const.APP_GRAMPS_XML: - import _ReadXML as ReadXML - md = ReadXML.importData - elif db_type == const.APP_GEDCOM: - import _ReadGedcom as ReadGedcom - md = ReadGedcom.importData - else: - #see if registered importer - found = False - pmgr = PluginManager.get_instance() - for plugin in pmgr.get_import_plugins(): - if db_type in plugin.get_mime_types(): - print "Found import plugin for %s" % plugin.get_name() - found = True - md = plugin.get_import_function() - break - if not found: - raise GrampsDbException("Attempt to create a database " - "reader for unknown format: " - "db_type = %s" % (str(db_type))) - - return md - - - diff --git a/src/GrampsDbUtils/_WriteXML.py b/src/GrampsDbUtils/_WriteXML.py deleted file mode 100644 index 60e202eae..000000000 --- a/src/GrampsDbUtils/_WriteXML.py +++ /dev/null @@ -1,149 +0,0 @@ -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2000-2007 Donald N. Allingham -# Copyright (C) 2008 Brian G. Matherly -# Copyright (C) 2008 Gary Burton -# Copyright (C) 2008 Robert Cheramy -# -# 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$ - -""" -Contains the interface to allow a database to get written using -GRAMPS' XML file format. -""" - -#------------------------------------------------------------------------- -# -# load standard python libraries -# -#------------------------------------------------------------------------- -import shutil -import os -from gettext import gettext as _ - -#------------------------------------------------------------------------- -# -# load GRAMPS libraries -# -#------------------------------------------------------------------------- -import const -from QuestionDialog import ErrorDialog - -import GrampsDbUtils -import ExportOptions -from gen.db.exceptions import GrampsDbWriteFailure -import gen.proxy - -#------------------------------------------------------------------------- -# -# Attempt to load the GZIP library. Some version of python do not seem -# to be compiled with this available. -# -#------------------------------------------------------------------------- -try: - import gzip - _gzip_ok = 1 -except: - _gzip_ok = 0 - -#------------------------------------------------------------------------- -# -# export_data -# -#------------------------------------------------------------------------- -def export_data(database, filename, person, option_box, callback=None): - """ - Call the XML writer with the syntax expected by the export plugin. - """ - if os.path.isfile(filename): - try: - shutil.copyfile(filename, filename + ".bak") - shutil.copystat(filename, filename + ".bak") - except: - pass - - compress = _gzip_ok == 1 - - option_box.parse_options() - - if option_box.private: - database = gen.proxy.PrivateProxyDb(database) - - if option_box.restrict: - database = gen.proxy.LivingProxyDb( - database, gen.proxy.LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY) - - # Apply the Person Filter - if not option_box.cfilter.is_empty(): - database = gen.proxy.FilterProxyDb(database, option_box.cfilter) - - # Apply the Note Filter - if not option_box.nfilter.is_empty(): - database = gen.proxy.FilterProxyDb( - database, note_filter=option_box.nfilter) - - # Apply the ReferencedProxyDb to remove any objects not referenced - # after any of the other proxies have been applied - if option_box.unlinked: - database = gen.proxy.ReferencedProxyDb(database) - - g = XmlWriter(database, callback, 0, compress) - return g.write(filename) - -#------------------------------------------------------------------------- -# -# XmlWriter -# -#------------------------------------------------------------------------- -class XmlWriter(GrampsDbUtils.GrampsDbXmlWriter): - """ - Writes a database to the XML file. - """ - - def __init__(self, dbase, callback, strip_photos, compress=1): - GrampsDbUtils.GrampsDbXmlWriter.__init__( - self, dbase, strip_photos, compress, const.VERSION, callback) - - def write(self, filename): - """ - Write the database to the specified file. - """ - ret = 0 #False - try: - ret = GrampsDbUtils.GrampsDbXmlWriter.write(self, filename) - except GrampsDbWriteFailure, msg: - (m1,m2) = msg.messages() - ErrorDialog(m1, m2) - return ret - -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -TITLE = _('GRAMPS _XML database') -DESCRIPTION = _('The GRAMPS XML database is a text version of a family tree. ' - 'It is read-write compatible with ' - 'the present GRAMPS database format.') -CONFIG = (_('GRAMPS XML export options'), ExportOptions.WriterOptionBox) -FILENAME = 'gramps' - -from gen.plug import PluginManager -pmgr = PluginManager.get_instance() -pmgr.register_export(export_data, TITLE, DESCRIPTION, CONFIG, FILENAME) diff --git a/src/GrampsDbUtils/__init__.py b/src/GrampsDbUtils/__init__.py index ff30b7c15..c4cce0b05 100644 --- a/src/GrampsDbUtils/__init__.py +++ b/src/GrampsDbUtils/__init__.py @@ -22,28 +22,12 @@ """ This package implements additions to the the GrampsDb database. - -This package should be used for code that extended GrampsDb but also -depends on Gtk. - -A number of importers and exporters are provided to convert between -the different backend formats. - -To obtain a class that implements readers use the gramps_db_reader_factory -method. For information on using this factory see the -_GrampsDbUtilsFactories.py file comments. - """ from _GedcomInfo import (personalConstantEvents, familyConstantEvents, personalConstantAttributes) -from _GrampsDbWRFactories import gramps_db_reader_factory from _GedcomParse import GedcomParser -from _WriteGedcom import GedcomWriter - -from _GrampsDbWriteXML import GrampsDbXmlWriter -from _WriteXML import XmlWriter import _Backup as Backup diff --git a/src/GrampsDbUtils/test/_GrampsDbWRFactories_test.py b/src/GrampsDbUtils/test/_GrampsDbWRFactories_test.py deleted file mode 100644 index d692b5f77..000000000 --- a/src/GrampsDbUtils/test/_GrampsDbWRFactories_test.py +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env python -import unittest - -from test import test_util as tu -par = tu.path_append_parent() - -### -class Test1(unittest.TestCase): - """Test imports which are buried within functions - otherwise they may not get timely test coverage - - NB: if any test fails, check imports within that module - - """ - def test1a_buried_imports(self): - import sys - self.assertTrue(par in sys.path, - "par %r has to be in path!" % par) - ilist = ( - "_WriteXML", - "_WriteGedcom", - "_ReadXML", - "_ReadGedcom", - ) - for m in ilist: - try: - mod = __import__(m) - except ImportError: - mod = None - self.assertTrue(mod, "try import of module %r" % m) - -if __name__ == "__main__": - unittest.main() -#===eof=== diff --git a/src/GrampsDbUtils/test/gedwrite_breakup_test.py b/src/GrampsDbUtils/test/gedwrite_breakup_test.py deleted file mode 100644 index ade11704b..000000000 --- a/src/GrampsDbUtils/test/gedwrite_breakup_test.py +++ /dev/null @@ -1,57 +0,0 @@ -"""gedwrite_breakup_test tests the breakup function in GedcomWrite""" -import unittest as U - -from test.test_util import msg, path_append_parent -path_append_parent(); -import _WriteGedcom as WG - -class Test1(U.TestCase): - def test1a_common(s): - #txt, limit, [split-results] - L=4 - dat = ( - ##0123456 - ("a", L, ["a",]), - ("abc", L, ["abc",]), - ("abcd", L, ["abcd",]), - ("abcde", L, ["abcd","e"]), - ("1234567", L, ["1234","567"]), - ("12345678", L, ["1234","5678"]), - ("123456789", L, ["1234","5678", "9"]), - ) - for (t,l,r) in dat: - g = WG.breakup(t,l) - s.assertEquals(g,r, msg(g,r, "breakup(%r,%d) results" % (t,l))) - - def test1b_spaces(s): - #txt, limit, [split-results] - L=4 - dat = ( - ##0123456 - ("a b ", L, ["a b ",]), - (" a b", L, [" a b",]), - ("asdf g", L, ["asd", "f g"]), - (" z", L, [" ", "z"]), - (" z", L, [" ", " z"]), - (" A", 2, [" ", " ", " ", "A"]), - ) - for (t,l,r) in dat: - g = WG.breakup(t,l) - s.assertEquals(g,r, msg(g,r, "breakup(%r,%d) results" % (t,l))) - - def test1c_unusual(s): - #just documenting behavior for unlikely input - #txt, limit, [split-results] - dat = ( - ##0123456 - ("", 4, []), - ("xyz", 1, ["x", "y", "z"]), - ) - for (t,l,r) in dat: - g = WG.breakup(t,l) - s.assertEquals(g,r, msg(g,r, "breakup(%r,%d) results" % (t,l))) - s.assertRaises(ValueError, WG.breakup, "xy",0) - -if __name__ == "__main__": - U.main() -#===eof=== diff --git a/src/PluginUtils/_PluginWindows.py b/src/PluginUtils/_PluginWindows.py index c2f586968..fc23577f6 100644 --- a/src/PluginUtils/_PluginWindows.py +++ b/src/PluginUtils/_PluginWindows.py @@ -133,7 +133,7 @@ class PluginStatus(ManagedWindow.ManagedWindow): data = model.get_value(node, 3) name = model.get_value(node, 1) if data: - PluginTrace(self.uistate, self.track, data, name) + PluginTrace(self.uistate, [], data, name) def build_menu_names(self, obj): return (self.title, "") diff --git a/src/gen/plug/Makefile.am b/src/gen/plug/Makefile.am index 37dd7fe58..93beb1f10 100644 --- a/src/gen/plug/Makefile.am +++ b/src/gen/plug/Makefile.am @@ -10,6 +10,7 @@ pkgdatadir = $(datadir)/@PACKAGE@/gen/plug pkgdata_PYTHON = \ __init__.py \ + _export.py \ _import.py \ _manager.py \ _plugin.py diff --git a/src/gen/plug/__init__.py b/src/gen/plug/__init__.py index b8db1da02..c1479ec8f 100644 --- a/src/gen/plug/__init__.py +++ b/src/gen/plug/__init__.py @@ -24,5 +24,6 @@ The "plug" package for handling plugins in Gramps. from _plugin import Plugin from _manager import PluginManager from _import import ImportPlugin +from _export import ExportPlugin -__all__ = [ "menu", Plugin, PluginManager, ImportPlugin ] +__all__ = [ "menu", Plugin, PluginManager, ImportPlugin, ExportPlugin ] diff --git a/src/gen/plug/_export.py b/src/gen/plug/_export.py new file mode 100644 index 000000000..d8a0e96b1 --- /dev/null +++ b/src/gen/plug/_export.py @@ -0,0 +1,102 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2008 Brian G. Matherly +# +# 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$ + +""" +This module provides the Plugin class for export plugins. +""" + +from gen.plug import Plugin + +class ExportPlugin(Plugin): + """ + This class represents a plugin for exporting data from Gramps + """ + def __init__(self, name, description, export_function, + extension, config=None): + """ + @param name: A friendly name to call this plugin. + Example: "GEDCOM Export" + @type name: string + @param description: An short description of the plugin. + Example: "This plugin will export a GEDCOM file from database" + @type description: string + @param export_function: A function to call to perform the export. + The function must take the form: + def export_function(database, filename, option_box, callback): + where: + "db" is a Gramps database to import the data into + "filename" is the file that the data will be exported to + "callback" is a callable object that takes two parameters. + The first parameter is a progress indicator. + The second parameter is a text string. + @type export_function: callable + @param extension: The extension for the output file. + Example: "ged" + @type extension: str + @param config: Options for the exporter + @type config: tuple (??,??) + @return: nothing + """ + Plugin.__init__(self, name, description) + self.__name = name + self.__export_func = export_function + self.__extension = extension + self.__config = config + + def get_module_name(self): + """ + Get the name of the module that this plugin lives in. + + @return: a string representing the name of the module for this plugin + """ + return self.__export_func.__module__ + + def get_name(self): + """ + Get the short name for this plugins. + + @return: str + """ + return self.__name + + def get_export_function(self): + """ + Get the import function for this plugins. + + @return: the callable import_function passed into __init__ + """ + return self.__export_func + + def get_extension(self): + """ + Get the file extension for the export file. + + @return: str + """ + return self.__extension + + def get_config(self): + """ + Get the config. + + @return: (??,??) + """ + return self.__config \ No newline at end of file diff --git a/src/gen/plug/_import.py b/src/gen/plug/_import.py index dfd7b2a1a..dd16e4528 100644 --- a/src/gen/plug/_import.py +++ b/src/gen/plug/_import.py @@ -29,7 +29,7 @@ class ImportPlugin(Plugin): """ This class represents a plugin for importing data into Gramps """ - def __init__(self, name, description, import_function, mime_types=None): + def __init__(self, name, description, import_function, extension): """ @param name: A friendly name to call this plugin. Example: "GEDCOM Import" @@ -47,14 +47,14 @@ class ImportPlugin(Plugin): The first parameter is a progress indicator. The second parameter is a text string. @type import_function: callable - @param mime_types: A list of mime types that apply to the file type. - Example: "['application/x-gramps']" - @type mime_types: [str] (list of strings) + @param extension: The extension for the files imported by this plugin. + Example: "ged" + @type extension: str @return: nothing """ Plugin.__init__(self, name, description) self.__import_func = import_function - self.__mime_types = mime_types + self.__extension = extension def get_module_name(self): """ @@ -72,10 +72,10 @@ class ImportPlugin(Plugin): """ return self.__import_func - def get_mime_types(self): + def get_extension(self): """ - Get the list of mime types that apply to the import file. + Get the extension for the files imported by this plugin. - @return: [str] (list of strings) + @return: str """ - return self.__mime_types + return self.__extension diff --git a/src/gen/plug/_manager.py b/src/gen/plug/_manager.py index 8c36509e8..38b835c20 100644 --- a/src/gen/plug/_manager.py +++ b/src/gen/plug/_manager.py @@ -93,8 +93,8 @@ class PluginManager(gen.utils.Callback): self.__report_list = [] self.__quick_report_list = [] self.__tool_list = [] - self.__export_list = [] self.__import_plugins = [] + self.__export_plugins = [] self.__attempt_list = [] self.__loaddir_list = [] self.__textdoc_list = [] @@ -257,10 +257,6 @@ class PluginManager(gen.utils.Callback): """ Return the list of command line tool plugins. """ return self.__cli_tool_list - def get_export_list(self): - """ Return the list of export plugins. """ - return self.__export_list - def get_module_description(self, module): """ Given a module name, return the module description. """ return self.__mod2text.get(module, '') @@ -274,6 +270,9 @@ class PluginManager(gen.utils.Callback): if isinstance(plugin, gen.plug.ImportPlugin): self.__import_plugins.append(plugin) self.__mod2text[plugin.get_module_name()] = plugin.get_description() + if isinstance(plugin, gen.plug.ExportPlugin): + self.__export_plugins.append(plugin) + self.__mod2text[plugin.get_module_name()] = plugin.get_description() def get_import_plugins(self): """ @@ -282,24 +281,14 @@ class PluginManager(gen.utils.Callback): @return: [gen.plug.ImportPlugin] (a list of ImportPlugin instances) """ return self.__import_plugins - - def register_export(self, export_data, title, description='', config=None, - filename=''): - """ - Register an export filter, taking the task, file filter, - and the list of patterns for the filename matching. - """ - if description and filename: - del_index = -1 - for i in range(0, len(self.__export_list)): - if self.__export_list[i][1] == title: - del_index = i - if del_index != -1: - del self.__export_list[del_index] - self.__export_list.append( - (export_data, title, description, config, filename)) - self.__mod2text[export_data.__module__] = description + def get_export_plugins(self): + """ + Get the list of export plugins. + + @return: [gen.plug.ExportPlugin] (a list of ExportPlugin instances) + """ + return self.__export_plugins def register_tool(self, name, category, tool_class, options_class, modes, translated_name, status=_("Unknown"), @@ -545,8 +534,8 @@ class PluginManager(gen.utils.Callback): for filename, junk in self.__failmsg_list ] - self.__export_list[:] = [ item for item in self.__export_list - if item[0].__module__ not in failed_module_names ][:] + self.__export_plugins[:] = [ item for item in self.__export_plugins + if item.get_module_name not in failed_module_names ][:] self.__import_plugins[:] = [ item for item in self.__import_plugins if item.get_module_name not in failed_module_names ][:] self.__tool_list[:] = [ item for item in self.__tool_list diff --git a/src/gramps_main.py b/src/gramps_main.py index 131fc33b3..989a89fb7 100644 --- a/src/gramps_main.py +++ b/src/gramps_main.py @@ -275,9 +275,8 @@ class Gramps: # we may need to change the order of operation ah = ArgHandler.ArgHandler(state, self.vm, args) if ah.need_gui(): - retval = ah.handle_args() - if retval: - filename, filetype = retval + filename = ah.handle_args() + if filename: self.vm.post_init_interface(show_manager=False) self.vm.open_activate(filename) else: diff --git a/src/plugins/WriteCD.py b/src/plugins/ExportCd.py similarity index 94% rename from src/plugins/WriteCD.py rename to src/plugins/ExportCd.py index 356bdb69b..594c53af2 100644 --- a/src/plugins/WriteCD.py +++ b/src/plugins/ExportCd.py @@ -73,10 +73,10 @@ except: # GRAMPS modules # #------------------------------------------------------------------------- -from GrampsDbUtils import XmlWriter +from ExportXml import XmlWriter from Utils import media_path_full from QuestionDialog import ErrorDialog, MissingMediaDialog -from gen.plug import PluginManager +from gen.plug import PluginManager, ExportPlugin _title_string = _("Export to CD") @@ -85,7 +85,7 @@ _title_string = _("Export to CD") # writeData # #------------------------------------------------------------------------- -def writeData(database, filename, person, option_box=None, callback=None): +def writeData(database, filename, option_box=None, callback=None): writer = PackageWriter(database, filename, callback) return writer.export() @@ -299,13 +299,15 @@ class PackageWriter: # Register the plugin # #------------------------------------------------------------------------- -_title = _('_Export to CD (portable XML)') -_description = _('Exporting to CD copies all your data and media ' - 'object files to the CD Creator. You may later burn the CD ' - 'with this data, and that copy will be completely portable ' - 'across different machines and binary architectures.') -_config = None -_filename = 'burn' +_description = _('Exporting to CD copies all your data and media object files ' + 'to the CD Creator. You may later burn the CD with this data, ' + 'and that copy will be completely portable across different ' + 'machines and binary architectures.') pmgr = PluginManager.get_instance() -pmgr.register_export(writeData, _title, _description, _config, _filename) +plugin = ExportPlugin(name = _('_Export to CD (portable XML)'), + description = _description, + export_function = writeData, + extension = "burn", + config = None ) +pmgr.register_plugin(plugin) diff --git a/src/plugins/csvexport.glade b/src/plugins/ExportCsv.glade similarity index 100% rename from src/plugins/csvexport.glade rename to src/plugins/ExportCsv.glade diff --git a/src/plugins/ExportCSV.py b/src/plugins/ExportCsv.py similarity index 89% rename from src/plugins/ExportCSV.py rename to src/plugins/ExportCsv.py index 62609fbe1..88b31a96c 100644 --- a/src/plugins/ExportCSV.py +++ b/src/plugins/ExportCsv.py @@ -57,9 +57,9 @@ log = logging.getLogger(".ExportCSV") import gen.lib from Filters import GenericFilter, Rules, build_filter_menu import Utils -import Errors from QuestionDialog import ErrorDialog -from gen.plug import PluginManager +from gen.plug import PluginManager, ExportPlugin +import gen.proxy import DateHandler #------------------------------------------------------------------------- @@ -67,8 +67,8 @@ import DateHandler # The function that does the exporting # #------------------------------------------------------------------------- -def exportData(database,filename,person, option_box,callback=None): - gw = CSVWriter(database,person,0,filename, option_box,callback) +def exportData(database, filename, option_box=None, callback=None): + gw = CSVWriter(database, filename, option_box, callback) return gw.export_data() #------------------------------------------------------------------------- @@ -166,15 +166,12 @@ class CSVWriterOptionBox: """ def __init__(self,person): self.person = person - - def get_option_box(self): self.include_individuals = 1 self.include_marriages = 1 self.include_children = 1 - glade_file = "%s/csvexport.glade" % os.path.dirname(__file__) - if not os.path.isfile(glade_file): - glade_file = "plugins/csvexport.glade" + def get_option_box(self): + glade_file = os.path.join(os.path.dirname(__file__), "ExportCsv.glade") self.topDialog = glade.XML(glade_file,"csvExport","gramps") filter_obj = self.topDialog.get_widget("filter") @@ -229,12 +226,9 @@ class CSVWriterOptionBox: # #------------------------------------------------------------------------- class CSVWriter: - def __init__(self,database,person,cl=0,filename="", - option_box=None,callback=None): + def __init__(self, database, filename, option_box=None, callback=None): self.db = database - self.person = person self.option_box = option_box - self.cl = cl self.filename = filename self.callback = callback if callable(self.callback): # callback is really callable @@ -250,7 +244,9 @@ class CSVWriter: self.person_ids = {} if not option_box: - self.cl_setup() + self.include_individuals = 1 + self.include_marriages = 1 + self.include_children = 1 else: self.option_box.parse_options() @@ -258,48 +254,9 @@ class CSVWriter: self.include_marriages = self.option_box.include_marriages self.include_children = self.option_box.include_children - if self.option_box.cfilter is None: - for p in self.db.get_person_handles(sort_handles=False): - self.plist[p] = 1 - else: - try: - for p in self.option_box.cfilter.apply(self.db, - self.db.get_person_handles(sort_handles=False)): - self.plist[p] = 1 - except Errors.FilterError, msg: - (m1,m2) = msg.messages() - ErrorDialog(m1,m2) - return + if not option_box.cfilter.is_empty(): + self.db = gen.proxy.FilterProxyDb(self.db, option_box.cfilter) - # get the families for which these people are spouses: - self.flist = {} - for key in self.plist: - p = self.db.get_person_from_handle(key) - for family_handle in p.get_family_handle_list(): - self.flist[family_handle] = 1 - # now add the families for which these people are a child: - family_handles = self.db.get_family_handles() - for family_handle in family_handles: - family = self.db.get_family_from_handle(family_handle) - for child_ref in family.get_child_ref_list(): - child_handle = child_ref.ref - if child_handle in self.plist.keys(): - 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.include_individuals = 0 - self.include_marriages = 0 - self.include_children = 0 for p in self.db.get_person_handles(sort_handles=False): self.plist[p] = 1 # get the families for which these people are spouses: @@ -316,6 +273,16 @@ class CSVWriter: child_handle = child_ref.ref if child_handle in self.plist.keys(): 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 writeln(self): self.g.writerow([]) @@ -497,13 +464,17 @@ class CSVWriter: #------------------------------------------------------------------------- # -# Register all of the plugins +# Register the plugin # #------------------------------------------------------------------------- -_title = _('Comma _Separated Values Spreadsheet (CSV)') +_name = _('Comma _Separated Values Spreadsheet (CSV)') _description = _('CSV is a common spreadsheet format.') _config = (_('CSV spreadsheet options'),CSVWriterOptionBox) -_filename = 'csv' pmgr = PluginManager.get_instance() -pmgr.register_export(exportData,_title,_description,_config,_filename) +plugin = ExportPlugin(name = _name, + description = _description, + export_function = exportData, + extension = "csv", + config = _config ) +pmgr.register_plugin(plugin) \ No newline at end of file diff --git a/src/plugins/writeftree.glade b/src/plugins/ExportFtree.glade similarity index 100% rename from src/plugins/writeftree.glade rename to src/plugins/ExportFtree.glade diff --git a/src/plugins/WriteFtree.py b/src/plugins/ExportFtree.py similarity index 93% rename from src/plugins/WriteFtree.py rename to src/plugins/ExportFtree.py index 6b3888bbd..96658887c 100644 --- a/src/plugins/WriteFtree.py +++ b/src/plugins/ExportFtree.py @@ -29,7 +29,6 @@ # #------------------------------------------------------------------------- import os -from cStringIO import StringIO from gettext import gettext as _ #------------------------------------------------------------------------ @@ -56,15 +55,15 @@ import Utils from Filters import GenericFilter, Rules, build_filter_menu import Errors from QuestionDialog import ErrorDialog -from gen.plug import PluginManager +from gen.plug import PluginManager, ExportPlugin #------------------------------------------------------------------------- # # writeData # #------------------------------------------------------------------------- -def writeData(database, filename, person, option_box, callback=None): - writer = FtreeWriter(database, person, 0, filename, option_box, callback) +def writeData(database, filename, option_box=None, callback=None): + writer = FtreeWriter(database, filename, option_box, callback) return writer.export_data() class FtreeWriterOptionBox: @@ -74,11 +73,11 @@ class FtreeWriterOptionBox: """ def __init__(self, person): self.person = person + self.restrict = True def get_option_box(self): - self.restrict = True - base = os.path.dirname(__file__) - glade_file = "%s/%s" % (base,"writeftree.glade") + glade_file = os.path.join(os.path.dirname(__file__), + "ExportFtree.glade") self.top = glade.XML(glade_file, "top", "gramps") @@ -133,12 +132,10 @@ class FtreeWriterOptionBox: #------------------------------------------------------------------------- class FtreeWriter: - def __init__(self, database, person, cl=0, filename="", option_box=None, + def __init__(self, database, filename="", option_box=None, callback = None): self.db = database - self.person = person self.option_box = option_box - self.cl = cl self.filename = filename self.callback = callback if callable(self.callback): # callback is really callable @@ -303,15 +300,17 @@ def get_name(name, count): else: return "%s %s%s, %s" % (name.first_name, name.surname, val, name.suffix) -#------------------------------------------------------------------------- +#------------------------------------------------------------------------ # -# Register the plugin +# Register with the plugin system # -#------------------------------------------------------------------------- -_title = _('_Web Family Tree') -_description = _('Web Family Tree format.') +#------------------------------------------------------------------------ _config = (_('Web Family Tree export options'), FtreeWriterOptionBox) -_filename = 'wft' pmgr = PluginManager.get_instance() -pmgr.register_export(writeData, _title, _description, _config,_filename) +plugin = ExportPlugin(name = _('_Web Family Tree'), + description = _('Web Family Tree format.'), + export_function = writeData, + extension = "wft", + config = _config ) +pmgr.register_plugin(plugin) diff --git a/src/GrampsDbUtils/_WriteGedcom.py b/src/plugins/ExportGedcom.py similarity index 98% rename from src/GrampsDbUtils/_WriteGedcom.py rename to src/plugins/ExportGedcom.py index b26fbf045..922f8d39a 100644 --- a/src/GrampsDbUtils/_WriteGedcom.py +++ b/src/plugins/ExportGedcom.py @@ -40,13 +40,14 @@ import time #------------------------------------------------------------------------- import gen.lib import const -import _GedcomInfo as GedcomInfo +import GrampsDbUtils._GedcomInfo as GedcomInfo import Errors import ExportOptions import BasicUtils from Utils import media_path_full import gen.proxy from QuestionDialog import ErrorDialog +from gen.plug import PluginManager, ExportPlugin #------------------------------------------------------------------------- # @@ -306,12 +307,11 @@ class GedcomWriter(BasicUtils.UpdateCallback): so that it can provide visual feedback via a progress bar if needed. """ - def __init__(self, database, person, cmd_line=0, + def __init__(self, database, cmd_line=0, option_box=None, callback=None): BasicUtils.UpdateCallback.__init__(self, callback) self.dbase = database - self.person = person self.cmd_line = cmd_line self.dirname = None self.gedcom_file = None @@ -1502,14 +1502,13 @@ class GedcomWriter(BasicUtils.UpdateCallback): # # #------------------------------------------------------------------------- -def export_data(database, filename, person, option_box, callback=None): +def export_data(database, filename, option_box=None, callback=None): """ External interface used to register with the plugin system. """ ret = False try: - ged_write = GedcomWriter(database, person, 0, - option_box, callback) + ged_write = GedcomWriter(database, 0, option_box, callback) ret = ged_write.write_gedcom_file(filename) except IOError, msg: msg2 = _("Could not create %s") % filename @@ -1520,17 +1519,19 @@ def export_data(database, filename, person, option_box, callback=None): ErrorDialog(_("Could not create %s") % filename) return ret -#------------------------------------------------------------------------- +#------------------------------------------------------------------------ # +# Register with the plugin system # -# -#------------------------------------------------------------------------- -TITLE = _('GE_DCOM') -DESCRIPTION = _('GEDCOM is used to transfer data between genealogy programs. ' +#------------------------------------------------------------------------ +_description = _('GEDCOM is used to transfer data between genealogy programs. ' 'Most genealogy software will accept a GEDCOM file as input.') -CONFIG = (_('GEDCOM export options'), ExportOptions.WriterOptionBox) -FILENAME = 'ged' +_config = (_('GEDCOM export options'), ExportOptions.WriterOptionBox) -from gen.plug import PluginManager pmgr = PluginManager.get_instance() -pmgr.register_export(export_data, TITLE, DESCRIPTION, CONFIG, FILENAME) +plugin = ExportPlugin(name = _('GE_DCOM'), + description = _description, + export_function = export_data, + extension = "ged", + config = _config ) +pmgr.register_plugin(plugin) diff --git a/src/plugins/genewebexport.glade b/src/plugins/ExportGeneWeb.glade similarity index 100% rename from src/plugins/genewebexport.glade rename to src/plugins/ExportGeneWeb.glade diff --git a/src/plugins/WriteGeneWeb.py b/src/plugins/ExportGeneWeb.py similarity index 93% rename from src/plugins/WriteGeneWeb.py rename to src/plugins/ExportGeneWeb.py index 0c8bc555a..6a0a2de5c 100644 --- a/src/plugins/WriteGeneWeb.py +++ b/src/plugins/ExportGeneWeb.py @@ -55,9 +55,8 @@ import gen.lib from Filters import GenericFilter, Rules, build_filter_menu #import const import Utils -import Errors from QuestionDialog import ErrorDialog -from gen.plug import PluginManager +from gen.plug import PluginManager, ExportPlugin #------------------------------------------------------------------------- # @@ -77,9 +76,8 @@ class GeneWebWriterOptionBox: self.restrict = 1 self.private = 1 - glade_file = "%s/genewebexport.glade" % os.path.dirname(__file__) - if not os.path.isfile(glade_file): - glade_file = "plugins/genewebexport.glade" + glade_file = os.path.join(os.path.dirname(__file__), + "ExportGeneWeb.glade") self.topDialog = glade.XML(glade_file, "genewebExport", "gramps") self.topDialog.signal_autoconnect({ @@ -154,12 +152,10 @@ class GeneWebWriterOptionBox: self.images_path = "" class GeneWebWriter: - def __init__(self, database, person, cl=0, filename="", option_box=None, + def __init__(self, database, filename="", option_box=None, callback=None): self.db = database - self.person = person self.option_box = option_box - self.cl = cl self.filename = filename self.callback = callback if callable(self.callback): # callback is really callable @@ -175,7 +171,10 @@ class GeneWebWriter: self.person_ids = {} if not option_box: - self.cl_setup() + self.restrict = 0 + self.private = 0 + self.copy = 0 + self.images = 0 else: self.option_box.parse_options() @@ -188,23 +187,17 @@ class GeneWebWriter: self.images = self.option_box.images self.images_path = self.option_box.images_path - if self.option_box.cfilter is None: - for p in self.db.get_person_handles(sort_handles=False): - self.plist[p] = 1 - else: - try: - for p in self.option_box.cfilter.apply(self.db, self.db.get_person_handles(sort_handles=False)): - self.plist[p] = 1 - except Errors.FilterError, msg: - (m1, m2) = msg.messages() - ErrorDialog(m1, m2) - return + if not option_box.cfilter.is_empty(): + self.db = gen.proxy.FilterProxyDb(self.db, option_box.cfilter) - self.flist = {} - for key in self.plist: - p = self.db.get_person_from_handle(key) - for family_handle in p.get_family_handle_list(): - self.flist[family_handle] = 1 + for p in self.db.get_person_handles(sort_handles=False): + self.plist[p] = 1 + + self.flist = {} + for key in self.plist: + p = self.db.get_person_from_handle(key) + for family_handle in p.get_family_handle_list(): + self.flist[family_handle] = 1 # remove families that dont contain father AND mother # because GeneWeb requires both to be present @@ -229,22 +222,6 @@ class GeneWebWriter: self.callback(newval) self.oldval = newval - def cl_setup(self): - self.restrict = 0 - self.private = 0 - self.copy = 0 - self.images = 0 - - for p in self.db.get_person_handles(sort_handles=False): - self.plist[p] = 1 - - self.flist = {} - - for key in self.plist: - p = self.db.get_person_from_handle(key) - for family_handle in p.get_family_handle_list(): - self.flist[family_handle] = 1 - def writeln(self, text): self.g.write(self.iso8859('%s\n' % (text))) @@ -389,7 +366,7 @@ class GeneWebWriter: note = "" for notehandle in notelist: noteobj = self.db.get_note_from_handle(notehandle) - note += noteobj.get(False) + note += noteobj.get() note += " " if note and note != "": @@ -629,19 +606,22 @@ class GeneWebWriter: # # #------------------------------------------------------------------------- -def exportData(database,filename,person, option_box,callback=None): - gw = GeneWebWriter(database,person,0,filename, option_box,callback) +def exportData(database, filename, option_box=None, callback=None): + gw = GeneWebWriter(database, filename, option_box, callback) return gw.export_data() -#------------------------------------------------------------------------- +#------------------------------------------------------------------------ # +# Register with the plugin system # -# -#------------------------------------------------------------------------- -_title = _('_GeneWeb') +#------------------------------------------------------------------------ _description = _('GeneWeb is a web based genealogy program.') _config = (_('GeneWeb export options'), GeneWebWriterOptionBox) -_filename = 'gw' pmgr = PluginManager.get_instance() -pmgr.register_export(exportData, _title, _description, _config, _filename) +plugin = ExportPlugin(name = _('_GeneWeb'), + description = _description, + export_function = exportData, + extension = "gw", + config = _config ) +pmgr.register_plugin(plugin) \ No newline at end of file diff --git a/src/plugins/WritePkg.py b/src/plugins/ExportPkg.py similarity index 85% rename from src/plugins/WritePkg.py rename to src/plugins/ExportPkg.py index 7cc85053c..3f7b46218 100644 --- a/src/plugins/WritePkg.py +++ b/src/plugins/ExportPkg.py @@ -60,8 +60,8 @@ import gtk # GRAMPS modules # #------------------------------------------------------------------------- -from GrampsDbUtils import XmlWriter -from gen.plug import PluginManager +from ExportXml import XmlWriter +from gen.plug import PluginManager, ExportPlugin import Utils #------------------------------------------------------------------------- @@ -69,29 +69,30 @@ import Utils # writeData # #------------------------------------------------------------------------- -def writeData(database, filename, person, option_box, callback=None): - option_box.parse_options() - - if option_box.private: - database = gen.proxy.PrivateProxyDb(database) - - if option_box.restrict: - database = gen.proxy.LivingProxyDb( - database, gen.proxy.LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY) - - # Apply the Person Filter - if not option_box.cfilter.is_empty(): - database = gen.proxy.FilterProxyDb(database, option_box.cfilter) - - # Apply the Note Filter - if not option_box.nfilter.is_empty(): - database = gen.proxy.FilterProxyDb( - database, note_filter=option_box.nfilter) +def writeData(database, filename, option_box=None, callback=None): + if option_box: + option_box.parse_options() - # Apply the ReferencedProxyDb to remove any objects not referenced - # after any of the other proxies have been applied - if option_box.unlinked: - database = gen.proxy.ReferencedProxyDb(database) + if option_box.private: + database = gen.proxy.PrivateProxyDb(database) + + if option_box.restrict: + database = gen.proxy.LivingProxyDb( + database, gen.proxy.LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY) + + # Apply the Person Filter + if not option_box.cfilter.is_empty(): + database = gen.proxy.FilterProxyDb(database, option_box.cfilter) + + # Apply the Note Filter + if not option_box.nfilter.is_empty(): + database = gen.proxy.FilterProxyDb( + database, note_filter=option_box.nfilter) + + # Apply the ReferencedProxyDb to remove any objects not referenced + # after any of the other proxies have been applied + if option_box.unlinked: + database = gen.proxy.ReferencedProxyDb(database) writer = PackageWriter(database, filename, callback) return writer.export() @@ -225,17 +226,20 @@ class PackageWriter: g.close() return True - -#------------------------------------------------------------------------- + +#------------------------------------------------------------------------ # -# Register the plugin +# Register with the plugin system # -#------------------------------------------------------------------------- -_title = _('GRAM_PS package (portable XML)') +#------------------------------------------------------------------------ _description = _('GRAMPS package is an archived XML database together ' 'with the media object files.') _config = (_('GRAMPS package export options'), ExportOptions.WriterOptionBox) -_filename = 'gpkg' pmgr = PluginManager.get_instance() -pmgr.register_export(writeData, _title, _description, _config, _filename) +plugin = ExportPlugin(name = _('GRAM_PS package (portable XML)'), + description = _description, + export_function = writeData, + extension = "gpkg", + config = _config ) +pmgr.register_plugin(plugin) \ No newline at end of file diff --git a/src/plugins/vcalendarexport.glade b/src/plugins/ExportVCalendar.glade similarity index 100% rename from src/plugins/vcalendarexport.glade rename to src/plugins/ExportVCalendar.glade diff --git a/src/plugins/ExportVCalendar.py b/src/plugins/ExportVCalendar.py index 17470cc55..4eb96b346 100644 --- a/src/plugins/ExportVCalendar.py +++ b/src/plugins/ExportVCalendar.py @@ -59,7 +59,7 @@ import Utils from gen.lib import Date, EventType import Errors from QuestionDialog import ErrorDialog -from gen.plug import PluginManager +from gen.plug import PluginManager, ExportPlugin #------------------------------------------------------------------------- # @@ -75,9 +75,9 @@ class CalendarWriterOptionBox: def __init__(self, person): self.person = person - glade_file = "%s/vcalendarexport.glade" % os.path.dirname(__file__) - if not os.path.isfile(glade_file): - glade_file = "plugins/vcalendarexport.glade" + glade_file = os.path.join(os.path.dirname(__file__), + "ExportVCalendar.glade") + self.topDialog = glade.XML(glade_file, "calendarExport", "gramps") self.copy = 0 self.filter_menu = gtk.Menu() @@ -128,10 +128,9 @@ class CalendarWriterOptionBox: class CalendarWriter: - def __init__(self, database, person, cl=0, filename="", option_box=None, + def __init__(self, database, cl=0, filename="", option_box=None, callback=None): self.db = database - self.person = person self.option_box = option_box self.cl = cl self.filename = filename @@ -342,19 +341,22 @@ class CalendarWriter: # # #------------------------------------------------------------------------- -def exportData(database, filename, person, option_box, callback=None): - cw = CalendarWriter(database, person, 0, filename, option_box, callback) +def exportData(database, filename, option_box=None, callback=None): + cw = CalendarWriter(database, 0, filename, option_box, callback) return cw.export_data(filename) -#------------------------------------------------------------------------- +#------------------------------------------------------------------------ # +# Register with the plugin system # -# -#------------------------------------------------------------------------- -_title = _('vC_alendar') +#------------------------------------------------------------------------ _description = _('vCalendar is used in many calendaring and pim applications.') _config = (_('vCalendar export options'), CalendarWriterOptionBox) -_filename = 'vcs' pmgr = PluginManager.get_instance() -pmgr.register_export(exportData, _title, _description, _config, _filename) +plugin = ExportPlugin(name = _('vC_alendar'), + description = _description, + export_function = exportData, + extension = "vcs", + config = _config ) +pmgr.register_plugin(plugin) \ No newline at end of file diff --git a/src/plugins/vcardexport.glade b/src/plugins/ExportVCard.glade similarity index 100% rename from src/plugins/vcardexport.glade rename to src/plugins/ExportVCard.glade diff --git a/src/plugins/ExportVCard.py b/src/plugins/ExportVCard.py index de6753669..0b7a4c537 100644 --- a/src/plugins/ExportVCard.py +++ b/src/plugins/ExportVCard.py @@ -56,7 +56,7 @@ from Filters import GenericFilter, Rules, build_filter_menu from gen.lib import Date import Errors from QuestionDialog import ErrorDialog -from gen.plug import PluginManager +from gen.plug import PluginManager, ExportPlugin #------------------------------------------------------------------------- # @@ -74,9 +74,8 @@ class CardWriterOptionBox: def get_option_box(self): - glade_file = "%s/vcardexport.glade" % os.path.dirname(__file__) - if not os.path.isfile(glade_file): - glade_file = "plugins/vcardexport.glade" + glade_file = os.path.join(os.path.dirname(__file__), + "ExportVCard.glade") self.topDialog = glade.XML(glade_file,"vcardExport","gramps") @@ -125,10 +124,9 @@ class CardWriterOptionBox: self.cfilter = self.filter_menu.get_active().get_data("filter") class CardWriter: - def __init__(self, database, person, cl=0, filename="", option_box=None, + def __init__(self, database, cl=0, filename="", option_box=None, callback=None): self.db = database - self.person = person self.option_box = option_box self.cl = cl self.filename = filename @@ -258,19 +256,22 @@ class CardWriter: # # #------------------------------------------------------------------------- -def exportData(database, filename, person, option_box, callback=None): - cw = CardWriter(database, person, 0, filename, option_box, callback) +def exportData(database, filename, option_box=None, callback=None): + cw = CardWriter(database, 0, filename, option_box, callback) return cw.export_data(filename) -#------------------------------------------------------------------------- +#------------------------------------------------------------------------ # +# Register with the plugin system # -# -#------------------------------------------------------------------------- -_title = _('_vCard') +#------------------------------------------------------------------------ _description = _('vCard is used in many addressbook and pim applications.') _config = (_('vCard export options'), CardWriterOptionBox) -_filename = 'vcf' pmgr = PluginManager.get_instance() -pmgr.register_export(exportData, _title, _description, _config, _filename) +plugin = ExportPlugin(name = _('_vCard'), + description = _description, + export_function = exportData, + extension = "vcf", + config = _config ) +pmgr.register_plugin(plugin) diff --git a/src/GrampsDbUtils/_GrampsDbWriteXML.py b/src/plugins/ExportXml.py similarity index 93% rename from src/GrampsDbUtils/_GrampsDbWriteXML.py rename to src/plugins/ExportXml.py index b0a17b420..4c229e1d5 100644 --- a/src/GrampsDbUtils/_GrampsDbWriteXML.py +++ b/src/plugins/ExportXml.py @@ -2,6 +2,9 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2000-2007 Donald N. Allingham +# Copyright (C) 2008 Brian G. Matherly +# Copyright (C) 2008 Gary Burton +# Copyright (C) 2008 Robert Cheramy # # 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 @@ -23,8 +26,6 @@ """ Contains the interface to allow a database to get written using GRAMPS' XML file format. -This module contains all that is needed for xml write, however it does not -provide the export plugin functionality. That is provided in _WriteXML.py """ #------------------------------------------------------------------------- @@ -33,11 +34,13 @@ provide the export plugin functionality. That is provided in _WriteXML.py # #------------------------------------------------------------------------- import time +import shutil import os import codecs from xml.sax.saxutils import escape from gettext import gettext as _ + #------------------------------------------------------------------------ # # Set up logging @@ -51,10 +54,14 @@ log = logging.getLogger(".WriteXML") # load GRAMPS libraries # #------------------------------------------------------------------------- - import gen.lib from BasicUtils import UpdateCallback from gen.db.exceptions import GrampsDbWriteFailure +import const +from QuestionDialog import ErrorDialog +import ExportOptions +import gen.proxy +from gen.plug import PluginManager, ExportPlugin #------------------------------------------------------------------------- # @@ -76,15 +83,6 @@ strip_dict = dict.fromkeys(range(9)+range(12,20)) def escxml(d): return escape(d, { '"' : '"' } ) -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def quick_write(database, filename, version="unknown"): - g = GrampsDbXmlWriter(database,0,1,version) - g.write(filename) - #------------------------------------------------------------------------- # # @@ -1131,8 +1129,90 @@ def conf_priv(obj): #------------------------------------------------------------------------- # -# +# export_data # #------------------------------------------------------------------------- +def export_data(database, filename, option_box=None, callback=None): + """ + Call the XML writer with the syntax expected by the export plugin. + """ + if os.path.isfile(filename): + try: + shutil.copyfile(filename, filename + ".bak") + shutil.copystat(filename, filename + ".bak") + except: + pass -# Don't export a writer for plugins, that is the task of _WriteXML.py + compress = _gzip_ok == 1 + + if option_box: + option_box.parse_options() + + if option_box.private: + database = gen.proxy.PrivateProxyDb(database) + + if option_box.restrict: + database = gen.proxy.LivingProxyDb( + database, gen.proxy.LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY) + + # Apply the Person Filter + if not option_box.cfilter.is_empty(): + database = gen.proxy.FilterProxyDb(database, option_box.cfilter) + + # Apply the Note Filter + if not option_box.nfilter.is_empty(): + database = gen.proxy.FilterProxyDb( + database, note_filter=option_box.nfilter) + + # Apply the ReferencedProxyDb to remove any objects not referenced + # after any of the other proxies have been applied + if option_box.unlinked: + database = gen.proxy.ReferencedProxyDb(database) + + g = XmlWriter(database, callback, 0, compress) + return g.write(filename) + +#------------------------------------------------------------------------- +# +# XmlWriter +# +#------------------------------------------------------------------------- +class XmlWriter(GrampsDbXmlWriter): + """ + Writes a database to the XML file. + """ + + def __init__(self, dbase, callback, strip_photos, compress=1): + GrampsDbXmlWriter.__init__( + self, dbase, strip_photos, compress, const.VERSION, callback) + + def write(self, filename): + """ + Write the database to the specified file. + """ + ret = 0 #False + try: + ret = GrampsDbXmlWriter.write(self, filename) + except GrampsDbWriteFailure, msg: + (m1,m2) = msg.messages() + ErrorDialog(m1, m2) + return ret + +#------------------------------------------------------------------------ +# +# Register with the plugin system +# +#------------------------------------------------------------------------ +_description = _('Exporting to CD copies all your data and media object files ' + 'to the CD Creator. You may later burn the CD with this data, ' + 'and that copy will be completely portable across different ' + 'machines and binary architectures.') +_config = (_('GRAMPS XML export options'), ExportOptions.WriterOptionBox) + +pmgr = PluginManager.get_instance() +plugin = ExportPlugin(name = _('GRAMPS _XML database'), + description = _description, + export_function = export_data, + extension = "gramps", + config = _config ) +pmgr.register_plugin(plugin) \ No newline at end of file diff --git a/src/plugins/ImportCSV.py b/src/plugins/ImportCsv.py similarity index 99% rename from src/plugins/ImportCSV.py rename to src/plugins/ImportCsv.py index 980daf7b8..4fa489bc1 100644 --- a/src/plugins/ImportCSV.py +++ b/src/plugins/ImportCsv.py @@ -796,5 +796,5 @@ pmgr = PluginManager.get_instance() plugin = ImportPlugin(name = _('CSV Spreadheet'), description = _("Import data from CSV files"), import_function = importData, - mime_types = [_mime_type, _mime_type_rfc_4180]) + extension = "csv") pmgr.register_plugin(plugin) \ No newline at end of file diff --git a/src/GrampsDbUtils/gedcomimport.glade b/src/plugins/ImportGedcom.glade similarity index 99% rename from src/GrampsDbUtils/gedcomimport.glade rename to src/plugins/ImportGedcom.glade index 414f2f6e4..6f1731173 100644 --- a/src/GrampsDbUtils/gedcomimport.glade +++ b/src/plugins/ImportGedcom.glade @@ -639,7 +639,7 @@ True - This GEDCOM file has identified itself as using ANSEL encoding. Sometimes, this is in error. If the imported data contains unusual characters, undo the import, and override the character set by selecting a different encoding below. + This GEDCOM file has identified itself as using ANSEL enconding. Sometimes, this is in error. If the imported data contains unusual characters, undo the import, and override the character set by selecting a different encoding below. False False GTK_JUSTIFY_LEFT diff --git a/src/GrampsDbUtils/_ReadGedcom.py b/src/plugins/ImportGedcom.py similarity index 82% rename from src/GrampsDbUtils/_ReadGedcom.py rename to src/plugins/ImportGedcom.py index 2dd98198a..286cb6a2a 100644 --- a/src/GrampsDbUtils/_ReadGedcom.py +++ b/src/plugins/ImportGedcom.py @@ -45,9 +45,10 @@ LOG = logging.getLogger(".GedcomImport") # #------------------------------------------------------------------------ import Errors -from _GedcomParse import GedcomParser -from _GedcomStageOne import StageOne +from GrampsDbUtils._GedcomParse import GedcomParser +from GrampsDbUtils._GedcomStageOne import StageOne from QuestionDialog import ErrorDialog, DBErrorDialog +from gen.plug import PluginManager, ImportPlugin try: import Config @@ -61,7 +62,7 @@ except ImportError: # importData # #------------------------------------------------------------------------- -def importData(database, filename, callback=None, use_trans=False): +def importData(database, filename, callback=None): """ Try to handle ANSEL encoded files that are not really ANSEL encoded """ @@ -83,7 +84,8 @@ def importData(database, filename, callback=None, use_trans=False): ifile.close() if not gramps and ansel: - glade_file = "%s/gedcomimport.glade" % os.path.dirname(__file__) + glade_file = os.path.join(os.path.dirname(__file__), + "ImportGedcom.glade") top = glade.XML(glade_file, 'encoding','gramps') code = top.get_widget('codeset') code.set_active(0) @@ -94,17 +96,6 @@ def importData(database, filename, callback=None, use_trans=False): dialog.destroy() else: code_set = "" - import2(database, filename, callback, code_set, use_trans) - -#------------------------------------------------------------------------- -# -# import2 -# -#------------------------------------------------------------------------- -def import2(database, filename, callback, code_set, use_trans): - """ - Import the gedcom file. - """ assert(isinstance(code_set, basestring)) @@ -126,13 +117,10 @@ def import2(database, filename, callback, code_set, use_trans): _("%s could not be imported") % filename + "\n" + str(msg)) return - if database.get_number_of_people() == 0: - use_trans = False - try: read_only = database.readonly database.readonly = False - gedparse.parse_gedcom_file(use_trans) + gedparse.parse_gedcom_file(False) database.readonly = read_only ifile.close() except IOError, msg: @@ -146,3 +134,17 @@ def import2(database, filename, callback, code_set, use_trans): ErrorDialog(_('Error reading GEDCOM file'), str(msg)) return +#------------------------------------------------------------------------ +# +# Register with the plugin system +# +#------------------------------------------------------------------------ +_description = _('GEDCOM is used to transfer data between genealogy programs. ' + 'Most genealogy software will accept a GEDCOM file as input.') + +pmgr = PluginManager.get_instance() +plugin = ImportPlugin(name = _('GE_DCOM'), + description = _description, + import_function = importData, + extension = "ged" ) +pmgr.register_plugin(plugin) \ No newline at end of file diff --git a/src/plugins/ImportGeneWeb.py b/src/plugins/ImportGeneWeb.py index 13bf27491..803ffcc4c 100644 --- a/src/plugins/ImportGeneWeb.py +++ b/src/plugins/ImportGeneWeb.py @@ -47,7 +47,6 @@ log = logging.getLogger(".ImportGeneWeb") #------------------------------------------------------------------------- import Errors import gen.lib -import const from QuestionDialog import ErrorDialog from gen.plug import PluginManager, ImportPlugin from htmlentitydefs import name2codepoint @@ -926,5 +925,5 @@ pmgr = PluginManager.get_instance() plugin = ImportPlugin(name = _('GeneWeb'), description = _("Import data from GeneWeb files"), import_function = importData, - mime_types = [const.APP_GENEWEB]) + extension = "gw") pmgr.register_plugin(plugin) diff --git a/src/plugins/ImportGpkg.py b/src/plugins/ImportGpkg.py index acd530e3c..87b754383 100644 --- a/src/plugins/ImportGpkg.py +++ b/src/plugins/ImportGpkg.py @@ -47,7 +47,7 @@ log = logging.getLogger(".ReadPkg") # #------------------------------------------------------------------------- import const -from GrampsDbUtils import gramps_db_reader_factory +import ImportXml from QuestionDialog import ErrorDialog, WarningDialog import Utils from gen.plug import PluginManager, ImportPlugin @@ -93,7 +93,7 @@ def impData(database, name, cb=None): imp_db_name = os.path.join(tmpdir_path, const.XMLFILE) - importer = gramps_db_reader_factory(const.APP_GRAMPS_XML) + importer = ImportXml.importData info = importer(database, imp_db_name, cb) newmediapath = database.get_mediapath() #import of gpkg should not change media path as all media has new paths! @@ -146,5 +146,5 @@ pmgr = PluginManager.get_instance() plugin = ImportPlugin(name = _('GRAMPS package'), description = _("Import data from GRAMPS packages"), import_function = impData, - mime_types = ['application/x-gramps-package']) + extension = "gpkg") pmgr.register_plugin(plugin) diff --git a/src/plugins/ImportGrdb.py b/src/plugins/ImportGrdb.py index 423225dfe..86d28a361 100644 --- a/src/plugins/ImportGrdb.py +++ b/src/plugins/ImportGrdb.py @@ -2687,5 +2687,5 @@ plugin = ImportPlugin(name = _('GRAMPS 2.x database'), description = _("Import data from GRAMPS 2.x " "database files"), import_function = importData, - mime_types = ['application/x-gramps']) + extension = "grdb") pmgr.register_plugin(plugin) diff --git a/src/plugins/ImportProGen.py b/src/plugins/ImportProGen.py index cab70af66..2bcb33d8b 100644 --- a/src/plugins/ImportProGen.py +++ b/src/plugins/ImportProGen.py @@ -1218,5 +1218,5 @@ pmgr = PluginManager.get_instance() plugin = ImportPlugin(name = _('Pro-Gen'), description = _("Import data from Pro-Gen files"), import_function = _importData, - mime_types = ["application/x-progen"]) + extension = "def") pmgr.register_plugin(plugin) diff --git a/src/plugins/ImportvCard.py b/src/plugins/ImportVCard.py similarity index 94% rename from src/plugins/ImportvCard.py rename to src/plugins/ImportVCard.py index 8ebd6dbe0..81c945e33 100644 --- a/src/plugins/ImportvCard.py +++ b/src/plugins/ImportVCard.py @@ -160,7 +160,11 @@ class VCardParser: self.person = gen.lib.Person() def set_nick_name(self, fields, data): - self.person.set_nick_name(data) + if self.person is not None: + attr = gen.lib.Attribute() + attr.set_type(gen.lib.AttributeType.NICKNAME) + attr.set_value(data) + self.person.add_attribute(attr) def add_name(self, fields, data): data_fields = data.split(";") @@ -170,7 +174,7 @@ class VCardParser: name.set_first_name(data_fields[1]) if data_fields[2]: name.set_first_name(data_fields[1]+" "+data_fields[2]) - name.set_prefix(data_fields[3]) + name.set_surname_prefix(data_fields[3]) name.set_suffix(data_fields[4]) self.person.set_primary_name(name) @@ -200,7 +204,10 @@ class VCardParser: event = gen.lib.Event() event.set_type(gen.lib.EventType(gen.lib.EventType.BIRTH)) self.db.add_event(event,self.trans) - self.person.set_birth_handle(event.get_handle()) + + event_ref = gen.lib.EventRef() + event_ref.set_reference_handle(event.get_handle()) + self.person.set_birth_ref(event_ref) def add_url(self, fields, data): url = gen.lib.Url() @@ -216,5 +223,5 @@ pmgr = PluginManager.get_instance() plugin = ImportPlugin(name = _('vCard'), description = _("Import data from vCard files"), import_function = importData, - mime_types = ["text/x-vcard", "text/x-vcalendar"]) + extension = "vcf") pmgr.register_plugin(plugin) diff --git a/src/GrampsDbUtils/_ReadXML.py b/src/plugins/ImportXml.py similarity index 99% rename from src/GrampsDbUtils/_ReadXML.py rename to src/plugins/ImportXml.py index d9231c432..bbfadc18b 100644 --- a/src/GrampsDbUtils/_ReadXML.py +++ b/src/plugins/ImportXml.py @@ -46,8 +46,9 @@ from BasicUtils import name_displayer from gen.db.dbconst import (PERSON_KEY, FAMILY_KEY, SOURCE_KEY, EVENT_KEY, MEDIA_KEY, PLACE_KEY, REPOSITORY_KEY, NOTE_KEY) from BasicUtils import UpdateCallback -import _GrampsDbWriteXML +import ExportXml import const +from gen.plug import PluginManager, ImportPlugin #------------------------------------------------------------------------- # @@ -2443,7 +2444,7 @@ def version_is_valid(filename, cli): """ parser = VersionParser(filename) - if parser.get_xmlns_version() > _GrampsDbWriteXML.XML_VERSION: + if parser.get_xmlns_version() > ExportXml.XML_VERSION: msg = _("The .gramps file you are importing was made by version %s of " "GRAMPS, while you are running an older version %s. " "The file will not be imported. Please upgrade to the latest " @@ -2457,3 +2458,18 @@ def version_is_valid(filename, cli): return False return True + +#------------------------------------------------------------------------ +# +# Register with the plugin system +# +#------------------------------------------------------------------------ +pmgr = PluginManager.get_instance() +plugin = ImportPlugin(name = _('GRAMPS _XML database'), + description = _('The GRAMPS XML database is a text ' + 'version of a family tree. It is ' + 'read-write compatible with the ' + 'present GRAMPS database format.'), + import_function = importData, + extension = "gramps" ) +pmgr.register_plugin(plugin) \ No newline at end of file diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index c8f2e297d..67a39171b 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -30,9 +30,15 @@ pkgdata_PYTHON = \ Eval.py\ EventCmp.py\ EventNames.py\ - ExportCSV.py\ + ExportCd.py\ + ExportCsv.py\ + ExportFtree.py\ + ExportGedcom.py\ + ExportGeneweb.py\ + ExportPkg.py\ ExportVCalendar.py\ ExportVCard.py\ + ExportXml.py\ ExtractCity.py\ FamilyGroup.py\ FanChart.py\ @@ -42,10 +48,13 @@ pkgdata_PYTHON = \ GVHourGlass.py\ GVRelGraph.py\ ImportCSV.py\ + ImportGedcom.py\ ImportGeneWeb.py\ ImportGpkg.py\ ImportGrdb.py\ + ImportProGen.py\ ImportvCard.py\ + ImportXml.py\ IndivComplete.py\ KinshipReport.py\ Leak.py\ @@ -89,10 +98,7 @@ pkgdata_PYTHON = \ TimeLine.py\ Verify.py\ WebCal.py\ - WriteFtree.py\ - WriteGeneWeb.py\ - WritePkg.py\ - WriteCD.py + WriteFtree.py # DateParserDisplayTest.py\ # DumpGenderStats.py\ @@ -104,28 +110,28 @@ pkgpyexecdir = @pkgpyexecdir@/plugins pkgpythondir = @pkgpythondir@/plugins GLADEFILES = \ - NotRelated.glade\ - changetype.glade\ - csvexport.glade\ - desbrowse.glade\ - eventcmp.glade\ - merge.glade\ - patchnames.glade\ + book.glade\ changenames.glade\ + changetype.glade\ + desbrowse.glade\ + eval.glade\ + eventcmp.glade\ + ExportCsv.glade\ + ExportFtree.glade\ + ExportGeneWeb.glade\ + ExportVCalendar.glade\ + ExportVCard.glade\ + ImportGedcom.glade\ + leak.glade\ + merge.glade\ + NotRelated.glade\ + ownereditor.glade\ + patchnames.glade\ relcalc.glade\ soundex.glade\ summary.glade\ - verify.glade\ - cdexport.glade\ - eval.glade\ - leak.glade\ - book.glade\ - ownereditor.glade\ - writeftree.glade\ - genewebexport.glade\ - vcardexport.glade\ - vcalendarexport.glade\ - unused.glade + unused.glade\ + verify.glade GRAPHICS = diff --git a/src/plugins/cdexport.glade b/src/plugins/cdexport.glade deleted file mode 100644 index c398bd3ee..000000000 --- a/src/plugins/cdexport.glade +++ /dev/null @@ -1,189 +0,0 @@ - - - - - - - True - - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - True - True - False - False - - - - True - False - 8 - - - - True - GTK_BUTTONBOX_END - - - - True - True - True - gtk-cancel - True - GTK_RELIEF_NORMAL - 0 - - - - - - - True - True - True - GTK_RELIEF_NORMAL - -5 - - - - - True - 0.5 - 0.5 - 0 - 0 - - - - True - False - 2 - - - - True - gtk-cdrom - 4 - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - _Export to CD - True - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - - - - - - - True - True - True - gtk-help - True - GTK_RELIEF_NORMAL - -11 - - - - - - 0 - False - True - GTK_PACK_END - - - - - - 12 - True - False - 12 - - - - True - - False - False - GTK_JUSTIFY_CENTER - False - False - 0.5 - 0.5 - 0 - 0 - - - 6 - False - False - - - - - - True - Exporting to a CD will not immediately write the CD. It will prepare the nautilus-cd-burner so that you can burn the CD from nautilus. - -After exporting, go to the <b>burn:///</b> directory in nautilus and select the Write to CD button. - False - True - GTK_JUSTIFY_LEFT - True - False - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - 0 - True - True - - - - - - - diff --git a/test/GrampsDb/GrampsDbBase_Test.py b/test/GrampsDb/GrampsDbBase_Test.py index 785595dee..4aae361fb 100644 --- a/test/GrampsDb/GrampsDbBase_Test.py +++ b/test/GrampsDb/GrampsDbBase_Test.py @@ -42,20 +42,6 @@ class FactoryTest(unittest.TestCase): self.assertRaises(GrampsDb.GrampsDbException, GrampsDb.gramps_db_factory, "gibberish") - def test_gramps_db_reader_factory(self): - """Test that gramps_db_reader_factory returns the correct method.""" - - md = GrampsDb.gramps_db_reader_factory(db_type = const.app_gramps) - assert callable(md), "Returned method is %s " % str(md) - - md = GrampsDb.gramps_db_reader_factory(db_type = const.app_gramps_xml) - assert callable(md), "Returned method is %s " % str(md) - - md = GrampsDb.gramps_db_reader_factory(db_type = const.app_gedcom) - assert callable(md), "Returned method is %s " % str(md) - - self.assertRaises(GrampsDb.GrampsDbException, GrampsDb.gramps_db_reader_factory, "gibberish") - class ReferenceMapTest (GrampsDbBaseTest):