Removal of command line parameter in XML import

svn: r16762
This commit is contained in:
Michiel Nauta 2011-03-05 12:41:27 +00:00
parent 959bea3507
commit fadd7c19de

View File

@ -86,7 +86,7 @@ EVENT_PERSON_STR = _("%(event_name)s of %(person)s")
# Must takes care of renaming media files according to their new IDs. # Must takes care of renaming media files according to their new IDs.
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def importData(database, filename, callback=None, cl=0): def importData(database, filename, callback=None):
## return Utils.profile(importDataPro, database, filename, callback, cl) ## return Utils.profile(importDataPro, database, filename, callback, cl)
##def importDataPro(database, filename, callback=None, cl=0): ##def importDataPro(database, filename, callback=None, cl=0):
@ -100,14 +100,11 @@ def importData(database, filename, callback=None, cl=0):
database.pmap = {} database.pmap = {}
database.fmap = {} database.fmap = {}
xml_file = open_file(filename, cl) xml_file = open_file(filename)
versionparser = VersionParser(xml_file) versionparser = VersionParser(xml_file)
if xml_file is None or \ if xml_file is None or \
version_is_valid(versionparser, cl) is False: version_is_valid(versionparser) is False:
if cl:
sys.exit(1)
else:
return return
version_string = versionparser.get_xmlns_version() version_string = versionparser.get_xmlns_version()
@ -127,23 +124,11 @@ def importData(database, filename, callback=None, cl=0):
try: try:
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:
LOG.warn("Error reading %s" % filename)
LOG.warn(msg)
import traceback
traceback.print_exc()
sys.exit(1)
else:
ErrorDialog(_("Error reading %s") % filename, str(msg)) ErrorDialog(_("Error reading %s") % filename, str(msg))
import traceback import traceback
traceback.print_exc() traceback.print_exc()
return return
except ExpatError, msg: except ExpatError, msg:
if cl:
LOG.warn("Error reading %s" % filename)
LOG.warn("The file is probably either corrupt or not a valid Gramps database.")
sys.exit(1)
else:
ErrorDialog(_("Error reading %s") % filename, ErrorDialog(_("Error reading %s") % filename,
_("The file is probably either corrupt or not a valid Gramps database.")) _("The file is probably either corrupt or not a valid Gramps database."))
return return
@ -2620,7 +2605,7 @@ class VersionParser(object):
" Get the version of Gramps that created the file " " Get the version of Gramps that created the file "
return self.__gramps_version return self.__gramps_version
def open_file(filename, cli): def open_file(filename):
""" """
Open the xml file. Open the xml file.
Return a valid file handle if the file opened sucessfully. Return a valid file handle if the file opened sucessfully.
@ -2645,22 +2630,15 @@ def open_file(filename, cli):
else: else:
xml_file = open(filename, "r") xml_file = open(filename, "r")
except IOError, msg: except IOError, msg:
if cli:
LOG.warn("Error: %s could not be opened Exiting." % filename)
LOG.warn(msg)
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:
LOG.warn("Error: %s could not be opened. Exiting." % filename)
else:
ErrorDialog(_("%s could not be opened") % filename) ErrorDialog(_("%s could not be opened") % filename)
xml_file = None xml_file = None
return xml_file return xml_file
def version_is_valid(versionparser, cli): def version_is_valid(versionparser):
""" """
Validate the xml version. Validate the xml version.
:param versionparser: A VersionParser object to work with :param versionparser: A VersionParser object to work with
@ -2672,10 +2650,6 @@ def version_is_valid(versionparser, cli):
"The file will not be imported. Please upgrade to the latest " "The file will not be imported. Please upgrade to the latest "
"version of Gramps and try again." ) % { "version of Gramps and try again." ) % {
'newer' : versionparser.get_gramps_version(), 'older' : const.VERSION } 'newer' : versionparser.get_gramps_version(), 'older' : const.VERSION }
if cli:
LOG.warn(msg)
return False
else:
ErrorDialog(msg) ErrorDialog(msg)
return False return False
if versionparser.get_xmlns_version() < '1.0.0': if versionparser.get_xmlns_version() < '1.0.0':
@ -2690,10 +2664,6 @@ def version_is_valid(versionparser, cli):
'newgramps': const.VERSION, 'newgramps': const.VERSION,
'xmlversion': versionparser.get_xmlns_version(), 'xmlversion': versionparser.get_xmlns_version(),
} }
if cli:
LOG.warn(msg)
return False
else:
ErrorDialog(_('The file will not be imported'), msg) ErrorDialog(_('The file will not be imported'), msg)
return False return False
elif versionparser.get_xmlns_version() < '1.1.0': elif versionparser.get_xmlns_version() < '1.1.0':
@ -2710,10 +2680,6 @@ def version_is_valid(versionparser, cli):
'newgramps': const.VERSION, 'newgramps': const.VERSION,
'xmlversion': versionparser.get_xmlns_version(), 'xmlversion': versionparser.get_xmlns_version(),
} }
if cli:
LOG.warn(msg)
return True
else:
WarningDialog(_('Old xml file'), msg) WarningDialog(_('Old xml file'), msg)
return True return True
return True return True