GEPS008: Create new module for file utilities

svn: r19906
This commit is contained in:
Nick Hall 2012-06-23 22:13:23 +00:00
parent 3ec4c0f80c
commit 2a0b009bdf
51 changed files with 424 additions and 360 deletions

View File

@ -211,6 +211,7 @@ src/gen/simple/_simpledoc.py
src/gen/utils/__init__.py
src/gen/utils/callback.py
src/gen/utils/callman.py
src/gen/utils/file.py
src/gen/utils/image.py
src/gen/utils/referent.py

View File

@ -36,7 +36,6 @@ import sys
import locale
import random
import time
import shutil
import uuid
import logging
LOG = logging.getLogger(".")
@ -51,7 +50,7 @@ import gen.lib
from gen.errors import DatabaseError
from gen.datehandler import displayer as date_displayer, codeset
from gen.config import config
from const import TEMP_DIR, USER_HOME, GRAMPS_UUID, IMAGE_DIR
from const import GRAMPS_UUID, IMAGE_DIR
from gen.constfunc import mac, win
from gen.ggettext import sgettext as _
@ -282,129 +281,6 @@ else:
conv_utf8_tosrtkey_ongtk = lambda x: locale.strxfrm(x)
conv_unicode_tosrtkey_ongtk = lambda x: locale.strxfrm(x)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def find_file( filename):
# try the filename we got
try:
fname = filename
if os.path.isfile( filename):
return( filename)
except:
pass
# Build list of alternate encodings
encodings = set()
#Darwin returns "mac roman" for preferredencoding, but since it
#returns "UTF-8" for filesystemencoding, and that's first, this
#works.
for enc in [sys.getfilesystemencoding, locale.getpreferredencoding]:
try:
encodings.add(enc)
except:
pass
encodings.add('UTF-8')
encodings.add('ISO-8859-1')
for enc in encodings:
try:
fname = filename.encode(enc)
if os.path.isfile( fname):
return fname
except:
pass
# 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 alternate encodings
try:
encodings = [sys.getfilesystemencoding(),
locale.getpreferredencoding(),
'UTF-8', 'ISO-8859-1']
except:
encodings = [sys.getfilesystemencoding(), 'UTF-8', 'ISO-8859-1']
encodings = list(set(encodings))
for enc in encodings:
try:
fname = filename.encode(enc)
if os.path.isdir( fname):
return fname
except:
pass
# not found
return ''
def get_unicode_path_from_file_chooser(path):
"""
Return the Unicode version of a path string.
:type path: str
:param path: The path to be converted to Unicode
:rtype: unicode
:returns: The Unicode version of path.
"""
# make only unicode of path of type 'str'
if not (isinstance(path, str)):
return path
if win():
# in windows filechooser returns officially utf-8, not filesystemencoding
try:
return unicode(path)
except:
LOG.warn("Problem encountered converting string: %s." % path)
return unicode(path, sys.getfilesystemencoding(), errors='replace')
else:
try:
return unicode(path, sys.getfilesystemencoding())
except:
LOG.warn("Problem encountered converting string: %s." % path)
return unicode(path, sys.getfilesystemencoding(), errors='replace')
def get_unicode_path_from_env_var(path):
"""
Return the Unicode version of a path string.
:type path: str
:param path: The path to be converted to Unicode
:rtype: unicode
:returns: The Unicode version of path.
"""
# make only unicode of path of type 'str'
if not (isinstance(path, str)):
return path
if win():
# In Windows path/filename returned from a environment variable is in filesystemencoding
try:
new_path = unicode(path, sys.getfilesystemencoding())
return new_path
except:
LOG.warn("Problem encountered converting string: %s." % path)
return unicode(path, sys.getfilesystemencoding(), errors='replace')
else:
try:
return unicode(path)
except:
LOG.warn("Problem encountered converting string: %s." % path)
return unicode(path, sys.getfilesystemencoding(), errors='replace')
#-------------------------------------------------------------------------
#
# Iterate over ancestors.
@ -452,25 +328,6 @@ from warnings import warn
def set_titles(window, title, t, msg=None):
warn('The Utils.set_titles is deprecated. Use ManagedWindow methods')
def search_for(name):
if name.startswith( '"' ):
name = name.split('"')[1]
else:
name = name.split()[0]
if win():
for i in os.environ['PATH'].split(';'):
fname = os.path.join(i, name)
if os.access(fname, os.X_OK) and not os.path.isdir(fname):
return 1
if os.access(name, os.X_OK) and not os.path.isdir(name):
return 1
else:
for i in os.environ['PATH'].split(':'):
fname = os.path.join(i, name)
if os.access(fname, os.X_OK) and not os.path.isdir(fname):
return 1
return 0
#-------------------------------------------------------------------------
#
# create_id
@ -495,35 +352,6 @@ def create_uid(self, handle=None):
#
#
#-------------------------------------------------------------------------
_NEW_NAME_PATTERN = '%s%sUntitled_%d.%s'
def get_new_filename(ext, folder='~/'):
ix = 1
while os.path.isfile(os.path.expanduser(_NEW_NAME_PATTERN %
(folder, os.path.sep, ix, ext))):
ix = ix + 1
return os.path.expanduser(_NEW_NAME_PATTERN % (folder, os.path.sep, ix, ext))
def get_empty_tempdir(dirname):
""" Return path to TEMP_DIR/dirname, a guaranteed empty directory
makes intervening directories if required
fails if _file_ by that name already exists,
or for inadequate permissions to delete dir/files or create dir(s)
"""
dirpath = os.path.join(TEMP_DIR,dirname)
if os.path.isdir(dirpath):
shutil.rmtree(dirpath)
os.makedirs(dirpath)
dirpath = get_unicode_path_from_env_var(dirpath)
return dirpath
def rm_tempdir(path):
"""Remove a tempdir created with get_empty_tempdir"""
if path.startswith(TEMP_DIR) and os.path.isdir(path):
shutil.rmtree(path)
def cast_to_bool(val):
if val == str(True):
return True
@ -580,66 +408,6 @@ def get_type_converter_by_name(val_str):
return unicode
return unicode
def relative_path(original, base):
"""
Calculate the relative path from base to original, with base a directory,
and original an absolute path
On problems, original is returned unchanged
"""
if not os.path.isdir(base):
return original
#original and base must be absolute paths
if not os.path.isabs(base):
return original
if not os.path.isabs(original):
return original
original = os.path.normpath(original)
base = os.path.normpath(base)
# If the db_dir and obj_dir are on different drives (win only)
# then there cannot be a relative path. Return original obj_path
(base_drive, base) = os.path.splitdrive(base)
(orig_drive, orig_name) = os.path.splitdrive(original)
if base_drive.upper() != orig_drive.upper():
return original
# Starting from the filepath root, work out how much of the filepath is
# shared by base and target.
base_list = (base).split(os.sep)
target_list = (orig_name).split(os.sep)
# make sure '/home/person' and 'c:/home/person' both give
# list ['home', 'person']
base_list = filter(None, base_list)
target_list = filter(None, target_list)
i = -1
for i in range(min(len(base_list), len(target_list))):
if base_list[i] <> target_list[i]: break
else:
#if break did not happen we are here at end, and add 1.
i += 1
rel_list = [os.pardir] * (len(base_list)-i) + target_list[i:]
return os.path.join(*rel_list)
def media_path(db):
"""
Given a database, return the mediapath to use as basedir for media
"""
mpath = db.get_mediapath()
if mpath is None:
#use home dir
mpath = USER_HOME
return mpath
def media_path_full(db, filename):
"""
Given a database and a filename of a media, return the media filename
is full form, eg 'graves/tomb.png' becomes '/home/me/genea/graves/tomb.png
"""
if os.path.isabs(filename):
return filename
mpath = media_path(db)
return os.path.join(mpath, filename)
def profile(func, *args):
import hotshot.stats

View File

@ -46,7 +46,8 @@ from gen.ggettext import gettext as _
#
#-------------------------------------------------------------------------
from gen.recentfiles import recent_files
import Utils
from gen.utils.file import (rm_tempdir, get_empty_tempdir,
get_unicode_path_from_env_var)
import gen
from clidbman import CLIDbManager, NAME_FILE, find_locker_name
@ -207,7 +208,7 @@ class ArgHandler(object):
"""
if value is None:
return None
value = Utils.get_unicode_path_from_env_var(value)
value = get_unicode_path_from_env_var(value)
db_path = self.__deduce_db_path(value)
if db_path:
@ -237,7 +238,7 @@ class ArgHandler(object):
"""
# Need to convert path/filename to unicode before opening
# For non latin characters in Windows path/file/user names
value = Utils.get_unicode_path_from_env_var(value)
value = get_unicode_path_from_env_var(value)
fname = value
fullpath = os.path.abspath(os.path.expanduser(fname))
if fname != '-' and not os.path.exists(fullpath):
@ -274,7 +275,7 @@ class ArgHandler(object):
return
# Need to convert path/filename to unicode before opening
# For non latin characters in Windows path/file/user names
value = Utils.get_unicode_path_from_env_var(value)
value = get_unicode_path_from_env_var(value)
fname = value
if fname == '-':
fullpath = '-'
@ -450,7 +451,7 @@ class ArgHandler(object):
# remove files in import db subdir after use
self.dbstate.db.close()
if self.imp_db_path:
Utils.rm_tempdir(self.imp_db_path)
rm_tempdir(self.imp_db_path)
def __import_action(self):
"""
@ -469,7 +470,7 @@ class ArgHandler(object):
if self.gui:
self.imp_db_path, title = self.dbman.create_new_db_cli()
else:
self.imp_db_path = Utils.get_empty_tempdir("import_dbdir") \
self.imp_db_path = get_empty_tempdir("import_dbdir") \
.encode(sys.getfilesystemencoding())
newdb = gen.db.DbBsddb()
newdb.write_version(self.imp_db_path)

View File

@ -49,7 +49,7 @@ import logging
import const
from gen.config import config
from gen.utils.configmanager import safe_eval
import Utils
from gen.utils.file import get_unicode_path_from_env_var
# Note: Make sure to edit const.py.in POPT_TABLE too!
_HELP = _("""
@ -216,7 +216,7 @@ class ArgParser(object):
# -Ärik is '-\xc3\x84rik' and getopt will respond :
# option -\xc3 not recognized
for arg in range(len(self.args) - 1):
self.args[arg+1] = Utils.get_unicode_path_from_env_var(self.args[arg + 1])
self.args[arg+1] = get_unicode_path_from_env_var(self.args[arg + 1])
options, leftargs = getopt.getopt(self.args[1:],
const.SHORTOPTS, const.LONGOPTS)
except getopt.GetoptError, msg:
@ -350,7 +350,7 @@ class ArgParser(object):
# but not for non-latin characters in list elements
cliargs = "[ "
for arg in range(len(self.args) - 1):
cliargs += Utils.get_unicode_path_from_env_var(self.args[arg + 1]) + " "
cliargs += get_unicode_path_from_env_var(self.args[arg + 1]) + " "
cliargs += "]"
self.errors += [(_('Error parsing the arguments'),
_("Error parsing the arguments: %s \n"

View File

@ -43,7 +43,7 @@ import sys
#
#-------------------------------------------------------------------------------
from gen.ggettext import gettext as _
import Utils
from gen.utils.file import search_for
from gen.plug.docgen import BaseDoc
from gen.plug.menu import NumberOption, TextOption, EnumeratedListOption, \
BooleanOption
@ -88,18 +88,18 @@ _NOTELOC = [ { 'name' : _("Top"), 'value' : "t" },
{ 'name' : _("Bottom"), 'value' : "b" }]
if win():
_DOT_FOUND = Utils.search_for("dot.exe")
_DOT_FOUND = search_for("dot.exe")
if Utils.search_for("gswin32c.exe") == 1:
if search_for("gswin32c.exe") == 1:
_GS_CMD = "gswin32c.exe"
elif Utils.search_for("gswin32.exe") == 1:
elif search_for("gswin32.exe") == 1:
_GS_CMD = "gswin32.exe"
else:
_GS_CMD = ""
else:
_DOT_FOUND = Utils.search_for("dot")
_DOT_FOUND = search_for("dot")
if Utils.search_for("gs") == 1:
if search_for("gs") == 1:
_GS_CMD = "gs"
else:
_GS_CMD = ""

View File

@ -42,7 +42,7 @@ from gen.ggettext import gettext as _
#
#------------------------------------------------------------------------
import gen.datehandler
from Utils import media_path_full
from gen.utils.file import media_path_full
from gen.plug.docgen import IndexMark, INDEX_TYPE_ALP
#-------------------------------------------------------------------------

View File

@ -40,7 +40,7 @@ import os
#-------------------------------------------------------------------------
from gen.plug._pluginreg import make_environment
import const
import Utils
from gen.utils.file import get_unicode_path_from_file_chooser
from gen.ggettext import gettext as _
#-------------------------------------------------------------------------
@ -287,7 +287,7 @@ def load_addon_file(path, callback=None):
gpr_files = set([os.path.split(os.path.join(const.USER_PLUGINS, name))[0]
for name in good_gpr])
for gpr_file in gpr_files:
u_gpr_file = Utils.get_unicode_path_from_file_chooser(gpr_file)
u_gpr_file = get_unicode_path_from_file_chooser(gpr_file)
if callback:
callback(" " + (_("Registered '%s'") % u_gpr_file) + "\n")
file_obj.close()

View File

@ -13,6 +13,7 @@ pkgpython_PYTHON = \
callman.py \
configmanager.py \
fallback.py \
file.py \
image.py \
keyword.py \
lds.py \

281
src/gen/utils/file.py Normal file
View File

@ -0,0 +1,281 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2007 Donald N. Allingham
# Copyright (C) 2009 Gary Burton
# Copyright (C) 2011 Tim G L Lyons
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id$
"""
File and folder related utility functions
"""
#-------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
import os
import sys
import locale
import shutil
import logging
LOG = logging.getLogger(".gen.utils.file")
#-------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
from gen.constfunc import win
from const import TEMP_DIR, USER_HOME
#-------------------------------------------------------------------------
#
# Constants
#
#-------------------------------------------------------------------------
_NEW_NAME_PATTERN = '%s%sUntitled_%d.%s'
#-------------------------------------------------------------------------
#
# Functions
#
#-------------------------------------------------------------------------
def find_file( filename):
# try the filename we got
try:
fname = filename
if os.path.isfile( filename):
return( filename)
except:
pass
# Build list of alternate encodings
encodings = set()
#Darwin returns "mac roman" for preferredencoding, but since it
#returns "UTF-8" for filesystemencoding, and that's first, this
#works.
for enc in [sys.getfilesystemencoding, locale.getpreferredencoding]:
try:
encodings.add(enc)
except:
pass
encodings.add('UTF-8')
encodings.add('ISO-8859-1')
for enc in encodings:
try:
fname = filename.encode(enc)
if os.path.isfile( fname):
return fname
except:
pass
# 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 alternate encodings
try:
encodings = [sys.getfilesystemencoding(),
locale.getpreferredencoding(),
'UTF-8', 'ISO-8859-1']
except:
encodings = [sys.getfilesystemencoding(), 'UTF-8', 'ISO-8859-1']
encodings = list(set(encodings))
for enc in encodings:
try:
fname = filename.encode(enc)
if os.path.isdir( fname):
return fname
except:
pass
# not found
return ''
def get_unicode_path_from_file_chooser(path):
"""
Return the Unicode version of a path string.
:type path: str
:param path: The path to be converted to Unicode
:rtype: unicode
:returns: The Unicode version of path.
"""
# make only unicode of path of type 'str'
if not (isinstance(path, str)):
return path
if win():
# in windows filechooser returns officially utf-8, not filesystemencoding
try:
return unicode(path)
except:
LOG.warn("Problem encountered converting string: %s." % path)
return unicode(path, sys.getfilesystemencoding(), errors='replace')
else:
try:
return unicode(path, sys.getfilesystemencoding())
except:
LOG.warn("Problem encountered converting string: %s." % path)
return unicode(path, sys.getfilesystemencoding(), errors='replace')
def get_unicode_path_from_env_var(path):
"""
Return the Unicode version of a path string.
:type path: str
:param path: The path to be converted to Unicode
:rtype: unicode
:returns: The Unicode version of path.
"""
# make only unicode of path of type 'str'
if not (isinstance(path, str)):
return path
if win():
# In Windows path/filename returned from a environment variable is in filesystemencoding
try:
new_path = unicode(path, sys.getfilesystemencoding())
return new_path
except:
LOG.warn("Problem encountered converting string: %s." % path)
return unicode(path, sys.getfilesystemencoding(), errors='replace')
else:
try:
return unicode(path)
except:
LOG.warn("Problem encountered converting string: %s." % path)
return unicode(path, sys.getfilesystemencoding(), errors='replace')
def get_new_filename(ext, folder='~/'):
ix = 1
while os.path.isfile(os.path.expanduser(_NEW_NAME_PATTERN %
(folder, os.path.sep, ix, ext))):
ix = ix + 1
return os.path.expanduser(_NEW_NAME_PATTERN % (folder, os.path.sep, ix, ext))
def get_empty_tempdir(dirname):
""" Return path to TEMP_DIR/dirname, a guaranteed empty directory
makes intervening directories if required
fails if _file_ by that name already exists,
or for inadequate permissions to delete dir/files or create dir(s)
"""
dirpath = os.path.join(TEMP_DIR,dirname)
if os.path.isdir(dirpath):
shutil.rmtree(dirpath)
os.makedirs(dirpath)
dirpath = get_unicode_path_from_env_var(dirpath)
return dirpath
def rm_tempdir(path):
"""Remove a tempdir created with get_empty_tempdir"""
if path.startswith(TEMP_DIR) and os.path.isdir(path):
shutil.rmtree(path)
def relative_path(original, base):
"""
Calculate the relative path from base to original, with base a directory,
and original an absolute path
On problems, original is returned unchanged
"""
if not os.path.isdir(base):
return original
#original and base must be absolute paths
if not os.path.isabs(base):
return original
if not os.path.isabs(original):
return original
original = os.path.normpath(original)
base = os.path.normpath(base)
# If the db_dir and obj_dir are on different drives (win only)
# then there cannot be a relative path. Return original obj_path
(base_drive, base) = os.path.splitdrive(base)
(orig_drive, orig_name) = os.path.splitdrive(original)
if base_drive.upper() != orig_drive.upper():
return original
# Starting from the filepath root, work out how much of the filepath is
# shared by base and target.
base_list = (base).split(os.sep)
target_list = (orig_name).split(os.sep)
# make sure '/home/person' and 'c:/home/person' both give
# list ['home', 'person']
base_list = filter(None, base_list)
target_list = filter(None, target_list)
i = -1
for i in range(min(len(base_list), len(target_list))):
if base_list[i] <> target_list[i]: break
else:
#if break did not happen we are here at end, and add 1.
i += 1
rel_list = [os.pardir] * (len(base_list)-i) + target_list[i:]
return os.path.join(*rel_list)
def media_path(db):
"""
Given a database, return the mediapath to use as basedir for media
"""
mpath = db.get_mediapath()
if mpath is None:
#use home dir
mpath = USER_HOME
return mpath
def media_path_full(db, filename):
"""
Given a database and a filename of a media, return the media filename
is full form, eg 'graves/tomb.png' becomes '/home/me/genea/graves/tomb.png
"""
if os.path.isabs(filename):
return filename
mpath = media_path(db)
return os.path.join(mpath, filename)
def search_for(name):
if name.startswith( '"' ):
name = name.split('"')[1]
else:
name = name.split()[0]
if win():
for i in os.environ['PATH'].split(';'):
fname = os.path.join(i, name)
if os.access(fname, os.X_OK) and not os.path.isdir(fname):
return 1
if os.access(name, os.X_OK) and not os.path.isdir(name):
return 1
else:
for i in os.environ['PATH'].split(':'):
fname = os.path.join(i, name)
if os.access(fname, os.X_OK) and not os.path.isdir(fname):
return 1
return 0

View File

@ -44,7 +44,7 @@ import tempfile
# Gramps modules
#
#-------------------------------------------------------------------------
import Utils
from gen.utils.file import get_unicode_path_from_env_var
#-------------------------------------------------------------------------
#
@ -257,7 +257,7 @@ def resize_to_jpeg_buffer(source, size, crop=None):
scaled = img.scale_simple(int(size[0]), int(size[1]), gtk.gdk.INTERP_BILINEAR)
os.close(filed)
dest = Utils.get_unicode_path_from_env_var(dest)
dest = get_unicode_path_from_env_var(dest)
scaled.save(dest, 'jpeg')
ofile = open(dest, mode='rb')
data = ofile.read()

View File

@ -263,7 +263,7 @@ def get_addon_translator(filename=None, domain="addon", languages=None):
# Check if path is of type str. Do import and conversion if so.
# The import cannot be done at the top as that will conflict with the translation system.
if type(path) == str:
from Utils import get_unicode_path_from_env_var
from gen.utils.file import get_unicode_path_from_env_var
path = get_unicode_path_from_env_var(path)
if languages:
addon_translator = gettext.translation(domain, os.path.join(path,"locale"),

View File

@ -51,7 +51,7 @@ import const
import gen.datehandler
from gen.display.name import displayer as _nd
from gen.display.name import NameDisplayError
from Utils import get_unicode_path_from_file_chooser
from gen.utils.file import get_unicode_path_from_file_chooser
from gen.utils.alive import update_constants
from gen.utils.keyword import (get_keywords, get_translation_from_keyword,
get_translations, get_keyword_from_translation)

View File

@ -57,7 +57,7 @@ import gobject
from cli.grampscli import CLIDbLoader
from gen.config import config
import gen.db
import Utils
from gen.utils.file import get_unicode_path_from_file_chooser
from gui.pluginmanager import GuiPluginManager
from gui.dialog import (DBErrorDialog, ErrorDialog, QuestionDialog2,
WarningDialog)
@ -162,7 +162,7 @@ class DbLoader(CLIDbLoader):
if response == gtk.RESPONSE_CANCEL:
break
elif response == gtk.RESPONSE_OK:
filename = Utils.get_unicode_path_from_file_chooser(import_dialog.get_filename())
filename = get_unicode_path_from_file_chooser(import_dialog.get_filename())
if self.check_errors(filename):
# displays errors if any
continue

View File

@ -79,7 +79,7 @@ from gen.recentfiles import rename_filename, remove_filename
from gui.glade import Glade
from gen.db.backup import restore
from gen.db.exceptions import DbException
from Utils import get_unicode_path_from_env_var
from gen.utils.file import get_unicode_path_from_env_var
_RETURN = gtk.gdk.keyval_from_name("Return")

View File

@ -52,7 +52,8 @@ import gtk
#-------------------------------------------------------------------------
import const
from gen.config import config
import Utils
from gen.utils.file import (media_path_full, media_path, relative_path,
find_file, get_unicode_path_from_file_chooser)
import gen.mime
from gui.thumbnails import find_mime_type_pixbuf
from gui.display import display_help
@ -101,7 +102,7 @@ class AddMediaObject(ManagedWindow):
self.last_directory = const.USER_HOME
#if existing path, use dir of path
if not self.obj.get_path() == "":
fullname = Utils.media_path_full(self.dbase, self.obj.get_path())
fullname = media_path_full(self.dbase, self.obj.get_path())
dir = os.path.dirname(fullname)
if os.path.isdir(dir):
self.last_directory = dir
@ -149,17 +150,17 @@ class AddMediaObject(ManagedWindow):
ErrorDialog(msgstr, msgstr2)
return
filename = Utils.get_unicode_path_from_file_chooser(self.file_text.get_filename())
filename = get_unicode_path_from_file_chooser(self.file_text.get_filename())
full_file = filename
if self.relpath.get_active():
pname = unicode(Utils.media_path(self.dbase))
pname = unicode(media_path(self.dbase))
if not os.path.exists(pname):
msgstr = _("Cannot import %s")
msgstr2 = _("Directory specified in preferences: Base path for relative media paths: %s does not exist. Change preferences or do not use relative path when importing")
ErrorDialog(msgstr % filename, msgstr2 % pname)
return
filename = Utils.relative_path(filename, pname)
filename = relative_path(filename, pname)
mtype = gen.mime.get_type(full_file)
@ -186,7 +187,7 @@ class AddMediaObject(ManagedWindow):
fname = self.file_text.get_filename()
if not fname:
return
filename = Utils.get_unicode_path_from_file_chooser(fname)
filename = get_unicode_path_from_file_chooser(fname)
basename = os.path.basename(filename)
(root, ext) = os.path.splitext(basename)
old_title = unicode(self.description.get_text())
@ -195,7 +196,7 @@ class AddMediaObject(ManagedWindow):
self.description.set_text(root)
self.temp_name = root
filename = Utils.find_file( filename)
filename = find_file( filename)
if filename:
mtype = gen.mime.get_type(filename)
if mtype and mtype.startswith("image"):

View File

@ -53,6 +53,7 @@ from gui.selectors import SelectorFactory
import gen.lib
from gen.db import DbTxn
import Utils
from gen.utils.file import media_path_full, media_path, relative_path
from gui.thumbnails import get_thumbnail_image
from gen.errors import WindowActiveError
import gen.mime
@ -131,7 +132,7 @@ class GalleryTab(ButtonTab, DbGUIElement):
menu = gtk.Menu()
ref_obj = self.dbstate.db.get_object_from_handle(obj.ref)
media_path = Utils.media_path_full(self.dbstate.db, ref_obj.get_path())
media_path = media_path_full(self.dbstate.db, ref_obj.get_path())
if media_path:
item = gtk.ImageMenuItem(_('View'))
img = gtk.Image()
@ -251,7 +252,7 @@ class GalleryTab(ButtonTab, DbGUIElement):
_('Non existing media found in the Gallery'))
else :
pixbuf = get_thumbnail_image(
Utils.media_path_full(self.dbstate.db,
media_path_full(self.dbstate.db,
obj.get_path()),
obj.get_mime_type(),
ref.get_rectangle())
@ -502,9 +503,9 @@ class GalleryTab(ButtonTab, DbGUIElement):
if not gen.mime.is_valid_type(mime):
return
photo = gen.lib.MediaObject()
base_dir = unicode(Utils.media_path(self.dbstate.db))
base_dir = unicode(media_path(self.dbstate.db))
if os.path.exists(base_dir):
name = Utils.relative_path(name, base_dir)
name = relative_path(name, base_dir)
photo.set_path(name)
photo.set_mime_type(mime)
basename = os.path.basename(name)

View File

@ -47,7 +47,8 @@ import gen.lib
from gen.db import DbTxn
import gen.mime
from gui.thumbnails import get_thumbnail_image, find_mime_type_pixbuf
import Utils
from gen.utils.file import (media_path_full, find_file,
get_unicode_path_from_file_chooser)
from editprimary import EditPrimary
from gui.widgets import (MonitoredDate, MonitoredEntry, PrivacyButton,
MonitoredTagList)
@ -156,10 +157,10 @@ class EditMedia(EditPrimary):
self.mimetext.set_text(descr)
path = self.file_path.get_text()
path_full = Utils.media_path_full(self.db, path)
path_full = media_path_full(self.db, path)
if path != self.obj.get_path() and path_full != self.obj.get_path():
#redetermine mime
mime = gen.mime.get_type(Utils.find_file(path_full))
mime = gen.mime.get_type(find_file(path_full))
self.obj.set_mime_type(mime)
descr = gen.mime.get_description(mime)
if descr:
@ -174,7 +175,7 @@ class EditMedia(EditPrimary):
mtype = self.obj.get_mime_type()
if mtype:
pb = get_thumbnail_image(
Utils.media_path_full(self.db, self.obj.get_path()),
media_path_full(self.db, self.obj.get_path()),
mtype)
self.pixmap.set_from_pixbuf(pb)
else:
@ -238,14 +239,14 @@ class EditMedia(EditPrimary):
ref_obj = self.dbstate.db.get_object_from_handle(self.obj.handle)
if ref_obj:
media_path = Utils.media_path_full(self.dbstate.db,
media_path = media_path_full(self.dbstate.db,
ref_obj.get_path())
open_file_with_default_application(media_path)
def select_file(self, val):
self.determine_mime()
path = self.file_path.get_text()
self.obj.set_path(Utils.get_unicode_path_from_file_chooser(path))
self.obj.set_path(get_unicode_path_from_file_chooser(path))
AddMediaObject(self.dbstate, self.uistate, self.track, self.obj,
self._update_addmedia)
@ -289,7 +290,7 @@ class EditMedia(EditPrimary):
path = self.file_path.get_text()
self.determine_mime()
self.obj.set_path(Utils.get_unicode_path_from_file_chooser(path))
self.obj.set_path(get_unicode_path_from_file_chooser(path))
with DbTxn('', self.db) as trans:
if not self.obj.get_handle():

View File

@ -47,7 +47,8 @@ from gui.utils import open_file_with_default_application
import const
import gen.mime
from gui.thumbnails import get_thumbnail_image, find_mime_type_pixbuf
import Utils
from gen.utils.file import (media_path_full, find_file,
get_unicode_path_from_file_chooser)
from gen.lib import NoteType
from gen.db import DbTxn
from gui.glade import Glade
@ -118,10 +119,10 @@ class EditMediaRef(EditReference):
self.mimetext.set_text(descr)
path = self.file_path.get_text()
path_full = Utils.media_path_full(self.db, path)
path_full = media_path_full(self.db, path)
if path != self.source.get_path() and path_full != self.source.get_path():
#redetermine mime
mime = gen.mime.get_type(Utils.find_file(path_full))
mime = gen.mime.get_type(find_file(path_full))
self.source.set_mime_type(mime)
descr = gen.mime.get_description(mime)
if descr:
@ -139,7 +140,7 @@ class EditMediaRef(EditReference):
"""
mtype = self.source.get_mime_type()
if mtype:
fullpath = Utils.media_path_full(self.db, self.source.get_path())
fullpath = media_path_full(self.db, self.source.get_path())
pb = get_thumbnail_image(fullpath, mtype)
self.pixmap.set_from_pixbuf(pb)
subpix = get_thumbnail_image(fullpath, mtype,
@ -394,7 +395,7 @@ class EditMediaRef(EditReference):
self.subpixmap.hide()
else:
try:
fullpath = Utils.media_path_full(self.db, path)
fullpath = media_path_full(self.db, path)
pixbuf = gtk.gdk.pixbuf_new_from_file(fullpath)
width = pixbuf.get_width()
height = pixbuf.get_height()
@ -433,7 +434,7 @@ class EditMediaRef(EditReference):
def button_press_event(self, obj, event):
if event.button==1 and event.type == gtk.gdk._2BUTTON_PRESS:
photo_path = Utils.media_path_full(self.db, self.source.get_path())
photo_path = media_path_full(self.db, self.source.get_path())
open_file_with_default_application(photo_path)
def button_press_event_ref(self, widget, event):
@ -581,7 +582,7 @@ class EditMediaRef(EditReference):
def select_file(self, val):
self.determine_mime()
path = self.file_path.get_text()
self.source.set_path(Utils.get_unicode_path_from_file_chooser(path))
self.source.set_path(get_unicode_path_from_file_chooser(path))
AddMediaObject(self.dbstate, self.uistate, self.track, self.source,
self._update_addmedia)

View File

@ -49,7 +49,7 @@ import pango
# gramps modules
#
#-------------------------------------------------------------------------
import Utils
from gen.utils.file import media_path_full
from gui.thumbnails import get_thumbnail_image
import gui.utils
from gen.utils import get_birth_or_fallback
@ -636,7 +636,7 @@ class EditPerson(EditPrimary):
photo = media_list[0]
object_handle = photo.get_reference_handle()
ref_obj = self.db.get_object_from_handle(object_handle)
photo_path = Utils.media_path_full(self.db, ref_obj.get_path())
photo_path = media_path_full(self.db, ref_obj.get_path())
gui.utils.open_file_with_default_application(photo_path)
def _popup_change_description(self, obj):
@ -940,7 +940,7 @@ class EditPerson(EditPrimary):
Load the person's main photo using the Thumbnailer.
"""
pixbuf = get_thumbnail_image(
Utils.media_path_full(self.dbstate.db,
media_path_full(self.dbstate.db,
obj.get_path()),
obj.get_mime_type(),
ref.get_rectangle())

View File

@ -50,7 +50,7 @@ import gobject
# gramps modules
#
#-------------------------------------------------------------------------
import Utils
from gen.utils.file import get_unicode_path_from_file_chooser
from gui.utils import ProgressMeter
from gui.pluginmanager import GuiPluginManager
from gui import widgets
@ -1688,7 +1688,7 @@ class GuiDestinationOption(gtk.HBox):
status = fcd.run()
if status == gtk.RESPONSE_OK:
path = Utils.get_unicode_path_from_file_chooser(fcd.get_filename())
path = get_unicode_path_from_file_chooser(fcd.get_filename())
if path:
if not self.__option.get_directory_entry() and \
not path.endswith(self.__option.get_extension()):

View File

@ -56,7 +56,7 @@ import tool
from _guioptions import add_gui_options
from gui.dialog import InfoDialog
from gui.editors import EditPerson
import Utils
from gen.utils.file import get_unicode_path_from_file_chooser
import const
from gen.config import config
@ -432,7 +432,7 @@ class PluginStatus(ManagedWindow):
status = fcd.run()
if status == gtk.RESPONSE_OK:
path = Utils.get_unicode_path_from_file_chooser(fcd.get_filename())
path = get_unicode_path_from_file_chooser(fcd.get_filename())
if path:
self.install_addon_path.set_text(path)
fcd.destroy()

View File

@ -58,7 +58,8 @@ import gtk
import const
from gen.config import config
from gui.pluginmanager import GuiPluginManager
import Utils
from gen.utils.file import (find_folder, get_new_filename,
get_unicode_path_from_file_chooser)
from gui.managedwindow import ManagedWindow
from gui.dialog import ErrorDialog
from gui.user import User
@ -358,8 +359,8 @@ class ExportAssistant(gtk.Assistant, ManagedWindow) :
filename = filechooser.get_filename()
folder = filechooser.get_current_folder()
#the file must be valid, not a folder, and folder must be valid
if filename and filename.strip and Utils.find_folder(filename) == '' \
and folder and Utils.find_folder(folder):
if filename and filename.strip and find_folder(filename) == '' \
and folder and find_folder(folder):
#this page of the assistant is complete
self.set_page_complete(filechooser, True)
##workaround around bug http://bugzilla.gnome.org/show_bug.cgi?id=56070
@ -488,7 +489,7 @@ class ExportAssistant(gtk.Assistant, ManagedWindow) :
#Allow for exotic error: file is still not correct
self.check_fileselect(self.chooser, show=False)
if self.get_page_complete(self.chooser) :
filename = Utils.get_unicode_path_from_file_chooser(self.chooser.get_filename())
filename = get_unicode_path_from_file_chooser(self.chooser.get_filename())
name = os.path.split(filename)[1]
folder = os.path.split(filename)[0]
confirm_text = _(
@ -611,7 +612,7 @@ class ExportAssistant(gtk.Assistant, ManagedWindow) :
elif ext == 'burn':
new_filename = os.path.basename(self.dbstate.db.get_save_path())
else:
new_filename = Utils.get_new_filename(ext,default_dir)
new_filename = get_new_filename(ext,default_dir)
return (default_dir, os.path.split(new_filename)[1])
def save(self):
@ -625,7 +626,7 @@ class ExportAssistant(gtk.Assistant, ManagedWindow) :
hasattr(self.option_box_instance, "no_fileselect")):
filename = ""
else:
filename = Utils.get_unicode_path_from_file_chooser(self.chooser.get_filename())
filename = get_unicode_path_from_file_chooser(self.chooser.get_filename())
config.set('paths.recent-export-dir', os.path.split(filename)[0])
ix = self.get_selected_format_index()
config.set('behavior.recent-export-type', ix)

View File

@ -24,7 +24,7 @@
import os
import gtk
import Utils
from gen.utils.file import get_unicode_path_from_file_chooser
class FileEntry(gtk.HBox):
""" A widget that allows the user to select a file from the file system """
@ -74,7 +74,7 @@ class FileEntry(gtk.HBox):
dialog.present()
status = dialog.run()
if status == gtk.RESPONSE_OK:
self.set_filename(Utils.get_unicode_path_from_file_chooser(dialog.get_filename()))
self.set_filename(get_unicode_path_from_file_chooser(dialog.get_filename()))
dialog.destroy()
def set_filename(self, path):

View File

@ -64,7 +64,7 @@ from _stylecombobox import StyleComboBox
from _styleeditor import StyleListDisplay
from _fileentry import FileEntry
from const import URL_MANUAL_PAGE
import Utils
from gen.utils.file import get_unicode_path_from_file_chooser
#-------------------------------------------------------------------------
#
# Private Constants
@ -496,7 +496,7 @@ class ReportDialog(ManagedWindow):
to tell the calling routine to give up. This function also
saves the current directory so that any future reports will
default to the most recently used directory."""
self.target_path = Utils.get_unicode_path_from_file_chooser(self.target_fileentry.get_full_path(0))
self.target_path = get_unicode_path_from_file_chooser(self.target_fileentry.get_full_path(0))
if not self.target_path:
return None

View File

@ -45,7 +45,7 @@ import gtk
#
#-------------------------------------------------------------------------
import const
from Utils import media_path_full
from gen.utils.file import media_path_full
from gui.thumbnails import get_thumbnail_image
from gui.views.treemodels import MediaModel
from baseselector import BaseSelector

View File

@ -86,7 +86,8 @@ from gui.dialog import (ErrorDialog, WarningDialog, QuestionDialog2,
InfoDialog)
from gui import widgets
from gui.undohistory import UndoHistory
import Utils
from gen.utils.file import (media_path_full, get_unicode_path_from_env_var,
get_unicode_path_from_file_chooser)
from gui.dbloader import DbLoader
from gui.display import display_help, display_url
from gui.widgets.progressdialog import ProgressMonitor, GtkProgressDialog
@ -1527,7 +1528,7 @@ class ViewManager(CLIManager):
bytes = 0
mbytes = "0"
for media in self.dbstate.db.iter_media_objects():
fullname = Utils.media_path_full(self.dbstate.db, media.get_path())
fullname = media_path_full(self.dbstate.db, media.get_path())
try:
bytes += posixpath.getsize(fullname)
length = len(str(bytes))
@ -1559,7 +1560,7 @@ class ViewManager(CLIManager):
filename = os.path.join(path_entry.get_text(), basefile)
filename = filename.encode(sys.getfilesystemencoding())
if os.path.exists(filename):
sfilename = Utils.get_unicode_path_from_env_var(filename)
sfilename = get_unicode_path_from_env_var(filename)
question = QuestionDialog2(
_("Backup file already exists! Overwrite?"),
_("The file '%s' exists.") % sfilename,
@ -1587,7 +1588,7 @@ class ViewManager(CLIManager):
writer.write(filename)
self.uistate.set_busy_cursor(0)
self.uistate.progress.hide()
filename = Utils.get_unicode_path_from_env_var(filename)
filename = get_unicode_path_from_env_var(filename)
self.uistate.push_message(self.dbstate, _("Backup saved to '%s'") % filename)
config.set('paths.quick-backup-directory', path_entry.get_text())
else:
@ -1624,7 +1625,7 @@ class ViewManager(CLIManager):
if status == gtk.RESPONSE_OK:
filename = f.get_filename()
if filename:
val = Utils.get_unicode_path_from_file_chooser(filename)
val = get_unicode_path_from_file_chooser(filename)
if val:
path_entry.set_text(val)
f.destroy()

View File

@ -59,6 +59,7 @@ from gui.filters import SearchBar
from gui.utils import add_menuitem
import const
import Utils
from gen.utils.file import get_unicode_path_from_file_chooser
from gui.dialog import QuestionDialog, QuestionDialog2
from gui.editors import FilterEditor
from gen.ggettext import sgettext as _
@ -941,7 +942,7 @@ class ListView(NavigationView):
while True:
value = chooser.run()
fn = chooser.get_filename()
fn = Utils.get_unicode_path_from_file_chooser(fn)
fn = get_unicode_path_from_file_chooser(fn)
fl = combobox.get_active()
if value == gtk.RESPONSE_OK:
if fn:

View File

@ -48,7 +48,7 @@ import libgedcom
from gen.errors import DatabaseError
from gui.plug.export import WriterOptionBox
from gen.updatecallback import UpdateCallback
from Utils import media_path_full
from gen.utils.file import media_path_full
from gen.utils.place import conv_lat_lon
#-------------------------------------------------------------------------

View File

@ -61,7 +61,7 @@ import gtk
#-------------------------------------------------------------------------
from gui.plug.export import WriterOptionBox
from ExportXml import XmlWriter
import Utils
from gen.utils.file import media_path_full, get_unicode_path_from_file_chooser
from gen.constfunc import win
#-------------------------------------------------------------------------
@ -157,7 +157,7 @@ class PackageWriter(object):
# pass
# def fs_ok_clicked(obj):
# name = Utils.get_unicode_path_from_file_chooser(fs_top.get_filename())
# name = get_unicode_path_from_file_chooser(fs_top.get_filename())
# if os.path.isfile(name):
# archive.add(name)
@ -185,7 +185,7 @@ class PackageWriter(object):
# during the process (i.e. when removing object)
for m_id in self.db.get_media_object_handles(sort_handles=True):
mobject = self.db.get_object_from_handle(m_id)
filename = Utils.media_path_full(self.db, mobject.get_path())
filename = media_path_full(self.db, mobject.get_path())
archname = str(mobject.get_path())
if os.path.isfile(filename) and os.access(filename, os.R_OK):
archive.add(filename, archname)

View File

@ -64,7 +64,7 @@ from gui.dialog import QuestionDialog, OptionDialog
from gen.lib import Date
import gen.mime
import Utils
from gen.utils.file import search_for, media_path_full
from gen.utils.place import conv_lat_lon
from gen.db import DbTxn
@ -82,9 +82,9 @@ else:
# validate the exiv2 is installed and its executable
system_platform = os.sys.platform
if system_platform == "win32":
EXIV2_FOUND = "exiv2.exe" if Utils.search_for("exiv2.exe") else False
EXIV2_FOUND = "exiv2.exe" if search_for("exiv2.exe") else False
else:
EXIV2_FOUND = "exiv2" if Utils.search_for("exiv2") else False
EXIV2_FOUND = "exiv2" if search_for("exiv2") else False
if not EXIV2_FOUND:
msg = 'You must have exiv2 and its development file installed.'
raise SystemExit(msg)
@ -406,7 +406,7 @@ class EditExifMetadata(Gramplet):
return
# get file path and attempt to find it?
self.image_path =Utils.media_path_full(db, self.orig_image.get_path() )
self.image_path = media_path_full(db, self.orig_image.get_path() )
if not os.path.isfile(self.image_path):
self.set_has_data(False)
return
@ -583,7 +583,7 @@ class EditExifMetadata(Gramplet):
if media is None:
return False
full_path = Utils.media_path_full(self.dbstate.db, media.get_path())
full_path = media_path_full(self.dbstate.db, media.get_path())
return self.view.get_has_data(full_path)
def __create_button(self, pos, text, callback =[], icon =False, sensitive =False):

View File

@ -22,7 +22,7 @@
from gen.plug import Gramplet
from gui.widgets import Photo
import Utils
from gen.utils.file import media_path_full
import gtk
class Gallery(Gramplet):
@ -59,7 +59,7 @@ class Gallery(Gramplet):
for media_ref in media_list:
media_handle = media_ref.get_reference_handle()
media = self.dbstate.db.get_object_from_handle(media_handle)
full_path = Utils.media_path_full(self.dbstate.db, media.get_path())
full_path = media_path_full(self.dbstate.db, media.get_path())
mime_type = media.get_mime_type()
if mime_type and mime_type.startswith("image"):
photo = Photo(self.uistate.screen_height() < 1000)

View File

@ -21,7 +21,7 @@
from gen.plug import Gramplet
from gui.widgets import Photo
import Utils
from gen.utils.file import media_path_full
import gtk
class MediaPreview(Gramplet):
@ -68,7 +68,7 @@ class MediaPreview(Gramplet):
"""
Load the primary image if it exists.
"""
self.full_path = Utils.media_path_full(self.dbstate.db,
self.full_path = media_path_full(self.dbstate.db,
media.get_path())
mime_type = media.get_mime_type()
self.photo.set_image(self.full_path, mime_type)

View File

@ -24,7 +24,7 @@
from libmetadata import MetadataView
from gen.plug import Gramplet
import Utils
from gen.utils.file import media_path_full
class MetadataViewer(Gramplet):
"""
@ -49,7 +49,7 @@ class MetadataViewer(Gramplet):
media = self.dbstate.db.get_object_from_handle(active_handle)
if media:
full_path = Utils.media_path_full(self.dbstate.db, media.get_path())
full_path = media_path_full(self.dbstate.db, media.get_path())
has_data = self.view.display_exif_tags(full_path)
self.set_has_data(has_data)
else:
@ -67,5 +67,5 @@ class MetadataViewer(Gramplet):
if media is None:
return False
full_path = Utils.media_path_full(self.dbstate.db, media.get_path())
full_path = media_path_full(self.dbstate.db, media.get_path())
return self.view.get_has_data(full_path)

View File

@ -25,7 +25,7 @@ from gui.widgets import Photo
from gen.display.name import displayer as name_displayer
from gen.ggettext import gettext as _
import gen.datehandler
import Utils
from gen.utils.file import media_path_full
import gtk
import pango
@ -223,7 +223,7 @@ class PersonDetails(Gramplet):
media_ref = media_list[0]
object_handle = media_ref.get_reference_handle()
obj = self.dbstate.db.get_object_from_handle(object_handle)
full_path = Utils.media_path_full(self.dbstate.db, obj.get_path())
full_path = media_path_full(self.dbstate.db, obj.get_path())
mime_type = obj.get_mime_type()
if mime_type and mime_type.startswith("image"):
self.photo.set_image(full_path, mime_type,

View File

@ -23,7 +23,7 @@ from gen.plug import Gramplet
from gui.widgets import Photo
from gen.ggettext import gettext as _
from gen.utils.place import conv_lat_lon
import Utils
from gen.utils.file import media_path_full
import gtk
import pango
@ -153,7 +153,7 @@ class PlaceDetails(Gramplet):
media_ref = media_list[0]
object_handle = media_ref.get_reference_handle()
obj = self.dbstate.db.get_object_from_handle(object_handle)
full_path = Utils.media_path_full(self.dbstate.db, obj.get_path())
full_path = media_path_full(self.dbstate.db, obj.get_path())
mime_type = obj.get_mime_type()
if mime_type and mime_type.startswith("image"):
self.photo.set_image(full_path, mime_type,

View File

@ -32,7 +32,7 @@ import posixpath
#------------------------------------------------------------------------
from gen.plug import Gramplet
from gen.ggettext import sgettext as _
from Utils import media_path_full
from gen.utils.file import media_path_full
import gen.datehandler
import gen

View File

@ -51,7 +51,7 @@ log = logging.getLogger(".FamilyLines")
#
#------------------------------------------------------------------------
import gen.lib
import Utils
from gen.utils.file import media_path_full
from gui.thumbnails import get_thumbnail_path
from gen.datehandler import displayer as _dd
from gen.plug.report import Report
@ -797,7 +797,7 @@ class FamilyLinesReport(Report):
mediaMimeType = media.get_mime_type()
if mediaMimeType[0:5] == "image":
imagePath = get_thumbnail_path(
Utils.media_path_full(self._db,
media_path_full(self._db,
media.get_path()),
rectangle=mediaList[0].get_rectangle())

View File

@ -55,7 +55,7 @@ from gen.plug.report import MenuReportOptions
from gen.display.name import displayer as name_displayer
import gen.datehandler
import gen.lib
import Utils
from gen.utils.file import media_path_full, find_file
from gui.thumbnails import get_thumbnail_path
from gen.utils import get_birth_or_fallback, get_death_or_fallback
@ -355,12 +355,12 @@ class RelGraphReport(Report):
mediaMimeType = media.get_mime_type()
if mediaMimeType[0:5] == "image":
imagePath = get_thumbnail_path(
Utils.media_path_full(self.database,
media_path_full(self.database,
media.get_path()),
rectangle=mediaList[0].get_rectangle())
# test if thumbnail actually exists in thumbs
# (import of data means media files might not be present
imagePath = Utils.find_file(imagePath)
imagePath = find_file(imagePath)
label = u""
lineDelimiter = '\\n'

View File

@ -48,7 +48,7 @@ log = logging.getLogger(".ReadPkg")
#-------------------------------------------------------------------------
import const
import ImportXml
import Utils
from gen.utils.file import media_path
#-------------------------------------------------------------------------
#
@ -61,7 +61,7 @@ def impData(database, name, user):
# in the mediapath dir of the family tree we import to
oldmediapath = database.get_mediapath()
#use home dir if no media path
media_path = Utils.media_path(database)
media_path = media_path(database)
media_dir = "%s.media" % os.path.basename(name)
tmpdir_path = os.path.join(media_path, media_dir)
if not os.path.isdir(tmpdir_path):

View File

@ -29,7 +29,7 @@ Display filtered data
from gen.simple import SimpleAccess, SimpleDoc
from gui.plug.quick import QuickTable
from Utils import media_path_full
from gen.utils.file import media_path_full
from gui.plug.quick import run_quick_report_by_name_direct
from gen.lib import Person
import gen.datehandler

View File

@ -53,7 +53,7 @@ from gen.plug.report import MenuReportOptions
from gen.plug.report import Bibliography
from gen.plug.report import endnotes as Endnotes
from gen.display.name import displayer as global_name_display
from Utils import media_path_full
from gen.utils.file import media_path_full
#------------------------------------------------------------------------
#

View File

@ -37,7 +37,7 @@ import os
#
#------------------------------------------------------------------------
from gen.plug.menu import StringOption, MediaOption, NumberOption
from Utils import media_path_full
from gen.utils.file import media_path_full
from gen.plug.report import Report
from gen.plug.report import MenuReportOptions
from gen.plug.docgen import (FontStyle, ParagraphStyle,

View File

@ -45,7 +45,7 @@ from gen.plug.report import utils as ReportUtils
from gen.plug.report import MenuReportOptions
from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle,
FONT_SANS_SERIF, INDEX_TYPE_TOC, PARA_ALIGN_CENTER)
from Utils import media_path_full
from gen.utils.file import media_path_full
import gen.datehandler

View File

@ -66,6 +66,9 @@ import gen.lib
from gen.db import DbTxn
from gen.config import config
import Utils
from gen.utils.file import (get_unicode_path_from_file_chooser,
media_path_full,
find_file)
from gui.utils import ProgressMeter
from gui.managedwindow import ManagedWindow
@ -630,7 +633,7 @@ class CheckIntegrity(object):
LOG(' FAIL: references to missing file kept')
def fs_ok_clicked(obj):
name = Utils.get_unicode_path_from_file_chooser(fs_top.get_filename())
name = get_unicode_path_from_file_chooser(fs_top.get_filename())
if os.path.isfile(name):
obj = self.db.get_object_from_handle(ObjectId)
obj.set_path(name)
@ -658,9 +661,9 @@ class CheckIntegrity(object):
for ObjectId in self.db.get_media_object_handles():
obj = self.db.get_object_from_handle(ObjectId)
photo_name = Utils.media_path_full(self.db, obj.get_path())
photo_name = media_path_full(self.db, obj.get_path())
photo_desc = obj.get_description()
if photo_name is not None and photo_name != "" and not Utils.find_file(photo_name):
if photo_name is not None and photo_name != "" and not find_file(photo_name):
if cl:
# Convert to file system encoding before prining
fn = os.path.basename(photo_name).encode(sys.getfilesystemencoding())

View File

@ -47,7 +47,7 @@ import gtk
from gen.filters import GenericFilter, rules
from gui.filters import build_filter_model
from gen.sort import Sort
import Utils
from gen.utils.file import get_unicode_path_from_file_chooser
from gui.utils import ProgressMeter
from docgen import ODSTab
import const
@ -400,7 +400,7 @@ class DisplayChart(ManagedWindow):
f.hide()
if status == gtk.RESPONSE_OK:
name = Utils.get_unicode_path_from_file_chooser(f.get_filename())
name = get_unicode_path_from_file_chooser(f.get_filename())
doc = ODSTab(len(self.row_data))
doc.creator(self.db.get_researcher().get_name())

View File

@ -55,7 +55,7 @@ from gen.lib import MediaObject
from gen.db import DbTxn
from gen.updatecallback import UpdateCallback
from gui.plug import tool
from Utils import media_path_full, relative_path, media_path
from gen.utils.file import media_path_full, relative_path, media_path
from gen.ggettext import sgettext as _
import gen.mime

View File

@ -59,7 +59,7 @@ import gtk
#-------------------------------------------------------------------------
from gui.views.navigationview import NavigationView
from gui.views.bookmarks import PersonBookmarks
import Utils
from gen.utils.file import get_empty_tempdir
from gen.constfunc import lin, mac, win
from gen.config import config
from const import TEMP_DIR
@ -92,8 +92,8 @@ def get_identity():
# I think we should set the two following variable in const.py
# They are used only with gtkmozembed.
MOZEMBED_PATH = TEMP_DIR
MOZEMBED_SUBPATH = Utils.get_empty_tempdir('mozembed_gramps')
GEOVIEW_SUBPATH = Utils.get_empty_tempdir('geoview')
MOZEMBED_SUBPATH = get_empty_tempdir('mozembed_gramps')
GEOVIEW_SUBPATH = get_empty_tempdir('geoview')
NOWEB = 0
WEBKIT = 1
MOZILLA = 2

View File

@ -56,6 +56,7 @@ import const
from gen.constfunc import win
from gen.config import config
import Utils
from gen.utils.file import media_path, relative_path, media_path_full
from gen.utils.referent import get_media_referents
from gui.views.bookmarks import MediaBookmarks
import gen.mime
@ -190,9 +191,9 @@ class MediaView(ListView):
if not gen.mime.is_valid_type(mime):
return
photo = gen.lib.MediaObject()
base_dir = unicode(Utils.media_path(self.dbstate.db))
base_dir = unicode(media_path(self.dbstate.db))
if os.path.exists(base_dir):
name = Utils.relative_path(name, base_dir)
name = relative_path(name, base_dir)
photo.set_path(name)
photo.set_mime_type(mime)
basename = os.path.basename(name)
@ -249,7 +250,7 @@ class MediaView(ListView):
"""
for handle in self.selected_handles():
ref_obj = self.dbstate.db.get_object_from_handle(handle)
mpath = Utils.media_path_full(self.dbstate.db, ref_obj.get_path())
mpath = media_path_full(self.dbstate.db, ref_obj.get_path())
open_file_with_default_application(mpath)
def open_containing_folder(self, obj):
@ -258,7 +259,7 @@ class MediaView(ListView):
"""
for handle in self.selected_handles():
ref_obj = self.dbstate.db.get_object_from_handle(handle)
mpath = Utils.media_path_full(self.dbstate.db, ref_obj.get_path())
mpath = media_path_full(self.dbstate.db, ref_obj.get_path())
if mpath:
mfolder, mfile = os.path.split(mpath)
open_file_with_default_application(mfolder)

View File

@ -52,8 +52,8 @@ from gui.views.navigationview import NavigationView
from gui.editors import FilterEditor
from gen.display.name import displayer as name_displayer
from gen.utils.alive import probably_alive
from Utils import (media_path_full, find_children, find_parents,
find_witnessed_people)
from gen.utils.file import media_path_full
from Utils import find_children, find_parents, find_witnessed_people
from libformatting import FormattingHelper
from gui.thumbnails import get_thumbnail_path
from gen.errors import WindowActiveError

View File

@ -52,7 +52,7 @@ from gui.views.navigationview import NavigationView
from gui.editors import EditPerson, EditFamily
from gui.editors import FilterEditor
from gen.display.name import displayer as name_displayer
from Utils import media_path_full
from gen.utils.file import media_path_full
from gen.utils.alive import probably_alive
from gui.utils import open_file_with_default_application
import gen.datehandler

View File

@ -89,6 +89,7 @@ from gen.plug.report import utils as ReportUtils
from gen.plug.report import MenuReportOptions
import Utils
from gen.utils.file import media_path_full
from gen.utils.referent import get_source_and_citation_referents
from gen.constfunc import win
from gui.thumbnails import get_thumbnail_path, run_thumbnailer
@ -498,7 +499,7 @@ def copy_thumbnail(report, handle, photo, region=None):
)
if photo.get_mime_type():
from_path = get_thumbnail_path(Utils.media_path_full(
from_path = get_thumbnail_path(media_path_full(
report.database,
photo.get_path()),
photo.get_mime_type(),
@ -1837,7 +1838,7 @@ class BasePage(object):
try:
newpath, thumb_path = self.report.prepare_copy_media(obj)
self.report.copy_file(Utils.media_path_full(
self.report.copy_file(media_path_full(
self.report.database, obj.get_path()), newpath)
# begin image
@ -3941,7 +3942,7 @@ class MediaPage(BasePage):
# improve the site's responsiveness. We don't want the user to
# have to await a large download unnecessarily. Either way, set
# the display image size as requested.
orig_image_path = Utils.media_path_full(self.dbase_, media.get_path())
orig_image_path = media_path_full(self.dbase_, media.get_path())
(width, height) = image_size(orig_image_path)
max_width = self.report.options['maxinitialimagewidth']
max_height = self.report.options['maxinitialimageheight']
@ -4008,7 +4009,7 @@ class MediaPage(BasePage):
dirname = tempfile.mkdtemp()
thmb_path = os.path.join(dirname, "document.png")
if run_thumbnailer(mime_type,
Utils.media_path_full(self.dbase_, media.get_path()),
media_path_full(self.dbase_, media.get_path()),
thmb_path, 320):
try:
path = self.report.build_path("preview", media.get_handle())
@ -4130,7 +4131,7 @@ class MediaPage(BasePage):
to_dir = self.report.build_path('images', handle)
newpath = os.path.join(to_dir, handle) + ext
fullpath = Utils.media_path_full(self.dbase_, photo.get_path())
fullpath = media_path_full(self.dbase_, photo.get_path())
if not os.path.isfile(fullpath):
_WRONGMEDIAPATH.append([ photo.get_gramps_id(), fullpath])
return None