Fix bugs in drag-n-drop filenames on dbmanager; allow any URL
svn: r18558
This commit is contained in:
parent
dd4b01cec0
commit
4ecd146f94
@ -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()
|
||||
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user