Merge branch 'master' into geps/gep-032-database-backend
Conflicts: gramps/plugins/importer/importcsv.py
This commit is contained in:
commit
c830311aca
@ -195,7 +195,9 @@ def import_as_dict(filename, user=None):
|
||||
#print("ERROR:", name, exception)
|
||||
return False
|
||||
import_function = getattr(mod, pdata.import_function)
|
||||
import_function(db, filename, user)
|
||||
results = import_function(db, filename, user)
|
||||
if results is None:
|
||||
return None
|
||||
return db
|
||||
return None
|
||||
|
||||
@ -311,9 +313,10 @@ def diff_db_to_file(old_db, filename, user=None):
|
||||
user = User()
|
||||
# First, get data as a DictionaryDb
|
||||
new_db = import_as_dict(filename, user, user)
|
||||
# Next get differences:
|
||||
diffs, m_old, m_new = diff_dbs(old_db, new_db, user)
|
||||
return diffs, m_old, m_new
|
||||
if new_db is not None:
|
||||
# Next get differences:
|
||||
diffs, m_old, m_new = diff_dbs(old_db, new_db, user)
|
||||
return diffs, m_old, m_new
|
||||
|
||||
def from_struct(struct):
|
||||
"""
|
||||
|
@ -197,3 +197,31 @@ class FormattingHelper(object):
|
||||
self._text_cache = {}
|
||||
self._markup_cache = {}
|
||||
|
||||
|
||||
class ImportInfo(object):
|
||||
"""
|
||||
Class object that can hold information about the import
|
||||
"""
|
||||
def __init__(self, default_info=None):
|
||||
"""
|
||||
Init of the import class.
|
||||
|
||||
This creates the datastructures to hold info
|
||||
"""
|
||||
if default_info is None:
|
||||
self.info = {}
|
||||
else:
|
||||
self.info = default_info
|
||||
|
||||
def info_text(self):
|
||||
"""
|
||||
Construct an info message from the data in the class.
|
||||
"""
|
||||
text = ""
|
||||
for key in self.info:
|
||||
# Do not fail; can this fail?
|
||||
try:
|
||||
text += "%s: %s\n" % (key, self.info[key])
|
||||
except:
|
||||
pass
|
||||
return text
|
||||
|
@ -51,7 +51,6 @@ _ = glocale.translation.sgettext
|
||||
ngettext = glocale.translation.ngettext # else "nearby" comments are ignored
|
||||
from gramps.gen.lib import ChildRef, Citation, Event, EventRef, EventType, Family, FamilyRelType, Name, NameType, Note, NoteType, Person, Place, Source, Surname, Tag
|
||||
from gramps.gen.db import DbTxn
|
||||
from gramps.gen.plug.utils import OpenFileOrStdin
|
||||
from gramps.gen.datehandler import parser as _dp
|
||||
from gramps.gen.utils.string import gender as gender_map
|
||||
from gramps.gen.utils.id import create_id
|
||||
@ -59,6 +58,7 @@ from gramps.gen.lib.eventroletype import EventRoleType
|
||||
from gramps.gen.constfunc import conv_to_unicode
|
||||
from gramps.gen.config import config
|
||||
from gramps.gen.display.place import displayer as place_displayer
|
||||
from gramps.gen.utils.libformatting import ImportInfo
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -76,54 +76,6 @@ def get_primary_event_ref_from_type(dbase, person, event_name):
|
||||
return ref
|
||||
return None
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Encoding support for CSV, from http://docs.python.org/lib/csv-examples.html
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class UTF8Recoder(object):
|
||||
"""
|
||||
Iterator that reads an encoded stream and reencodes the input to UTF-8
|
||||
"""
|
||||
def __init__(self, stream, encoding):
|
||||
self.reader = codecs.getreader(encoding)(stream)
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def __next__(self):
|
||||
"Encode the next line of the file."
|
||||
return self.reader.next().encode("utf-8")
|
||||
|
||||
next = __next__
|
||||
|
||||
class UnicodeReader(object):
|
||||
"""
|
||||
A CSV reader which will iterate over lines in the CSV file,
|
||||
which is encoded in the given encoding.
|
||||
"""
|
||||
|
||||
def __init__(self, csvfile, encoding="utf-8", **kwds):
|
||||
self.first_row = True
|
||||
csvfile = UTF8Recoder(csvfile, encoding)
|
||||
self.reader = csv.reader(csvfile, **kwds)
|
||||
|
||||
def __next__(self):
|
||||
"Read the next line of the file."
|
||||
row = next(self.reader)
|
||||
rowlist = [conv_to_unicode(s, "utf-8") for s in row]
|
||||
# Add check for Byte Order Mark (Windows, Notepad probably):
|
||||
if self.first_row:
|
||||
if len(rowlist) > 0 and rowlist[0].startswith("\ufeff"):
|
||||
rowlist[0] = rowlist[0][1:]
|
||||
self.first_row = False
|
||||
return rowlist
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
next = __next__
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Support and main functions
|
||||
@ -152,13 +104,13 @@ def importData(dbase, filename, user):
|
||||
config.get('preferences.tag-on-import') else None))
|
||||
try:
|
||||
dbase.prepare_import()
|
||||
with OpenFileOrStdin(filename, 'b') as filehandle:
|
||||
with open(filename, 'r') as filehandle:
|
||||
parser.parse(filehandle)
|
||||
dbase.commit_import()
|
||||
except EnvironmentError as err:
|
||||
user.notify_error(_("%s could not be opened\n") % filename, str(err))
|
||||
return
|
||||
return None # This module doesn't provide info about what got imported.
|
||||
return ImportInfo({_("Results"): _("done")})
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -262,12 +214,11 @@ class CSVParser(object):
|
||||
|
||||
def read_csv(self, filehandle):
|
||||
"Read the data from the file and return it as a list."
|
||||
reader = UnicodeReader(filehandle)
|
||||
try:
|
||||
data = [[r.strip() for r in row] for row in reader]
|
||||
data = [[r.strip() for r in row] for row in csv.reader(filehandle)]
|
||||
except csv.Error as err:
|
||||
self.user.notify_error(_('format error: line %(line)d: %(zero)s') % {
|
||||
'line' : reader.reader.line_num, 'zero' : err } )
|
||||
'line' : reader.line_num, 'zero' : err } )
|
||||
return None
|
||||
return data
|
||||
|
||||
|
@ -40,6 +40,7 @@ from gramps.gen.errors import DbError, GedcomError
|
||||
from gramps.gui.glade import Glade
|
||||
from gramps.plugins.lib.libmixin import DbMixin
|
||||
from gramps.plugins.lib import libgedcom
|
||||
from gramps.gen.utils.libformatting import ImportInfo
|
||||
# The following code is necessary to ensure that when Help->Plugin
|
||||
# Manager->Reload is executed, not only is the top-level exportgedcom file
|
||||
# reloaded, but also the dependent libgedcom. This ensures that testing can have
|
||||
@ -145,3 +146,4 @@ def importData(database, filename, user):
|
||||
except GedcomError as msg:
|
||||
user.notify_error(_('Error reading GEDCOM file'), str(msg))
|
||||
return
|
||||
return ImportInfo({_("Results"): _("done")})
|
||||
|
@ -44,6 +44,7 @@ LOG = logging.getLogger(".ImportGeneWeb")
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||
from gramps.gen.utils.libformatting import ImportInfo
|
||||
_ = glocale.translation.gettext
|
||||
ngettext = glocale.translation.ngettext # else "nearby" comments are ignored
|
||||
from gramps.gen.errors import GedcomError
|
||||
@ -93,6 +94,7 @@ def importData(database, filename, user):
|
||||
errmsg = _("%s could not be opened\n") % filename
|
||||
user.notify_error(errmsg,str(msg))
|
||||
return
|
||||
return ImportInfo({_("Results"): _("done")})
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# For a description of the file format see
|
||||
|
@ -54,6 +54,7 @@ from gramps.gen.lib import (Attribute, AttributeType, ChildRef, Date, Event,
|
||||
NameType, Note, NoteType, Person, Place, Source,
|
||||
Surname, Citation, Location, NameOriginType)
|
||||
from gramps.gen.db import DbTxn
|
||||
from gramps.gen.utils.libformatting import ImportInfo
|
||||
|
||||
class ProgenError(Exception):
|
||||
"""Error used to report Progen errors."""
|
||||
@ -83,6 +84,7 @@ def _importData(database, filename, user):
|
||||
except IOError as msg:
|
||||
user.notify_error(_("%s could not be opened") % filename, str(msg))
|
||||
return
|
||||
return ImportInfo({_("Results"): _("done")})
|
||||
|
||||
|
||||
def _find_from_handle(progen_id, table):
|
||||
|
@ -52,6 +52,7 @@ from gramps.gen.lib import (Address, Date, DateError, Event, EventRef,
|
||||
EventType, Name, NameType, Person, Surname, Url, UrlType)
|
||||
from gramps.gen.db import DbTxn
|
||||
from gramps.gen.plug.utils import OpenFileOrStdin
|
||||
from gramps.gen.utils.libformatting import ImportInfo
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -72,7 +73,7 @@ def importData(database, filename, user):
|
||||
except GrampsImportError as msg:
|
||||
user.notify_error(_("%s could not be opened\n") % filename, str(msg))
|
||||
return
|
||||
return None # This module doesn't provide info about what got imported.
|
||||
return ImportInfo({_("Results"): _("done")})
|
||||
|
||||
|
||||
def splitof_nameprefix(name):
|
||||
|
@ -243,6 +243,7 @@ gramps/gen/filters/rules/place/_hassourceof.py
|
||||
gramps/gen/filters/rules/place/_hastag.py
|
||||
gramps/gen/filters/rules/place/_hastitle.py
|
||||
gramps/gen/filters/rules/place/_inlatlonneighborhood.py
|
||||
gramps/gen/filters/rules/place/_isenclosedby.py
|
||||
gramps/gen/filters/rules/place/_matcheseventfilter.py
|
||||
gramps/gen/filters/rules/place/_matchesfilter.py
|
||||
gramps/gen/filters/rules/place/_matchessourceconfidence.py
|
||||
|
@ -8,7 +8,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2015-05-24 21:47-0700\n"
|
||||
"POT-Creation-Date: 2015-05-26 19:11+0200\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
@ -2576,6 +2576,7 @@ msgstr ""
|
||||
#: ../gramps/gen/filters/rules/place/_hasdata.py:54
|
||||
#: ../gramps/gen/filters/rules/place/_hasplace.py:60
|
||||
#: ../gramps/gen/filters/rules/place/_hastitle.py:51
|
||||
#: ../gramps/gen/filters/rules/place/_isenclosedby.py:51
|
||||
#: ../gramps/gen/filters/rules/place/_matcheseventfilter.py:53
|
||||
#: ../gramps/gen/filters/rules/repository/_hasrepo.py:53
|
||||
#: ../gramps/gen/filters/rules/repository/_matchesnamesubstringof.py:45
|
||||
@ -2713,6 +2714,7 @@ msgstr ""
|
||||
#: ../gramps/gen/filters/rules/person/_isrelatedwith.py:44
|
||||
#: ../gramps/gen/filters/rules/person/_matchidof.py:44
|
||||
#: ../gramps/gen/filters/rules/person/_relationshippathbetween.py:45
|
||||
#: ../gramps/gen/filters/rules/place/_isenclosedby.py:48
|
||||
#: ../gramps/gui/editors/filtereditor.py:517
|
||||
#: ../gramps/gui/glade/editplaceref.glade:230
|
||||
msgid "ID:"
|
||||
@ -4954,6 +4956,14 @@ msgid ""
|
||||
"longitude."
|
||||
msgstr ""
|
||||
|
||||
#: ../gramps/gen/filters/rules/place/_isenclosedby.py:49
|
||||
msgid "Places enclosed by another place"
|
||||
msgstr ""
|
||||
|
||||
#: ../gramps/gen/filters/rules/place/_isenclosedby.py:50
|
||||
msgid "Matches a place enclosed by a particular place"
|
||||
msgstr ""
|
||||
|
||||
#: ../gramps/gen/filters/rules/place/_matcheseventfilter.py:50
|
||||
msgid "Places of events matching the <event filter>"
|
||||
msgstr ""
|
||||
|
Loading…
x
Reference in New Issue
Block a user