From 4ecd146f94dc372b66c766ba1af2d80b9149a901 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Fri, 9 Dec 2011 14:25:39 +0000 Subject: [PATCH] Fix bugs in drag-n-drop filenames on dbmanager; allow any URL svn: r18558 --- src/cli/clidbman.py | 21 +++++++++++++++++++++ src/gui/dbman.py | 15 ++++++++------- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/cli/clidbman.py b/src/cli/clidbman.py index 93eb5385d..c215e07c5 100644 --- a/src/cli/clidbman.py +++ b/src/cli/clidbman.py @@ -35,6 +35,9 @@ creating, and deleting of databases. import os import sys import time +import urllib2 +import urlparse +import tempfile from gen.ggettext import gettext as _ #------------------------------------------------------------------------- # @@ -286,6 +289,24 @@ 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.urlparse(filename) + if url.scheme != "": + if url.scheme == "file": + filename = urllib2.url2pathname(filename[7:]) + else: + url_fp = urllib2.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() + temp_fp.close() + (name, ext) = os.path.splitext(os.path.basename(filename)) format = ext[1:].lower() diff --git a/src/gui/dbman.py b/src/gui/dbman.py index 9a3d5beca..611e3e80b 100644 --- a/src/gui/dbman.py +++ b/src/gui/dbman.py @@ -36,6 +36,7 @@ import os import time import copy import subprocess +import urlparse from gen.ggettext import gettext as _ #------------------------------------------------------------------------- # @@ -736,13 +737,13 @@ class DbManager(CLIDbManager): fname = None type = None title = None - # we are only interested in this if it is a file:// URL. - if drag_value and drag_value[0:7] == "file://": - - drag_value = drag_value.strip() - - fname, title = self.import_new_db(drag_value[7:], None) - + # Allow any type of URL ("file://", "http://", etc): + if drag_value and urlparse.urlparse(drag_value).scheme != "": + fname, title = [], [] + for treename in [v.strip() for v in drag_value.split("\n") if v.strip() != '']: + f, t = self.import_new_db(treename, None) + fname.append(f) + title.append(t) return fname, title def drag_motion(wid, context, xpos, ypos, time_stamp):