From b7b80b3d0a79d89b56ac74a684720045120cddba Mon Sep 17 00:00:00 2001 From: Brian Matherly Date: Mon, 9 Apr 2007 04:24:06 +0000 Subject: [PATCH] 0000995: Don't have write access on import/open in paths containing non-ASCII characters. svn: r8367 --- gramps2/ChangeLog | 15 +++++++++++++++ gramps2/src/AddMedia.py | 5 ++--- gramps2/src/ArgHandler.py | 3 +-- gramps2/src/DbLoader.py | 12 ++++-------- gramps2/src/Editors/_EditMedia.py | 4 ++-- gramps2/src/Exporter.py | 6 ++---- gramps2/src/ReportBase/_FileEntry.py | 4 ++-- gramps2/src/Utils.py | 14 ++++++++++++++ gramps2/src/plugins/Check.py | 3 +-- gramps2/src/plugins/EventCmp.py | 3 +-- gramps2/src/plugins/WriteCD.py | 4 ++-- gramps2/src/plugins/WritePkg.py | 3 +-- 12 files changed, 47 insertions(+), 29 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 00f2de7c6..43fa267b5 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,18 @@ +2007-04-08 Brian Matherly + * 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 * src/plugins/NarrativeWeb.py: 0001006: Narrative Web: Media objects missing title (description), mime_type, or path, are displayed poorly. diff --git a/gramps2/src/AddMedia.py b/gramps2/src/AddMedia.py index 3970d5db8..2e930dab5 100644 --- a/gramps2/src/AddMedia.py +++ b/gramps2/src/AddMedia.py @@ -131,8 +131,7 @@ class AddMediaObject(ManagedWindow.ManagedWindow): mobj.set_handle(Utils.create_id()) mobj.set_mime_type(None) else: - filename = unicode(self.file_text.get_filename(), - sys.getfilesystemencoding()) + filename = Utils.get_unicode_path(self.file_text.get_filename()) full_file = filename if self.relpath.get_active(): @@ -176,7 +175,7 @@ class AddMediaObject(ManagedWindow.ManagedWindow): fn = self.file_text.get_filename() if not fn: return - filename = unicode(fn, sys.getfilesystemencoding()) + filename = Utils.get_unicode_path(fn) basename = os.path.basename(filename) (root,ext) = os.path.splitext(basename) old_title = unicode(self.description.get_text()) diff --git a/gramps2/src/ArgHandler.py b/gramps2/src/ArgHandler.py index 130ab0898..2e6eea334 100644 --- a/gramps2/src/ArgHandler.py +++ b/gramps2/src/ArgHandler.py @@ -743,8 +743,7 @@ class NewNativeDbPrompter: while (True): response = choose.run() if response == gtk.RESPONSE_OK: - filename = unicode(choose.get_filename(), - sys.getfilesystemencoding()) + filename = Utils.get_unicode_path(choose.get_filename()) if filename == None: continue if os.path.splitext(filename)[1] != ".grdb": diff --git a/gramps2/src/DbLoader.py b/gramps2/src/DbLoader.py index c32089ddf..32663021e 100644 --- a/gramps2/src/DbLoader.py +++ b/gramps2/src/DbLoader.py @@ -99,8 +99,7 @@ class DbLoader: choose.set_current_folder(get_default_dir()) response = choose.run() if response == gtk.RESPONSE_OK: - filename = unicode(choose.get_filename(), - sys.getfilesystemencoding()) + filename = Utils.get_unicode_path(choose.get_filename()) if self.check_errors(filename): return ('','') @@ -156,8 +155,7 @@ class DbLoader: while (True): response = choose.run() if response == gtk.RESPONSE_OK: - filename = unicode(choose.get_filename(), - sys.getfilesystemencoding()) + filename = Utils.get_unicode_path(choose.get_filename()) if self.check_errors(filename): return ('','') @@ -219,8 +217,7 @@ class DbLoader: response = choose.run() if response == gtk.RESPONSE_OK: - filename = unicode(choose.get_filename(), - sys.getfilesystemencoding()) + filename = Utils.get_unicode_path(choose.get_filename()) if self.check_errors(filename): return ('','') @@ -311,8 +308,7 @@ class DbLoader: choose.set_current_folder(default_dir) response = choose.run() if response == gtk.RESPONSE_OK: - filename = unicode(choose.get_filename(), - sys.getfilesystemencoding()) + filename = Utils.get_unicode_path(choose.get_filename()) if self.check_errors(filename): return False diff --git a/gramps2/src/Editors/_EditMedia.py b/gramps2/src/Editors/_EditMedia.py index ae0dcecaa..43e476ec0 100644 --- a/gramps2/src/Editors/_EditMedia.py +++ b/gramps2/src/Editors/_EditMedia.py @@ -46,6 +46,7 @@ import Config import RelLib import Mime import ImgManip +import Utils from _EditPrimary import EditPrimary from GrampsWidgets import * @@ -217,8 +218,7 @@ class EditMedia(EditPrimary): status = f.run() if status == gtk.RESPONSE_OK: - self.file_path.set_text(unicode(f.get_filename(), - sys.getfilesystemencoding())) + self.file_path.set_text(Utils.get_unicode_path(f.get_filename())) f.destroy() def setup_filepath(self): diff --git a/gramps2/src/Exporter.py b/gramps2/src/Exporter.py index a3f9b9cf6..886712428 100644 --- a/gramps2/src/Exporter.py +++ b/gramps2/src/Exporter.py @@ -152,8 +152,7 @@ class Exporter: the selected options (format, filename) and present the summary of the proposed action. """ - filename = unicode(self.chooser.get_filename(), - sys.getfilesystemencoding()) + filename = Utils.get_unicode_path(self.chooser.get_filename()) name = os.path.split(filename)[1] folder = os.path.split(filename)[0] ix = self.get_selected_format_index() @@ -174,8 +173,7 @@ class Exporter: Perform the actual Save As/Export operation. Depending on the success status, set the text for the final page. """ - filename = unicode(self.chooser.get_filename(), - sys.getfilesystemencoding()) + filename = Utils.get_unicode_path(self.chooser.get_filename()) Config.set(Config.RECENT_EXPORT_DIR,os.path.split(filename)[0]) ix = self.get_selected_format_index() self.pre_save() diff --git a/gramps2/src/ReportBase/_FileEntry.py b/gramps2/src/ReportBase/_FileEntry.py index 89df9e9d6..274c69a7e 100644 --- a/gramps2/src/ReportBase/_FileEntry.py +++ b/gramps2/src/ReportBase/_FileEntry.py @@ -23,6 +23,7 @@ import os import sys import gtk +import Utils class FileEntry(gtk.HBox): def __init__(self,defname,title): @@ -68,8 +69,7 @@ class FileEntry(gtk.HBox): f.present() status = f.run() if status == gtk.RESPONSE_OK: - self.set_filename(unicode(f.get_filename(), - sys.getfilesystemencoding())) + self.set_filename(Utils.get_unicode_path(f.get_filename())) f.destroy() def set_filename(self,path): diff --git a/gramps2/src/Utils.py b/gramps2/src/Utils.py index 118ababe8..34b260530 100644 --- a/gramps2/src/Utils.py +++ b/gramps2/src/Utils.py @@ -335,6 +335,20 @@ def find_folder( filename): # not found 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()) + #------------------------------------------------------------------------- # # diff --git a/gramps2/src/plugins/Check.py b/gramps2/src/plugins/Check.py index 6ca0e9736..f2f9631d0 100644 --- a/gramps2/src/plugins/Check.py +++ b/gramps2/src/plugins/Check.py @@ -502,8 +502,7 @@ class CheckIntegrity: self.bad_photo.append(ObjectId) def fs_ok_clicked(obj): - name = unicode(fs_top.get_filename(), - sys.getfilesystemencoding()) + name = Utils.get_unicode_path(fs_top.get_filename()) if os.path.isfile(name): obj = self.db.get_object_from_handle(ObjectId) obj.set_path(name) diff --git a/gramps2/src/plugins/EventCmp.py b/gramps2/src/plugins/EventCmp.py index 882bd2c5b..847864cd1 100644 --- a/gramps2/src/plugins/EventCmp.py +++ b/gramps2/src/plugins/EventCmp.py @@ -417,8 +417,7 @@ class DisplayChart(ManagedWindow.ManagedWindow): f.hide() if status == gtk.RESPONSE_OK: - name = unicode(f.get_filename(), - sys.getfilesystemencoding()) + name = Utils.get_unicode_path(f.get_filename()) pstyle = BaseDoc.PaperStyle("junk",10,10) doc = ODSDoc.ODSDoc(pstyle,BaseDoc.PAPER_PORTRAIT) doc.creator(self.db.get_researcher().get_name()) diff --git a/gramps2/src/plugins/WriteCD.py b/gramps2/src/plugins/WriteCD.py index e932f42ba..9c979f358 100644 --- a/gramps2/src/plugins/WriteCD.py +++ b/gramps2/src/plugins/WriteCD.py @@ -71,6 +71,7 @@ import Mime import const import QuestionDialog import ImgManip +import Utils from PluginUtils import register_export _title_string = _("Export to CD") @@ -235,8 +236,7 @@ class PackageWriter: pass def fs_ok_clicked(obj): - newfile = unicode(fs_top.get_filename(), - sys.getfilesystemencoding()) + newfile = Utils.get_unicode_path(fs_top.get_filename()) if os.path.isfile(newfile): self.copy_file(newfile,'burn:///%s/%s' % (base,obase)) ntype = Mime.get_type(newfile) diff --git a/gramps2/src/plugins/WritePkg.py b/gramps2/src/plugins/WritePkg.py index 7233e1c10..102549b4d 100644 --- a/gramps2/src/plugins/WritePkg.py +++ b/gramps2/src/plugins/WritePkg.py @@ -140,8 +140,7 @@ class PackageWriter: pass def fs_ok_clicked(obj): - name = unicode(fs_top.get_filename(), - sys.getfilesystemencoding()) + name = Utils.get_unicode_path(fs_top.get_filename()) if os.path.isfile(name): archive.add(name)