3428: When running with pythonw.exe, Windows may crash if you write to stdout

svn: r14396
This commit is contained in:
Doug Blank
2010-02-16 02:18:24 +00:00
parent 7f1c3f0e70
commit 7f5e91d9ea
10 changed files with 138 additions and 165 deletions

View File

@@ -40,7 +40,7 @@ import codecs
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import logging import logging
log = logging.getLogger(".ExportCSV") LOG = logging.getLogger(".ExportCSV")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -309,8 +309,8 @@ class CSVWriter(object):
if self.include_children: if self.include_children:
self.total += len(self.flist) self.total += len(self.flist)
######################## ########################
print "Possible people to export:", len(self.plist) LOG.debug("Possible people to export: %s", len(self.plist))
print "Possible families to export:", len(self.flist) LOG.debug("Possible families to export: %s", len(self.flist))
########################### sort: ########################### sort:
sortorder = [] sortorder = []
for key in self.plist: for key in self.plist:

View File

@@ -41,7 +41,7 @@ import time
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import logging import logging
log = logging.getLogger(".ExportDjango") LOG = logging.getLogger(".ExportDjango")
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@@ -86,7 +86,7 @@ def export_all(database, filename, option_box=None, callback=None):
dji.clear_tables("primary", "secondary", "ref") dji.clear_tables("primary", "secondary", "ref")
for step in [0, 1]: for step in [0, 1]:
print >> sys.stderr, "Exporting Step %d..." % (step + 1) LOG.debug("Exporting Step %d..." % (step + 1))
# --------------------------------- # ---------------------------------
# Person # Person
# --------------------------------- # ---------------------------------
@@ -185,7 +185,7 @@ def export_all(database, filename, option_box=None, callback=None):
total_time = time.time() - start total_time = time.time() - start
msg = ngettext('Export Complete: %d second','Export Complete: %d seconds', total_time ) % total_time msg = ngettext('Export Complete: %d second','Export Complete: %d seconds', total_time ) % total_time
print >> sys.stderr, msg LOG.debug(msg)
return True return True
class NoFilenameOptions(ExportOptions.WriterOptionBox): class NoFilenameOptions(ExportOptions.WriterOptionBox):

View File

@@ -149,7 +149,7 @@ class GrampsXmlWriter(UpdateCallback):
else: else:
g = open(filename,"w") g = open(filename,"w")
except IOError,msg: except IOError,msg:
print str(msg) LOG.warn(str(msg))
raise DbWriteFailure((_('Failure writing %s') % filename, raise DbWriteFailure((_('Failure writing %s') % filename,
str(msg))) str(msg)))
return 0 return 0

View File

@@ -30,8 +30,6 @@
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import time import time
from gen.ggettext import sgettext as _
from gen.ggettext import ngettext
import csv import csv
import codecs import codecs
import cStringIO import cStringIO
@@ -42,19 +40,21 @@ import cStringIO
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import logging import logging
log = logging.getLogger(".ImportCSV") LOG = logging.getLogger(".ImportCSV")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.ggettext import sgettext as _
from gen.ggettext import ngettext
import gen.lib import gen.lib
from QuestionDialog import ErrorDialog from QuestionDialog import ErrorDialog
from DateHandler import parser as _dp from DateHandler import parser as _dp
from Utils import gender as gender_map from Utils import gender as gender_map
from gui.utils import ProgressMeter
from Utils import create_id from Utils import create_id
from gui.utils import ProgressMeter
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -138,7 +138,7 @@ def rd(line_number, row, col, key, default = None):
""" Return Row data by column name """ """ Return Row data by column name """
if key in col: if key in col:
if col[key] >= len(row): if col[key] >= len(row):
print "Warning: missing '%s, on line %d" % (key, line_number) LOG.warn("missing '%s, on line %d" % (key, line_number))
return default return default
retval = row[col[key]].strip() retval = row[col[key]].strip()
if retval == "": if retval == "":
@@ -312,7 +312,6 @@ class CSVParser(object):
self.db = db self.db = db
self.filename = filename self.filename = filename
self.callback = callback self.callback = callback
self.debug = 0
def readCSV(self): def readCSV(self):
fp = None fp = None
@@ -367,7 +366,7 @@ class CSVParser(object):
else: else:
return None return None
else: else:
print "error: invalid lookup type in CSV import: '%s'" % type LOG.warn("invalid lookup type in CSV import: '%s'" % type)
return None return None
def storeup(self, type, id, object): def storeup(self, type, id, object):
@@ -379,7 +378,7 @@ class CSVParser(object):
elif type == "family": elif type == "family":
self.fref[id.lower()] = object self.fref[id.lower()] = object
else: else:
print "error: invalid storeup type in CSV import: '%s'" % type LOG.warn("invalid storeup type in CSV import: '%s'" % type)
def process(self): def process(self):
progress = ProgressMeter(_('CSV Import')) progress = ProgressMeter(_('CSV Import'))
@@ -428,7 +427,7 @@ class CSVParser(object):
husband = self.lookup("person", husband) husband = self.lookup("person", husband)
if husband is None and wife is None: if husband is None and wife is None:
# might have children, so go ahead and add # might have children, so go ahead and add
print "Warning: no parents on line %d; adding family anyway" % line_number LOG.warn("no parents on line %d; adding family anyway" % line_number)
family = self.get_or_create_family(marriage_ref, husband, wife) family = self.get_or_create_family(marriage_ref, husband, wife)
# adjust gender, if not already provided # adjust gender, if not already provided
if husband: if husband:
@@ -488,7 +487,7 @@ class CSVParser(object):
# family, child # family, child
family_ref = rd(line_number, row, col, "family") family_ref = rd(line_number, row, col, "family")
if family_ref is None: if family_ref is None:
print "Error: no family reference found for family on line %d" % line_number LOG.warn("no family reference found for family on line %d" % line_number)
continue # required continue # required
child = rd(line_number, row, col, "child") child = rd(line_number, row, col, "child")
source = rd(line_number, row, col, "source") source = rd(line_number, row, col, "source")
@@ -497,17 +496,17 @@ class CSVParser(object):
child = self.lookup("person", child) child = self.lookup("person", child)
family = self.lookup("family", family_ref) family = self.lookup("family", family_ref)
if family is None: if family is None:
print "Error: no matching family reference found for family on line %d" % line_number LOG.warn("no matching family reference found for family on line %d" % line_number)
continue continue
if child is None: if child is None:
print "Error: no matching child reference found for family on line %d" % line_number LOG.warn("no matching child reference found for family on line %d" % line_number)
continue continue
# is this child already in this family? If so, don't add # is this child already in this family? If so, don't add
if self.debug: print "children:", [ref.ref for ref in family.get_child_ref_list()] LOG.debug("children: %s", [ref.ref for ref in family.get_child_ref_list()])
if self.debug: print "looking for:", child.get_handle() LOG.debug("looking for: %s", child.get_handle())
if child.get_handle() not in [ref.ref for ref in family.get_child_ref_list()]: if child.get_handle() not in [ref.ref for ref in family.get_child_ref_list()]:
# add child to family # add child to family
if self.debug: print " adding child to family", child.get_gramps_id(), family.get_gramps_id() LOG.debug(" adding child [%s] to family [%s]", child.get_gramps_id(), family.get_gramps_id())
childref = gen.lib.ChildRef() childref = gen.lib.ChildRef()
childref.set_reference_handle(child.get_handle()) childref.set_reference_handle(child.get_handle())
family.add_child_ref( childref) family.add_child_ref( childref)
@@ -529,7 +528,7 @@ class CSVParser(object):
source_refs = child.get_source_references() source_refs = child.get_source_references()
found = 0 found = 0
for ref in source_refs: for ref in source_refs:
if self.debug: print "child: looking for ref:", ref.ref, source.get_handle() LOG.debug("child: %s looking for ref: %s", ref.ref, source.get_handle())
if ref.ref == source.get_handle(): if ref.ref == source.get_handle():
found = 1 found = 1
if not found: if not found:
@@ -586,7 +585,7 @@ class CSVParser(object):
person = self.lookup("person", person_ref) person = self.lookup("person", person_ref)
if person is None: if person is None:
if surname is None: if surname is None:
print "Warning: empty surname for new person on line %d" % line_number LOG.warn("empty surname for new person on line %d" % line_number)
surname = "" surname = ""
# new person # new person
person = self.create_person(firstname, surname) person = self.create_person(firstname, surname)
@@ -686,7 +685,7 @@ class CSVParser(object):
source_refs = person.get_source_references() source_refs = person.get_source_references()
found = 0 found = 0
for ref in source_refs: for ref in source_refs:
if self.debug: print "person: looking for ref:", ref.ref, source.get_handle() LOG.debug("person: %s looking for ref: %s", ref.ref, source.get_handle())
if ref.ref == source.get_handle(): if ref.ref == source.get_handle():
found = 1 found = 1
if not found: if not found:
@@ -695,21 +694,21 @@ class CSVParser(object):
person.add_source_reference(sref) person.add_source_reference(sref)
self.db.commit_person(person, self.trans) self.db.commit_person(person, self.trans)
else: else:
print "Warning: ignoring line %d" % line_number LOG.warn("ignoring line %d" % line_number)
t = time.time() - t t = time.time() - t
msg = ngettext('Import Complete: %d second','Import Complete: %d seconds', t ) % t msg = ngettext('Import Complete: %d second','Import Complete: %d seconds', t ) % t
self.db.transaction_commit(self.trans,_("CSV import")) self.db.transaction_commit(self.trans,_("CSV import"))
self.db.enable_signals() self.db.enable_signals()
self.db.request_rebuild() self.db.request_rebuild()
print msg LOG.debug(msg)
print "New Families: %d" % self.fam_count LOG.debug("New Families: %d" % self.fam_count)
print "New Individuals: %d" % self.indi_count LOG.debug("New Individuals: %d" % self.indi_count)
progress.close() progress.close()
return None return None
def get_or_create_family(self, family_ref, husband, wife): def get_or_create_family(self, family_ref, husband, wife):
# if a gramps_id and exists: # if a gramps_id and exists:
if self.debug: print "get_or_create_family" LOG.debug("get_or_create_family")
if family_ref.startswith("[") and family_ref.endswith("]"): if family_ref.startswith("[") and family_ref.endswith("]"):
family = self.db.get_family_from_gramps_id(family_ref[1:-1]) family = self.db.get_family_from_gramps_id(family_ref[1:-1])
if family: if family:
@@ -724,7 +723,7 @@ class CSVParser(object):
if wife.get_handle() != fam_wife_handle: if wife.get_handle() != fam_wife_handle:
# this wife is not the same old one! Add her! # this wife is not the same old one! Add her!
family.set_mother_handle(wife.get_handle()) family.set_mother_handle(wife.get_handle())
if self.debug: print " returning existing family" LOG.debug(" returning existing family")
return family return family
# if not, create one: # if not, create one:
family = gen.lib.Family() family = gen.lib.Family()
@@ -752,13 +751,13 @@ class CSVParser(object):
def get_or_create_event(self, object, type, date=None, place=None, source=None): def get_or_create_event(self, object, type, date=None, place=None, source=None):
""" Add or find a type event on object """ """ Add or find a type event on object """
# first, see if it exists # first, see if it exists
if self.debug: print "get_or_create_event" LOG.debug("get_or_create_event")
ref_list = object.get_event_ref_list() ref_list = object.get_event_ref_list()
if self.debug: print "refs:", ref_list LOG.debug("refs: %s", ref_list)
# look for a match, and possible correction # look for a match, and possible correction
for ref in ref_list: for ref in ref_list:
event = self.db.get_event_from_handle(ref.ref) event = self.db.get_event_from_handle(ref.ref)
if self.debug: print " compare event type", int(event.get_type()), type LOG.debug(" compare event type %s == %s", int(event.get_type()), type)
if int(event.get_type()) == type: if int(event.get_type()) == type:
# Match! Let's update # Match! Let's update
if date: if date:
@@ -769,7 +768,7 @@ class CSVParser(object):
source_refs = event.get_source_references() source_refs = event.get_source_references()
found = 0 found = 0
for ref in source_refs: for ref in source_refs:
if self.debug: print "get_or_create_event: looking for ref:", ref.ref, source.get_handle() LOG.debug("get_or_create_event: %s looking for ref: %s", ref.ref, source.get_handle())
if ref.ref == source.get_handle(): if ref.ref == source.get_handle():
found = 1 found = 1
if not found: if not found:
@@ -777,10 +776,10 @@ class CSVParser(object):
sref.set_reference_handle(source.get_handle()) sref.set_reference_handle(source.get_handle())
event.add_source_reference(sref) event.add_source_reference(sref)
self.db.commit_event(event,self.trans) self.db.commit_event(event,self.trans)
if self.debug: print " returning existing event" LOG.debug(" returning existing event")
return (0, event) return (0, event)
# else create it: # else create it:
if self.debug: print " creating event" LOG.debug(" creating event")
event = gen.lib.Event() event = gen.lib.Event()
if type: if type:
event.set_type(gen.lib.EventType(type)) event.set_type(gen.lib.EventType(type))
@@ -792,7 +791,7 @@ class CSVParser(object):
source_refs = event.get_source_references() source_refs = event.get_source_references()
found = 0 found = 0
for ref in source_refs: for ref in source_refs:
if self.debug: print "looking for ref:", ref.ref, source.get_handle() LOG.debug("%s looking for ref: %s", ref.ref, source.get_handle())
if ref.ref == source.get_handle(): if ref.ref == source.get_handle():
found = 1 found = 1
if not found: if not found:
@@ -814,8 +813,8 @@ class CSVParser(object):
def get_or_create_place(self,place_name): def get_or_create_place(self,place_name):
place_list = self.db.iter_place_handles() place_list = self.db.iter_place_handles()
if self.debug: print "get_or_create_place: list:", list(place_list) LOG.debug("get_or_create_place: list: %s", list(place_list))
if self.debug: print "get_or_create_place: looking for:", place_name LOG.debug("get_or_create_place: looking for: %s", place_name)
for place_handle in place_list: for place_handle in place_list:
place = self.db.get_place_from_handle(place_handle) place = self.db.get_place_from_handle(place_handle)
if place.get_title() == place_name: if place.get_title() == place_name:
@@ -828,8 +827,8 @@ class CSVParser(object):
def get_or_create_source(self, source_text): def get_or_create_source(self, source_text):
source_list = self.db.get_source_handles() source_list = self.db.get_source_handles()
if self.debug: print "get_or_create_source: list:", source_list LOG.debug("get_or_create_source: list: %s", source_list)
if self.debug: print "get_or_create_source: looking for:", source_text LOG.debug("get_or_create_source: looking for: %s", source_text)
for source_handle in source_list: for source_handle in source_list:
source = self.db.get_source_from_handle(source_handle) source = self.db.get_source_from_handle(source_handle)
if source.get_title() == source_text: if source.get_title() == source_text:

View File

@@ -40,7 +40,7 @@ import os
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import logging import logging
log = logging.getLogger(".ImportDjango") LOG = logging.getLogger(".ImportDjango")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -186,8 +186,7 @@ class DjangoReader(object):
self.db.transaction_commit(self.trans, _("Django import")) self.db.transaction_commit(self.trans, _("Django import"))
self.db.enable_signals() self.db.enable_signals()
self.db.request_rebuild() self.db.request_rebuild()
print >> sys.stderr, msg LOG.debug(msg)
def import_data(db, filename, callback=None): def import_data(db, filename, callback=None):
g = DjangoReader(db, filename, callback) g = DjangoReader(db, filename, callback)

View File

@@ -39,7 +39,7 @@ from gen.ggettext import ngettext
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import logging import logging
log = logging.getLogger(".ImportGeneWeb") LOG = logging.getLogger(".ImportGeneWeb")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -66,8 +66,6 @@ _cal_map = {
'F' : gen.lib.Date.CAL_FRENCH, 'F' : gen.lib.Date.CAL_FRENCH,
} }
enable_debug = False
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# #
@@ -142,7 +140,7 @@ class GeneWebParser(object):
fields = line.split(" ") fields = line.split(" ")
self.debug("LINE: %s" %line) LOG.debug("LINE: %s" %line)
if fields[0] == "fam": if fields[0] == "fam":
self.current_mode = "fam" self.current_mode = "fam"
self.read_family_line(line,fields) self.read_family_line(line,fields)
@@ -172,7 +170,8 @@ class GeneWebParser(object):
elif fields[0] == "encoding:": elif fields[0] == "encoding:":
self.encoding = fields[1] self.encoding = fields[1]
else: else:
print "parse_geneweb_file(): Token >%s< unknown. line %d skipped: %s" % (fields[0],self.lineno,line) LOG.warn("parse_geneweb_file(): Token >%s< unknown. line %d skipped: %s" %
(fields[0],self.lineno,line))
except Errors.GedcomError, err: except Errors.GedcomError, err:
self.errmsg(str(err)) self.errmsg(str(err))
@@ -183,9 +182,9 @@ class GeneWebParser(object):
self.db.enable_signals() self.db.enable_signals()
self.db.request_rebuild() self.db.request_rebuild()
print msg LOG.debug(msg)
print "Families: %d" % len(self.fkeys) LOG.debug("Families: %d" % len(self.fkeys))
print "Individuals: %d" % len(self.ikeys) LOG.debug("Individuals: %d" % len(self.ikeys))
return None return None
def read_family_line(self,line,fields): def read_family_line(self,line,fields):
@@ -198,7 +197,7 @@ class GeneWebParser(object):
self.fkeys.append(self.current_family.get_handle()) self.fkeys.append(self.current_family.get_handle())
idx = 1; idx = 1;
self.debug("\nHusband:") LOG.debug("\nHusband:")
(idx, husband) = self.parse_person(fields,idx,gen.lib.Person.MALE,None) (idx, husband) = self.parse_person(fields,idx,gen.lib.Person.MALE,None)
if husband: if husband:
self.current_husband_handle = husband.get_handle() self.current_husband_handle = husband.get_handle()
@@ -206,9 +205,9 @@ class GeneWebParser(object):
self.db.commit_family(self.current_family,self.trans) self.db.commit_family(self.current_family,self.trans)
husband.add_family_handle(self.current_family.get_handle()) husband.add_family_handle(self.current_family.get_handle())
self.db.commit_person(husband,self.trans) self.db.commit_person(husband,self.trans)
self.debug("Marriage:") LOG.debug("Marriage:")
idx = self.parse_marriage(fields,idx) idx = self.parse_marriage(fields,idx)
self.debug("Wife:") LOG.debug("Wife:")
(idx,wife) = self.parse_person(fields,idx,gen.lib.Person.FEMALE,None) (idx,wife) = self.parse_person(fields,idx,gen.lib.Person.FEMALE,None)
if wife: if wife:
self.current_family.set_mother_handle(wife.get_handle()) self.current_family.set_mother_handle(wife.get_handle())
@@ -218,14 +217,14 @@ class GeneWebParser(object):
return None return None
def read_relationship_person(self,line,fields): def read_relationship_person(self,line,fields):
self.debug("\Relationships:") LOG.debug("\Relationships:")
(idx,person) = self.parse_person(fields,1,gen.lib.Person.UNKNOWN,None) (idx,person) = self.parse_person(fields,1,gen.lib.Person.UNKNOWN,None)
if person: if person:
self.current_relationship_person_handle = person.get_handle() self.current_relationship_person_handle = person.get_handle()
def read_relation_lines(self): def read_relation_lines(self):
if not self.current_relationship_person_handle: if not self.current_relationship_person_handle:
print "Unknown person for relationship in line %d!" % self.lineno LOG.warn("Unknown person for relationship in line %d!" % self.lineno)
return None return None
rel_person = self.db.get_person_from_handle(self.current_relationship_person_handle) rel_person = self.db.get_person_from_handle(self.current_relationship_person_handle)
while 1: while 1:
@@ -245,14 +244,14 @@ class GeneWebParser(object):
(idx,asso_p) = self.parse_person(fields,0,gen.lib.Person.UNKNOWN,None) (idx,asso_p) = self.parse_person(fields,0,gen.lib.Person.UNKNOWN,None)
pref = gen.lib.PersonRef() pref = gen.lib.PersonRef()
pref.set_relation(matches.groups()[0]) pref.set_relation(matches.groups()[0])
print("TODO: Handle association types properly") LOG.warn("TODO: Handle association types properly")
pref.set_reference_handle(asso_p.get_handle()) pref.set_reference_handle(asso_p.get_handle())
rel_person.add_person_ref(pref) rel_person.add_person_ref(pref)
self.db.commit_person(rel_person,self.trans) self.db.commit_person(rel_person,self.trans)
else: else:
print "Invalid name of person in line %d" % self.lineno LOG.warn("Invalid name of person in line %d" % self.lineno)
else: else:
print "Invalid relationship in line %d" % self.lineno LOG.warn("Invalid relationship in line %d" % self.lineno)
break break
self.current_mode = None self.current_mode = None
return None return None
@@ -261,7 +260,7 @@ class GeneWebParser(object):
def read_source_line(self,line,fields): def read_source_line(self,line,fields):
if not self.current_family: if not self.current_family:
print "Unknown family of child in line %d!" % self.lineno LOG.warn("Unknown family of child in line %d!" % self.lineno)
return None return None
source = self.get_or_create_source(self.decode(fields[1])) source = self.get_or_create_source(self.decode(fields[1]))
self.current_family.add_source_reference(source) self.current_family.add_source_reference(source)
@@ -269,7 +268,7 @@ class GeneWebParser(object):
return None return None
def read_witness_line(self,line,fields): def read_witness_line(self,line,fields):
self.debug("Witness:") LOG.debug("Witness:")
if fields[1] == "m:": if fields[1] == "m:":
(idx,wit_p) = self.parse_person(fields,2,gen.lib.Person.MALE,None) (idx,wit_p) = self.parse_person(fields,2,gen.lib.Person.MALE,None)
elif fields[1] == "f:": elif fields[1] == "f:":
@@ -298,12 +297,12 @@ class GeneWebParser(object):
def read_children_lines(self): def read_children_lines(self):
father_surname = "Dummy" father_surname = "Dummy"
if not self.current_husband_handle: if not self.current_husband_handle:
print "Unknown father for child in line %d!" % self.lineno LOG.warn("Unknown father for child in line %d!" % self.lineno)
return None return None
husb = self.db.get_person_from_handle(self.current_husband_handle) husb = self.db.get_person_from_handle(self.current_husband_handle)
father_surname = husb.get_primary_name().get_surname() father_surname = husb.get_primary_name().get_surname()
if not self.current_family: if not self.current_family:
print "Unknown family of child in line %d!" % self.lineno LOG.warn("Unknown family of child in line %d!" % self.lineno)
return None return None
while 1: while 1:
line = self.get_next_line() line = self.get_next_line()
@@ -314,7 +313,7 @@ class GeneWebParser(object):
fields = line.split(" ") fields = line.split(" ")
if fields[0] == "-": if fields[0] == "-":
self.debug("Child:") LOG.debug("Child:")
child = None child = None
if fields[1] == "h": if fields[1] == "h":
(idx,child) = self.parse_person(fields,2,gen.lib.Person.MALE,father_surname) (idx,child) = self.parse_person(fields,2,gen.lib.Person.MALE,father_surname)
@@ -363,7 +362,7 @@ class GeneWebParser(object):
def read_family_comment(self,line,fields): def read_family_comment(self,line,fields):
if not self.current_family: if not self.current_family:
print "Unknown family of child in line %d!" % self.lineno LOG.warn("Unknown family of child in line %d!" % self.lineno)
return None return None
n = gen.lib.Note() n = gen.lib.Note()
n.set(line) n.set(line)
@@ -424,8 +423,8 @@ class GeneWebParser(object):
#while idx < len(fields) and not fields[idx][0] == "+": #while idx < len(fields) and not fields[idx][0] == "+":
while idx < len(fields) and not (fields[idx] and fields[idx][0] == "+"): while idx < len(fields) and not (fields[idx] and fields[idx][0] == "+"):
if fields[idx]: if fields[idx]:
print "parse_marriage(): Unknown field:", \ LOG.warn(("parse_marriage(): Unknown field: " +
"'%s' in line %d!" % (fields[idx], self.lineno) "'%s' in line %d!") % (fields[idx], self.lineno))
idx += 1 idx += 1
while idx < len(fields) and mariageDataRe.match(fields[idx]): while idx < len(fields) and mariageDataRe.match(fields[idx]):
@@ -433,33 +432,33 @@ class GeneWebParser(object):
idx += 1 idx += 1
if field.startswith("+"): if field.startswith("+"):
mar_date = self.parse_date(self.decode(field)) mar_date = self.parse_date(self.decode(field))
self.debug(" Married at: %s" % field) LOG.debug(" Married at: %s" % field)
elif field.startswith("-"): elif field.startswith("-"):
div_date = self.parse_date(self.decode(field)) div_date = self.parse_date(self.decode(field))
self.debug(" Div at: %s" % field) LOG.debug(" Div at: %s" % field)
elif field == "#mp" and idx < len(fields): elif field == "#mp" and idx < len(fields):
mar_place = self.get_or_create_place(self.decode(fields[idx])) mar_place = self.get_or_create_place(self.decode(fields[idx]))
self.debug(" Marriage place: %s" % fields[idx]) LOG.debug(" Marriage place: %s" % fields[idx])
idx += 1 idx += 1
elif field == "#ms" and idx < len(fields): elif field == "#ms" and idx < len(fields):
mar_source = self.get_or_create_source(self.decode(fields[idx])) mar_source = self.get_or_create_source(self.decode(fields[idx]))
self.debug(" Marriage source: %s" % fields[idx]) LOG.debug(" Marriage source: %s" % fields[idx])
idx += 1 idx += 1
elif field == "#sep" and idx < len(fields): elif field == "#sep" and idx < len(fields):
sep_date = self.parse_date(self.decode(fields[idx])) sep_date = self.parse_date(self.decode(fields[idx]))
self.debug(" Seperated since: %s" % fields[idx]) LOG.debug(" Seperated since: %s" % fields[idx])
idx += 1 idx += 1
elif field == "#nm": elif field == "#nm":
self.debug(" Are not married.") LOG.debug(" Are not married.")
married = 0 married = 0
elif field == "#noment": elif field == "#noment":
self.debug(" Not mentioned.") LOG.debug(" Not mentioned.")
elif field == "#eng": elif field == "#eng":
self.debug(" Are engaged.") LOG.debug(" Are engaged.")
engaged = 1 engaged = 1
else: else:
print "parse_marriage(): Unknown field", \ LOG.warn(("parse_marriage(): Unknown field " +
"'%s'for mariage in line %d!" % (field, self.lineno) "'%s'for mariage in line %d!") % (field, self.lineno))
if mar_date or mar_place or mar_source: if mar_date or mar_place or mar_source:
mar = self.create_event( mar = self.create_event(
@@ -493,7 +492,7 @@ class GeneWebParser(object):
if not father_surname: if not father_surname:
if not idx < len(fields): if not idx < len(fields):
print "Missing surname of person in line %d!" % self.lineno LOG.warn("Missing surname of person in line %d!" % self.lineno)
surname ="" surname =""
else: else:
surname = self.decode(fields[idx]) surname = self.decode(fields[idx])
@@ -502,7 +501,7 @@ class GeneWebParser(object):
surname = father_surname surname = father_surname
if not idx < len(fields): if not idx < len(fields):
print "Missing firstname of person in line %d!" % self.lineno LOG.warn("Missing firstname of person in line %d!" % self.lineno)
firstname = "" firstname = ""
else: else:
firstname = self.decode(fields[idx]) firstname = self.decode(fields[idx])
@@ -513,7 +512,7 @@ class GeneWebParser(object):
surname = self.decode(fields[idx]) surname = self.decode(fields[idx])
idx += 1 idx += 1
self.debug("Person: %s %s" % (firstname, surname)) LOG.debug("Person: %s %s" % (firstname, surname))
person = self.get_or_create_person(firstname,surname) person = self.get_or_create_person(firstname,surname)
name = gen.lib.Name() name = gen.lib.Name()
name.set_type( gen.lib.NameType(gen.lib.NameType.BIRTH)) name.set_type( gen.lib.NameType(gen.lib.NameType.BIRTH))
@@ -556,13 +555,13 @@ class GeneWebParser(object):
field = fields[idx] field = fields[idx]
idx += 1 idx += 1
if field.startswith('('): if field.startswith('('):
self.debug("Public Name: %s" % field) LOG.debug("Public Name: %s" % field)
public_name = self.decode(field[1:-1]) public_name = self.decode(field[1:-1])
elif field.startswith('{'): elif field.startswith('{'):
self.debug("Firstsname Alias: %s" % field) LOG.debug("Firstsname Alias: %s" % field)
firstname_aliases.append(self.decode(field[1:-1])) firstname_aliases.append(self.decode(field[1:-1]))
elif field.startswith('['): elif field.startswith('['):
self.debug("Title: %s" % field) LOG.debug("Title: %s" % field)
titleparts = self.decode(field[1:-1]).split(":") titleparts = self.decode(field[1:-1]).split(":")
tname = ttitle = tplace = tstart = tend = tnth = None tname = ttitle = tplace = tstart = tend = tnth = None
try: try:
@@ -591,11 +590,11 @@ class GeneWebParser(object):
title_ref.set_reference_handle(title.get_handle()) title_ref.set_reference_handle(title.get_handle())
person.add_event_ref(title_ref) person.add_event_ref(title_ref)
elif field == '#nick' and idx < len(fields): elif field == '#nick' and idx < len(fields):
self.debug("Nick Name: %s" % fields[idx]) LOG.debug("Nick Name: %s" % fields[idx])
nick_names.append(self.decode(fields[idx])) nick_names.append(self.decode(fields[idx]))
idx += 1 idx += 1
elif field == '#occu' and idx < len(fields): elif field == '#occu' and idx < len(fields):
self.debug("Occupation: %s" % fields[idx]) LOG.debug("Occupation: %s" % fields[idx])
occu = self.create_event( occu = self.create_event(
gen.lib.EventType.OCCUPATION, self.decode(fields[idx])) gen.lib.EventType.OCCUPATION, self.decode(fields[idx]))
occu_ref = gen.lib.EventRef() occu_ref = gen.lib.EventRef()
@@ -603,80 +602,80 @@ class GeneWebParser(object):
person.add_event_ref(occu_ref) person.add_event_ref(occu_ref)
idx += 1 idx += 1
elif field == '#alias' and idx < len(fields): elif field == '#alias' and idx < len(fields):
self.debug("Name Alias: %s" % fields[idx]) LOG.debug("Name Alias: %s" % fields[idx])
name_aliases.append(self.decode(fields[idx])) name_aliases.append(self.decode(fields[idx]))
idx += 1 idx += 1
elif field == '#salias' and idx < len(fields): elif field == '#salias' and idx < len(fields):
self.debug("Surname Alias: %s" % fields[idx]) LOG.debug("Surname Alias: %s" % fields[idx])
surname_aliases.append(self.decode(fields[idx])) surname_aliases.append(self.decode(fields[idx]))
idx += 1 idx += 1
elif field == '#image' and idx < len(fields): elif field == '#image' and idx < len(fields):
self.debug("Image: %s" % fields[idx]) LOG.debug("Image: %s" % fields[idx])
idx += 1 idx += 1
elif field == '#src' and idx < len(fields): elif field == '#src' and idx < len(fields):
self.debug("Source: %s" % fields[idx]) LOG.debug("Source: %s" % fields[idx])
source = self.get_or_create_source(self.decode(fields[idx])) source = self.get_or_create_source(self.decode(fields[idx]))
idx += 1 idx += 1
elif field == '#bs' and idx < len(fields): elif field == '#bs' and idx < len(fields):
self.debug("Birth Source: %s" % fields[idx]) LOG.debug("Birth Source: %s" % fields[idx])
birth_source = self.get_or_create_source(self.decode(fields[idx])) birth_source = self.get_or_create_source(self.decode(fields[idx]))
idx += 1 idx += 1
elif field[0] == '!': elif field[0] == '!':
self.debug("Baptize at: %s" % fields[idx]) LOG.debug("Baptize at: %s" % fields[idx])
bapt_date = self.parse_date(self.decode(fields[idx][1:])) bapt_date = self.parse_date(self.decode(fields[idx][1:]))
idx += 1 idx += 1
elif field == '#bp' and idx < len(fields): elif field == '#bp' and idx < len(fields):
self.debug("Birth Place: %s" % fields[idx]) LOG.debug("Birth Place: %s" % fields[idx])
birth_place = self.get_or_create_place(self.decode(fields[idx])) birth_place = self.get_or_create_place(self.decode(fields[idx]))
idx += 1 idx += 1
elif field == '#pp' and idx < len(fields): elif field == '#pp' and idx < len(fields):
self.debug("Baptize Place: %s" % fields[idx]) LOG.debug("Baptize Place: %s" % fields[idx])
bapt_place = self.get_or_create_place(self.decode(fields[idx])) bapt_place = self.get_or_create_place(self.decode(fields[idx]))
idx += 1 idx += 1
elif field == '#ps' and idx < len(fields): elif field == '#ps' and idx < len(fields):
self.debug("Baptize Source: %s" % fields[idx]) LOG.debug("Baptize Source: %s" % fields[idx])
bapt_source = self.get_or_create_source(self.decode(fields[idx])) bapt_source = self.get_or_create_source(self.decode(fields[idx]))
idx += 1 idx += 1
elif field == '#dp' and idx < len(fields): elif field == '#dp' and idx < len(fields):
self.debug("Death Place: %s" % fields[idx]) LOG.debug("Death Place: %s" % fields[idx])
death_place = self.get_or_create_place(self.decode(fields[idx])) death_place = self.get_or_create_place(self.decode(fields[idx]))
idx += 1 idx += 1
elif field == '#ds' and idx < len(fields): elif field == '#ds' and idx < len(fields):
self.debug("Death Source: %s" % fields[idx]) LOG.debug("Death Source: %s" % fields[idx])
death_source = self.get_or_create_source(self.decode(fields[idx])) death_source = self.get_or_create_source(self.decode(fields[idx]))
idx += 1 idx += 1
elif field == '#buri' and idx < len(fields): elif field == '#buri' and idx < len(fields):
self.debug("Burial Date: %s" % fields[idx]) LOG.debug("Burial Date: %s" % fields[idx])
bur_date = self.parse_date(self.decode(fields[idx])) bur_date = self.parse_date(self.decode(fields[idx]))
idx += 1 idx += 1
elif field == '#crem' and idx < len(fields): elif field == '#crem' and idx < len(fields):
self.debug("Cremention Date: %s" % fields[idx]) LOG.debug("Cremention Date: %s" % fields[idx])
crem_date = self.parse_date(self.decode(fields[idx])) crem_date = self.parse_date(self.decode(fields[idx]))
idx += 1 idx += 1
elif field == '#rp' and idx < len(fields): elif field == '#rp' and idx < len(fields):
self.debug("Burial Place: %s" % fields[idx]) LOG.debug("Burial Place: %s" % fields[idx])
bur_place = self.get_or_create_place(self.decode(fields[idx])) bur_place = self.get_or_create_place(self.decode(fields[idx]))
idx += 1 idx += 1
elif field == '#rs' and idx < len(fields): elif field == '#rs' and idx < len(fields):
self.debug("Burial Source: %s" % fields[idx]) LOG.debug("Burial Source: %s" % fields[idx])
bur_source = self.get_or_create_source(self.decode(fields[idx])) bur_source = self.get_or_create_source(self.decode(fields[idx]))
idx += 1 idx += 1
elif field == '#apubl': elif field == '#apubl':
self.debug("This is a public record") LOG.debug("This is a public record")
elif field == '#apriv': elif field == '#apriv':
self.debug("This is a private record") LOG.debug("This is a private record")
person.set_privacy(True) person.set_privacy(True)
elif field == '#h': elif field == '#h':
self.debug("This is a restricted record") LOG.debug("This is a restricted record")
#TODO: Gramps does currently not feature this level #TODO: Gramps does currently not feature this level
person.set_privacy(True) person.set_privacy(True)
elif dateRe.match(field): elif dateRe.match(field):
if not birth_parsed: if not birth_parsed:
self.debug("Birth Date: %s" % field) LOG.debug("Birth Date: %s" % field)
birth_date = self.parse_date(self.decode(field)) birth_date = self.parse_date(self.decode(field))
birth_parsed = True birth_parsed = True
else: else:
self.debug("Death Date: %s" % field) LOG.debug("Death Date: %s" % field)
death_date = self.parse_date(self.decode(field)) death_date = self.parse_date(self.decode(field))
if field == "mj": if field == "mj":
death_cause = "Died joung" death_cause = "Died joung"
@@ -690,8 +689,8 @@ class GeneWebParser(object):
death_cause = "Disappeared" death_cause = "Disappeared"
#TODO: Set special death types more properly #TODO: Set special death types more properly
else: else:
print "parse_person(): Unknown field", \ LOG.warn(("parse_person(): Unknown field " +
"'%s' for person in line %d!" % (field, self.lineno) "'%s' for person in line %d!") % (field, self.lineno))
if public_name: if public_name:
name = person.get_primary_name() name = person.get_primary_name()

View File

@@ -38,7 +38,7 @@ import cPickle as pickle
import time import time
from bsddb import dbshelve, db from bsddb import dbshelve, db
import logging import logging
__LOG = logging.getLogger(".Db") LOG = logging.getLogger(".Db")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -158,7 +158,6 @@ class GrampsBSDDB(DbGrdb, UpdateCallback):
def __open_table(self, file_name, table_name, dbtype=db.DB_HASH): def __open_table(self, file_name, table_name, dbtype=db.DB_HASH):
dbmap = dbshelve.DBShelf(self.env) dbmap = dbshelve.DBShelf(self.env)
dbmap.db.set_pagesize(16384) dbmap.db.set_pagesize(16384)
print file_name
if self.readonly: if self.readonly:
dbmap.open(file_name, table_name, dbtype, db.DB_RDONLY) dbmap.open(file_name, table_name, dbtype, db.DB_RDONLY)
else: else:
@@ -739,9 +738,7 @@ class GrampsBSDDB(DbGrdb, UpdateCallback):
# Use the secondary index to locate all the reference_map entries # Use the secondary index to locate all the reference_map entries
# that include a reference to the object we are looking for. # that include a reference to the object we are looking for.
print "FIND BACKLINK"
referenced_cur = self.get_reference_map_referenced_cursor() referenced_cur = self.get_reference_map_referenced_cursor()
print "refcur", referenced_cur
try: try:
ret = referenced_cur.set(handle) ret = referenced_cur.set(handle)
@@ -1400,7 +1397,7 @@ class GrampsBSDDB(DbGrdb, UpdateCallback):
# under certain circumstances during a database reload, # under certain circumstances during a database reload,
# data_map can be none. If so, then don't report an error # data_map can be none. If so, then don't report an error
if data_map: if data_map:
__LOG.error("Failed to get from handle", exc_info=True) LOG.error("Failed to get from handle", exc_info=True)
if data: if data:
newobj = class_type() newobj = class_type()
newobj.unserialize(data) newobj.unserialize(data)
@@ -1508,7 +1505,6 @@ class GrampsBSDDB(DbGrdb, UpdateCallback):
self.txn = None self.txn = None
def undo(self, update_history=True): def undo(self, update_history=True):
print "Undoing it"
if self.UseTXN: if self.UseTXN:
self.txn = self.env.txn_begin() self.txn = self.env.txn_begin()
status = DbBase.undo(self, update_history) status = DbBase.undo(self, update_history)
@@ -1521,7 +1517,6 @@ class GrampsBSDDB(DbGrdb, UpdateCallback):
return status return status
def redo(self, update_history=True): def redo(self, update_history=True):
print "Redoing it"
if self.UseTXN: if self.UseTXN:
self.txn = self.env.txn_begin() self.txn = self.env.txn_begin()
status = DbBase.redo(self, update_history) status = DbBase.redo(self, update_history)
@@ -1568,30 +1563,10 @@ class GrampsBSDDB(DbGrdb, UpdateCallback):
self.gramps_upgrade_13() self.gramps_upgrade_13()
if version < 14: if version < 14:
self.gramps_upgrade_14() self.gramps_upgrade_14()
print "Upgrade time:", int(time.time()-t), "seconds" LOG.debug("Upgrade time: %s %s", int(time.time()-t), "seconds")
def gramps_upgrade_10(self): def gramps_upgrade_10(self):
print "Upgrading to DB version 10..." LOG.debug("Upgrading to DB version 10...")
# Remove event column metadata, since columns have changed.
# This will reset all columns to defaults in event view
## This action is removed: column data is no longer used, so no
## need to change it
#for name in (PERSON_COL_KEY, EVENT_COL_KEY):
# try:
# if self.UseTXN:
# # Start transaction if needed
# the_txn = self.env.txn_begin()
# else:
# the_txn = None
# self.metadata.delete(name, txn=the_txn)
# if self.UseTXN:
# the_txn.commit()
# else:
# self.metadata.sync()
# except KeyError:
# if self.UseTXN:
# the_txn.abort()
# This upgrade adds attribute lists to Event and EventRef objects # This upgrade adds attribute lists to Event and EventRef objects
length = self.get_number_of_events() + len(self.person_map) \ length = self.get_number_of_events() + len(self.person_map) \
@@ -1713,10 +1688,10 @@ class GrampsBSDDB(DbGrdb, UpdateCallback):
else: else:
self.metadata.sync() self.metadata.sync()
print "Done upgrading to DB version 10" LOG.debug("Done upgrading to DB version 10")
def gramps_upgrade_11(self): def gramps_upgrade_11(self):
print "Upgrading to DB version 11..." LOG.debug("Upgrading to DB version 11...")
# This upgrade modifies addresses and locations # This upgrade modifies addresses and locations
length = len(self.person_map) + len(self.place_map) \ length = len(self.person_map) + len(self.place_map) \
@@ -1822,10 +1797,10 @@ class GrampsBSDDB(DbGrdb, UpdateCallback):
else: else:
self.metadata.sync() self.metadata.sync()
print "Done upgrading to DB version 11" LOG.debug("Done upgrading to DB version 11")
def gramps_upgrade_12(self): def gramps_upgrade_12(self):
print "Upgrading to DB version 12..." LOG.debug("Upgrading to DB version 12...")
# Hook up surnames # Hook up surnames
table_flags = self.__open_flags() table_flags = self.__open_flags()
self.surnames = db.DB(self.env) self.surnames = db.DB(self.env)
@@ -1850,14 +1825,14 @@ class GrampsBSDDB(DbGrdb, UpdateCallback):
else: else:
self.metadata.sync() self.metadata.sync()
print "Done upgrading to DB version 12" LOG.debug("Done upgrading to DB version 12")
def gramps_upgrade_13(self): def gramps_upgrade_13(self):
""" """
First upgrade in 2.3/3.0 branch. First upgrade in 2.3/3.0 branch.
We assume that the data is at least from 2.2.x. We assume that the data is at least from 2.2.x.
""" """
print "Upgrading to DB version 13..." LOG.debug("Upgrading to DB version 13...")
# Hook up note id index # Hook up note id index
table_flags = self.__open_flags() table_flags = self.__open_flags()
self.nid_trans = db.DB(self.env) self.nid_trans = db.DB(self.env)
@@ -1977,7 +1952,7 @@ class GrampsBSDDB(DbGrdb, UpdateCallback):
table_flags) table_flags)
self.reference_map_referenced_map.close() self.reference_map_referenced_map.close()
print "Done upgrading to DB version 13" LOG.debug("Done upgrading to DB version 13")
def commit_13(self,data_tuple,data_key_name,data_map, note_handles=None): def commit_13(self,data_tuple,data_key_name,data_map, note_handles=None):
""" """
@@ -2314,13 +2289,13 @@ class GrampsBSDDB(DbGrdb, UpdateCallback):
urls, new_lds_list, new_source_list, note_list, urls, new_lds_list, new_source_list, note_list,
change, marker, priv, new_person_ref_list) change, marker, priv, new_person_ref_list)
else: else:
print name, obj LOG.warn("could not convert_notes_13 %s %s", name, obj)
# Return the required tuple # Return the required tuple
return (new_obj, note_handles) return (new_obj, note_handles)
def gramps_upgrade_14(self): def gramps_upgrade_14(self):
"""Upgrade database from version 13 to 14.""" """Upgrade database from version 13 to 14."""
print "Upgrading to DB version 14..." LOG.debug("Upgrading to DB version 14...")
# This upgrade modifies notes and dates # This upgrade modifies notes and dates
length = (len(self.note_map) + len(self.person_map) + length = (len(self.note_map) + len(self.person_map) +
len(self.event_map) + len(self.family_map) + len(self.event_map) + len(self.family_map) +
@@ -2695,22 +2670,22 @@ def importData(database, filename, callback=None, cl=0):
other_database.load(new_filename, callback) other_database.load(new_filename, callback)
except: except:
if cl: if cl:
print "Error: %s could not be opened. Exiting." % new_filename LOG.warn("%s could not be opened. Exiting." % new_filename)
else: else:
import traceback import traceback
print traceback.print_exc() traceback.print_exc()
ErrorDialog(_("%s could not be opened") % new_filename) ErrorDialog(_("%s could not be opened") % new_filename)
return return
if not other_database.version_supported(): if not other_database.version_supported():
if cl: if cl:
print "Error: %s could not be opened.\n%s Exiting." \ LOG.warn("Error: %s could not be opened.\n%s Exiting." \
% (filename, % (filename,
_("The database version is not supported " _("The database version is not supported "
"by this version of Gramps.\n"\ "by this version of Gramps.\n"\
"Please upgrade to the corresponding version " "Please upgrade to the corresponding version "
"or use XML for porting data between different " "or use XML for porting data between different "
"database versions.")) "database versions.")))
else: else:
ErrorDialog(_("%s could not be opened") % filename, ErrorDialog(_("%s could not be opened") % filename,
_("The Database version is not supported " _("The Database version is not supported "
@@ -2853,7 +2828,7 @@ def importData(database, filename, callback=None, cl=0):
msg = _("Your family tree groups name %s together" msg = _("Your family tree groups name %s together"
" with %s, did not change this grouping to %s") % ( " with %s, did not change this grouping to %s") % (
key, present, value) key, present, value)
print msg LOG.warn(msg)
else: else:
database.set_name_group_mapping(key, value) database.set_name_group_mapping(key, value)

View File

@@ -137,7 +137,6 @@ def _read_recs(table, bname):
recs.append(tups) recs.append(tups)
log.info("# length %s.recs[] = %d" % (table['name1'], len(recs))) log.info("# length %s.recs[] = %d" % (table['name1'], len(recs)))
print "# length %s.recs[] = %d" % (table['name1'], len(recs))
return recs return recs

View File

@@ -39,7 +39,7 @@ from gen.ggettext import ngettext
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import logging import logging
log = logging.getLogger(".ImportVCard") LOG = logging.getLogger(".ImportVCard")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -136,7 +136,7 @@ class VCardParser(object):
elif fields[0] == "URL": elif fields[0] == "URL":
self.add_url(fields, line_parts.group(2)) self.add_url(fields, line_parts.group(2))
else: else:
print "Token >%s< unknown. line skipped: %s" % (fields[0],line) LOG.warn("Token >%s< unknown. line skipped: %s" % (fields[0],line))
except Errors.GedcomError, err: except Errors.GedcomError, err:
self.errmsg(str(err)) self.errmsg(str(err))

View File

@@ -31,6 +31,8 @@ import sys
from xml.parsers.expat import ExpatError, ParserCreate from xml.parsers.expat import ExpatError, ParserCreate
from gen.ggettext import gettext as _ from gen.ggettext import gettext as _
import re import re
import logging
LOG = logging.getLogger(".ImportXML")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -117,8 +119,8 @@ def importData(database, filename, callback=None, cl=0):
info = parser.parse(xml_file, line_cnt, person_cnt) info = parser.parse(xml_file, line_cnt, person_cnt)
except IOError, msg: except IOError, msg:
if cl: if cl:
print "Error reading %s" % filename LOG.warn("Error reading %s" % filename)
print msg LOG.warn(msg)
import traceback import traceback
traceback.print_exc() traceback.print_exc()
sys.exit(1) sys.exit(1)
@@ -129,8 +131,8 @@ def importData(database, filename, callback=None, cl=0):
return return
except ExpatError, msg: except ExpatError, msg:
if cl: if cl:
print "Error reading %s" % filename LOG.warn("Error reading %s" % filename)
print "The file is probably either corrupt or not a valid Gramps database." LOG.warn("The file is probably either corrupt or not a valid Gramps database.")
sys.exit(1) sys.exit(1)
else: else:
ErrorDialog(_("Error reading %s") % filename, ErrorDialog(_("Error reading %s") % filename,
@@ -2456,14 +2458,14 @@ def open_file(filename, cli):
xml_file = open(filename, "r") xml_file = open(filename, "r")
except IOError, msg: except IOError, msg:
if cli: if cli:
print "Error: %s could not be opened Exiting." % filename LOG.warn("Error: %s could not be opened Exiting." % filename)
print msg LOG.warn(msg)
else: else:
ErrorDialog(_("%s could not be opened") % filename, str(msg)) ErrorDialog(_("%s could not be opened") % filename, str(msg))
xml_file = None xml_file = None
except: except:
if cli: if cli:
print "Error: %s could not be opened. Exiting." % filename LOG.warn("Error: %s could not be opened. Exiting." % filename)
else: else:
ErrorDialog(_("%s could not be opened") % filename) ErrorDialog(_("%s could not be opened") % filename)
xml_file = None xml_file = None
@@ -2483,7 +2485,7 @@ def version_is_valid(filename, cli):
"version of Gramps and try again." "version of Gramps and try again."
) % (parser.get_gramps_version(), const.VERSION) ) % (parser.get_gramps_version(), const.VERSION)
if cli: if cli:
print msg LOG.warn(msg)
return False return False
else: else:
ErrorDialog(msg) ErrorDialog(msg)
@@ -2501,7 +2503,7 @@ def version_is_valid(filename, cli):
'xmlversion': parser.get_xmlns_version(), 'xmlversion': parser.get_xmlns_version(),
} }
if cli: if cli:
print msg LOG.warn(msg)
return False return False
else: else:
ErrorDialog(_('The file will not be imported'), msg) ErrorDialog(_('The file will not be imported'), msg)
@@ -2521,7 +2523,7 @@ def version_is_valid(filename, cli):
'xmlversion': parser.get_xmlns_version(), 'xmlversion': parser.get_xmlns_version(),
} }
if cli: if cli:
print msg LOG.warn(msg)
return True return True
else: else:
WarningDialog(_('Old xml file'), msg) WarningDialog(_('Old xml file'), msg)