0000995: Don't have write access on import/open in paths containing non-ASCII characters.

svn: r8367
This commit is contained in:
Brian Matherly 2007-04-09 04:24:06 +00:00
parent 8ed86bc145
commit 044e38b129
12 changed files with 47 additions and 29 deletions

View File

@ -1,3 +1,18 @@
2007-04-08 Brian Matherly <brian@gramps-project.org>
* src\Exporter.py
* src\ReportBase\_FileEntry.py
* src\Editors\_EditMedia.py
* src\plugins\WriteCD.py
* src\plugins\WritePkg.py
* src\plugins\Check.py
* src\plugins\EventCmp.py
* src\AddMedia.py
* src\Utils.py
* src\ArgHandler.py
* src\DbLoader.py
0000995: Don't have write access on import/open in paths containing
non-ASCII characters.
2007-04-08 Brian Matherly <brian@gramps-project.org> 2007-04-08 Brian Matherly <brian@gramps-project.org>
* src/plugins/NarrativeWeb.py: 0001006: Narrative Web: Media objects missing * src/plugins/NarrativeWeb.py: 0001006: Narrative Web: Media objects missing
title (description), mime_type, or path, are displayed poorly. title (description), mime_type, or path, are displayed poorly.

View File

@ -131,8 +131,7 @@ class AddMediaObject(ManagedWindow.ManagedWindow):
mobj.set_handle(Utils.create_id()) mobj.set_handle(Utils.create_id())
mobj.set_mime_type(None) mobj.set_mime_type(None)
else: else:
filename = unicode(self.file_text.get_filename(), filename = Utils.get_unicode_path(self.file_text.get_filename())
sys.getfilesystemencoding())
full_file = filename full_file = filename
if self.relpath.get_active(): if self.relpath.get_active():
@ -176,7 +175,7 @@ class AddMediaObject(ManagedWindow.ManagedWindow):
fn = self.file_text.get_filename() fn = self.file_text.get_filename()
if not fn: if not fn:
return return
filename = unicode(fn, sys.getfilesystemencoding()) filename = Utils.get_unicode_path(fn)
basename = os.path.basename(filename) basename = os.path.basename(filename)
(root,ext) = os.path.splitext(basename) (root,ext) = os.path.splitext(basename)
old_title = unicode(self.description.get_text()) old_title = unicode(self.description.get_text())

View File

@ -743,8 +743,7 @@ class NewNativeDbPrompter:
while (True): while (True):
response = choose.run() response = choose.run()
if response == gtk.RESPONSE_OK: if response == gtk.RESPONSE_OK:
filename = unicode(choose.get_filename(), filename = Utils.get_unicode_path(choose.get_filename())
sys.getfilesystemencoding())
if filename == None: if filename == None:
continue continue
if os.path.splitext(filename)[1] != ".grdb": if os.path.splitext(filename)[1] != ".grdb":

View File

@ -99,8 +99,7 @@ class DbLoader:
choose.set_current_folder(get_default_dir()) choose.set_current_folder(get_default_dir())
response = choose.run() response = choose.run()
if response == gtk.RESPONSE_OK: if response == gtk.RESPONSE_OK:
filename = unicode(choose.get_filename(), filename = Utils.get_unicode_path(choose.get_filename())
sys.getfilesystemencoding())
if self.check_errors(filename): if self.check_errors(filename):
return ('','') return ('','')
@ -156,8 +155,7 @@ class DbLoader:
while (True): while (True):
response = choose.run() response = choose.run()
if response == gtk.RESPONSE_OK: if response == gtk.RESPONSE_OK:
filename = unicode(choose.get_filename(), filename = Utils.get_unicode_path(choose.get_filename())
sys.getfilesystemencoding())
if self.check_errors(filename): if self.check_errors(filename):
return ('','') return ('','')
@ -219,8 +217,7 @@ class DbLoader:
response = choose.run() response = choose.run()
if response == gtk.RESPONSE_OK: if response == gtk.RESPONSE_OK:
filename = unicode(choose.get_filename(), filename = Utils.get_unicode_path(choose.get_filename())
sys.getfilesystemencoding())
if self.check_errors(filename): if self.check_errors(filename):
return ('','') return ('','')
@ -311,8 +308,7 @@ class DbLoader:
choose.set_current_folder(default_dir) choose.set_current_folder(default_dir)
response = choose.run() response = choose.run()
if response == gtk.RESPONSE_OK: if response == gtk.RESPONSE_OK:
filename = unicode(choose.get_filename(), filename = Utils.get_unicode_path(choose.get_filename())
sys.getfilesystemencoding())
if self.check_errors(filename): if self.check_errors(filename):
return False return False

View File

@ -46,6 +46,7 @@ import Config
import RelLib import RelLib
import Mime import Mime
import ImgManip import ImgManip
import Utils
from _EditPrimary import EditPrimary from _EditPrimary import EditPrimary
from GrampsWidgets import * from GrampsWidgets import *
@ -217,8 +218,7 @@ class EditMedia(EditPrimary):
status = f.run() status = f.run()
if status == gtk.RESPONSE_OK: if status == gtk.RESPONSE_OK:
self.file_path.set_text(unicode(f.get_filename(), self.file_path.set_text(Utils.get_unicode_path(f.get_filename()))
sys.getfilesystemencoding()))
f.destroy() f.destroy()
def setup_filepath(self): def setup_filepath(self):

View File

@ -152,8 +152,7 @@ class Exporter:
the selected options (format, filename) and present the summary the selected options (format, filename) and present the summary
of the proposed action. of the proposed action.
""" """
filename = unicode(self.chooser.get_filename(), filename = Utils.get_unicode_path(self.chooser.get_filename())
sys.getfilesystemencoding())
name = os.path.split(filename)[1] name = os.path.split(filename)[1]
folder = os.path.split(filename)[0] folder = os.path.split(filename)[0]
ix = self.get_selected_format_index() ix = self.get_selected_format_index()
@ -174,8 +173,7 @@ class Exporter:
Perform the actual Save As/Export operation. Perform the actual Save As/Export operation.
Depending on the success status, set the text for the final page. Depending on the success status, set the text for the final page.
""" """
filename = unicode(self.chooser.get_filename(), filename = Utils.get_unicode_path(self.chooser.get_filename())
sys.getfilesystemencoding())
Config.set(Config.RECENT_EXPORT_DIR,os.path.split(filename)[0]) Config.set(Config.RECENT_EXPORT_DIR,os.path.split(filename)[0])
ix = self.get_selected_format_index() ix = self.get_selected_format_index()
self.pre_save() self.pre_save()

View File

@ -23,6 +23,7 @@
import os import os
import sys import sys
import gtk import gtk
import Utils
class FileEntry(gtk.HBox): class FileEntry(gtk.HBox):
def __init__(self,defname,title): def __init__(self,defname,title):
@ -68,8 +69,7 @@ class FileEntry(gtk.HBox):
f.present() f.present()
status = f.run() status = f.run()
if status == gtk.RESPONSE_OK: if status == gtk.RESPONSE_OK:
self.set_filename(unicode(f.get_filename(), self.set_filename(Utils.get_unicode_path(f.get_filename()))
sys.getfilesystemencoding()))
f.destroy() f.destroy()
def set_filename(self,path): def set_filename(self,path):

View File

@ -335,6 +335,20 @@ def find_folder( filename):
# not found # not found
return '' return ''
def get_unicode_path(path):
"""
Return the Unicode version of a path string.
@type path: str
@param path: The path to be converted to Unicode
@rtype: unicode
@return: The Unicode version of path.
"""
if os.sys.platform == "win32":
return unicode(path)
else:
return unicode(path,sys.getfilesystemencoding())
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# #

View File

@ -502,8 +502,7 @@ class CheckIntegrity:
self.bad_photo.append(ObjectId) self.bad_photo.append(ObjectId)
def fs_ok_clicked(obj): def fs_ok_clicked(obj):
name = unicode(fs_top.get_filename(), name = Utils.get_unicode_path(fs_top.get_filename())
sys.getfilesystemencoding())
if os.path.isfile(name): if os.path.isfile(name):
obj = self.db.get_object_from_handle(ObjectId) obj = self.db.get_object_from_handle(ObjectId)
obj.set_path(name) obj.set_path(name)

View File

@ -417,8 +417,7 @@ class DisplayChart(ManagedWindow.ManagedWindow):
f.hide() f.hide()
if status == gtk.RESPONSE_OK: if status == gtk.RESPONSE_OK:
name = unicode(f.get_filename(), name = Utils.get_unicode_path(f.get_filename())
sys.getfilesystemencoding())
pstyle = BaseDoc.PaperStyle("junk",10,10) pstyle = BaseDoc.PaperStyle("junk",10,10)
doc = ODSDoc.ODSDoc(pstyle,BaseDoc.PAPER_PORTRAIT) doc = ODSDoc.ODSDoc(pstyle,BaseDoc.PAPER_PORTRAIT)
doc.creator(self.db.get_researcher().get_name()) doc.creator(self.db.get_researcher().get_name())

View File

@ -71,6 +71,7 @@ import Mime
import const import const
import QuestionDialog import QuestionDialog
import ImgManip import ImgManip
import Utils
from PluginUtils import register_export from PluginUtils import register_export
_title_string = _("Export to CD") _title_string = _("Export to CD")
@ -235,8 +236,7 @@ class PackageWriter:
pass pass
def fs_ok_clicked(obj): def fs_ok_clicked(obj):
newfile = unicode(fs_top.get_filename(), newfile = Utils.get_unicode_path(fs_top.get_filename())
sys.getfilesystemencoding())
if os.path.isfile(newfile): if os.path.isfile(newfile):
self.copy_file(newfile,'burn:///%s/%s' % (base,obase)) self.copy_file(newfile,'burn:///%s/%s' % (base,obase))
ntype = Mime.get_type(newfile) ntype = Mime.get_type(newfile)

View File

@ -140,8 +140,7 @@ class PackageWriter:
pass pass
def fs_ok_clicked(obj): def fs_ok_clicked(obj):
name = unicode(fs_top.get_filename(), name = Utils.get_unicode_path(fs_top.get_filename())
sys.getfilesystemencoding())
if os.path.isfile(name): if os.path.isfile(name):
archive.add(name) archive.add(name)