* 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


svn: r5406
This commit is contained in:
Martin Hawlisch 2005-11-18 15:19:38 +00:00
parent 86fa385a9b
commit fd10da84a2
3 changed files with 30 additions and 3 deletions

View File

@ -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 <Martin.Hawlisch@gmx.de>
* src/gramps.glade,
src/TipOfDay.py: Add window title

View File

@ -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 ''
#-------------------------------------------------------------------------
#
#

View File

@ -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 '