diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 9b22d1297..d92f8a946 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -8,6 +8,10 @@ * src/plugins/Check.py (encoding) dont encode a utf-8 string as again, (cleanup_missing_photos) Use Utils.find_file to fix encoding problems + * src/Utils.py (find_folder): new method + * src/gramps_main.py: Use Utils.find_file and Utils.find_folder to enable + using unicode names for gramps databases + 2005-11-17 Martin Hawlisch * src/gramps.glade, src/TipOfDay.py: Add window title diff --git a/gramps2/src/Utils.py b/gramps2/src/Utils.py index 544fa62a8..1517cbda7 100644 --- a/gramps2/src/Utils.py +++ b/gramps2/src/Utils.py @@ -286,6 +286,29 @@ def find_file( filename): # not found return '' +def find_folder( filename): + # try the filename we got + try: + fname = filename + if os.path.isdir( filename): + return( filename) + except: + pass + + # Build list of elternate encodings + encodings = [sys.getfilesystemencoding(), locale.getpreferredencoding(), 'UTF-8', 'ISO-8859-1'] + encodings = list(sets.Set(encodings)) + for enc in encodings: + try: + fname = filename.encode(enc) + if os.path.isdir( fname): + return fname + except: + pass + + # not found + return '' + #------------------------------------------------------------------------- # # diff --git a/gramps2/src/gramps_main.py b/gramps2/src/gramps_main.py index 989414e3b..53ae11225 100755 --- a/gramps2/src/gramps_main.py +++ b/gramps2/src/gramps_main.py @@ -522,7 +522,7 @@ class Gramps(GrampsDBCallback.GrampsDBCallback): self.open_recent.set_submenu(recent_menu) def recent_callback(self,obj,filename,filetype): - if os.path.exists(filename): + if Utils.find_file(filename): DbPrompter.open_native(self,filename,filetype) else: ErrorDialog(_('File does not exist'), @@ -1289,12 +1289,12 @@ class Gramps(GrampsDBCallback.GrampsDBCallback): mode = "w" filename = os.path.normpath(os.path.abspath(filename)) - if os.path.isdir(filename): + if Utils.find_folder(filename): ErrorDialog(_('Cannot open database'), _('The selected file is a directory, not ' 'a file.\nA GRAMPS database must be a file.')) return 0 - elif os.path.exists(filename): + elif Utils.find_file(filename): if not os.access(filename,os.R_OK): ErrorDialog(_('Cannot open database'), _('You do not have read access to the selected '