From 9442a5afe826a687eb9e61a33826527e45a3641d Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Wed, 3 Jul 2013 12:54:19 +0000 Subject: [PATCH] 6081: Crash after double-click on .gpkg file svn: r22643 --- gramps/cli/clidbman.py | 46 ++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/gramps/cli/clidbman.py b/gramps/cli/clidbman.py index c1855a29a..89e6fd5e0 100644 --- a/gramps/cli/clidbman.py +++ b/gramps/cli/clidbman.py @@ -336,28 +336,30 @@ class CLIDbManager(object): or (None, None) if no import was performed. """ pmgr = BasePluginManager.get_instance() - # Allow URL names here; make temp file if necessary - url = urlparse(filename) - if url.scheme != "": - if url.scheme == "file": - filename = url2pathname(filename[7:]) - else: - url_fp = urlopen(filename) # open URL - # make a temp local file: - ext = os.path.splitext(url.path)[1] - fd, filename = tempfile.mkstemp(suffix=ext) - temp_fp = os.fdopen(fd, "w") - # read from URL: - data = url_fp.read() - # write locally: - temp_fp.write(data) - url_fp.close() - from gen.db.dbconst import BDBVERSFN - versionpath = os.path.join(name, BDBVERSFN) - _LOG.debug("Write bsddb version %s" % str(dbase.version())) - with open(versionpath, "w") as version_file: - version_file.write(str(dbase.version())) - temp_fp.close() + # check to see if it isn't a filename directly: + if not os.path.isfile(filename): + # Allow URL names here; make temp file if necessary + url = urlparse(filename) + if url.scheme != "": + if url.scheme == "file": + filename = url2pathname(filename[7:]) + else: + url_fp = urlopen(filename) # open URL + # make a temp local file: + ext = os.path.splitext(url.path)[1] + fd, filename = tempfile.mkstemp(suffix=ext) + temp_fp = os.fdopen(fd, "w") + # read from URL: + data = url_fp.read() + # write locally: + temp_fp.write(data) + url_fp.close() + from gen.db.dbconst import BDBVERSFN + versionpath = os.path.join(name, BDBVERSFN) + _LOG.debug("Write bsddb version %s" % str(dbase.version())) + with open(versionpath, "w") as version_file: + version_file.write(str(dbase.version())) + temp_fp.close() (name, ext) = os.path.splitext(os.path.basename(filename)) format = ext[1:].lower()