GEPS008: Create new module for file utilities

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

No files matched your search

+1 -1
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
#-------------------------------------------------------------------------
+3 -3
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)
+5 -5
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):
+2 -2
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)
+2 -2
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)
+3 -3
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)
+2 -2
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,
+2 -2
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,
+1 -1
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
+2 -2
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())
+3 -3
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'
+2 -2
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):
+1 -1
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
+1 -1
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
#------------------------------------------------------------------------
#
+1 -1
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,
+1 -1
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
+6 -3
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())
+2 -2
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())
+1 -1
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
+3 -3
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
+5 -4
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)
+2 -2
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
+1 -1
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
+6 -5
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