2006-08-18 03:58:18 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
2008-05-19 00:54:28 +05:30
|
|
|
# Copyright (C) 2008 B. Malengier
|
|
|
|
# Copyright (C) 2008 Brian G. Matherly
|
2006-08-18 03:58:18 +05:30
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
2006-08-18 11:34:54 +05:30
|
|
|
# Written by Alex Roitman
|
|
|
|
|
2006-08-18 03:58:18 +05:30
|
|
|
# $Id$
|
|
|
|
|
2008-03-02 04:17:48 +05:30
|
|
|
"""Tools/Utilities/Media Manager"""
|
2006-08-18 03:58:18 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# standard python modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2009-06-16 21:19:17 +05:30
|
|
|
from __future__ import with_statement
|
2006-08-18 03:58:18 +05:30
|
|
|
import os
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME/GTK modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import gtk
|
2008-01-18 22:33:55 +05:30
|
|
|
import gobject
|
2006-08-18 03:58:18 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2009-02-26 15:38:38 +05:30
|
|
|
import const
|
2006-08-18 03:58:18 +05:30
|
|
|
import GrampsDisplay
|
|
|
|
import Assistant
|
|
|
|
import Errors
|
2007-10-08 22:11:39 +05:30
|
|
|
from gen.lib import MediaObject
|
2010-01-11 01:51:10 +05:30
|
|
|
from gen.updatecallback import UpdateCallback
|
2008-10-02 09:32:10 +05:30
|
|
|
from PluginUtils import Tool
|
2008-02-12 03:57:24 +05:30
|
|
|
from Utils import media_path_full, relative_path, media_path
|
2010-01-18 10:12:17 +05:30
|
|
|
from gen.ggettext import sgettext as _
|
2008-04-18 16:33:01 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-02-26 15:38:38 +05:30
|
|
|
WIKI_HELP_PAGE = '%s_-_Tools' % const.URL_MANUAL_PAGE
|
2008-04-18 16:33:01 +05:30
|
|
|
WIKI_HELP_SEC = _('manual|Media_Manager...')
|
2006-08-18 03:58:18 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# This is an Assistant implementation to guide the user
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class MediaMan(Tool.Tool):
|
|
|
|
|
|
|
|
def __init__(self, dbstate, uistate, options_class, name, callback=None):
|
|
|
|
|
|
|
|
Tool.Tool.__init__(self, dbstate, options_class, name)
|
|
|
|
self.uistate = uistate
|
2006-08-18 05:14:49 +05:30
|
|
|
self.callback = uistate.pulse_progressbar
|
2006-08-18 03:58:18 +05:30
|
|
|
|
|
|
|
self.build_batch_ops()
|
|
|
|
self.batch_settings = None
|
2006-08-18 06:46:55 +05:30
|
|
|
self.settings_page = None
|
2006-08-18 03:58:18 +05:30
|
|
|
|
|
|
|
try:
|
|
|
|
self.w = Assistant.Assistant(uistate,self.__class__,self.complete,
|
|
|
|
_("Media Manager"))
|
|
|
|
except Errors.WindowActiveError:
|
|
|
|
return
|
|
|
|
|
2009-11-18 01:44:53 +05:30
|
|
|
self.welcome_page = self.w.add_text_page(_('Gramps Media Manager'),
|
2006-08-18 03:58:18 +05:30
|
|
|
self.get_info_text())
|
|
|
|
self.selection_page = self.w.add_page(_('Selecting operation'),
|
|
|
|
self.build_selection_page())
|
2006-08-18 06:46:55 +05:30
|
|
|
self.confirm_page = self.w.add_text_page('','')
|
2006-08-18 03:58:18 +05:30
|
|
|
self.conclusion_page = self.w.add_text_page('','')
|
|
|
|
|
|
|
|
self.w.connect('before-page-next',self.on_before_page_next)
|
|
|
|
|
|
|
|
self.w.show()
|
|
|
|
|
|
|
|
def complete(self):
|
|
|
|
pass
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def on_before_page_next(self, obj,page,data=None):
|
2006-08-18 03:58:18 +05:30
|
|
|
if page == self.selection_page:
|
|
|
|
self.build_settings_page()
|
2006-08-18 06:46:55 +05:30
|
|
|
elif page == self.settings_page:
|
|
|
|
self.build_confirmation()
|
2006-08-18 03:58:18 +05:30
|
|
|
elif page == self.confirm_page:
|
|
|
|
success = self.run()
|
|
|
|
self.build_conclusion(success)
|
|
|
|
|
|
|
|
def get_info_text(self):
|
|
|
|
return _("This tool allows batch operations on media objects "
|
2009-11-18 01:44:53 +05:30
|
|
|
"stored in Gramps. "
|
|
|
|
"An important distinction must be made between a Gramps "
|
2006-08-18 03:58:18 +05:30
|
|
|
"media object and its file.\n\n"
|
2009-11-18 01:44:53 +05:30
|
|
|
"The Gramps media object is a collection of data about "
|
2006-08-18 03:58:18 +05:30
|
|
|
"the media object file: its filename and/or path, its "
|
|
|
|
"description, its ID, notes, source references, etc. "
|
|
|
|
"These data <b>do not include the file itself</b>.\n\n"
|
2006-08-19 02:15:58 +05:30
|
|
|
"The files containing image, sound, video, etc, exist "
|
2006-08-18 11:34:54 +05:30
|
|
|
"separately on your hard drive. These files are "
|
2009-11-18 01:44:53 +05:30
|
|
|
"not managed by Gramps and are not included in the Gramps "
|
2006-08-18 03:58:18 +05:30
|
|
|
"database. "
|
2009-11-18 01:44:53 +05:30
|
|
|
"The Gramps database only stores the path and file names.\n\n"
|
2006-08-18 11:34:54 +05:30
|
|
|
"This tool allows you to only modify the records within "
|
2009-11-18 01:44:53 +05:30
|
|
|
"your Gramps database. If you want to move or rename "
|
2006-08-18 11:34:54 +05:30
|
|
|
"the files then you need to do it on your own, outside of "
|
2009-11-18 01:44:53 +05:30
|
|
|
"Gramps. Then you can adjust the paths using this tool so "
|
2006-08-18 11:34:54 +05:30
|
|
|
"that the media objects store the correct file locations.")
|
2006-08-18 03:58:18 +05:30
|
|
|
|
|
|
|
def build_selection_page(self):
|
|
|
|
"""
|
|
|
|
Build a page with the radio buttons for every available batch op.
|
|
|
|
"""
|
|
|
|
self.batch_op_buttons = []
|
|
|
|
|
|
|
|
box = gtk.VBox()
|
|
|
|
box.set_spacing(12)
|
|
|
|
|
|
|
|
table = gtk.Table(2*len(self.batch_ops),2)
|
|
|
|
table.set_row_spacings(6)
|
|
|
|
table.set_col_spacings(6)
|
|
|
|
|
|
|
|
group = None
|
|
|
|
for ix in range(len(self.batch_ops)):
|
2006-08-19 02:15:58 +05:30
|
|
|
title = self.batch_ops[ix].title
|
|
|
|
description= self.batch_ops[ix].description
|
2006-08-18 03:58:18 +05:30
|
|
|
|
|
|
|
button = gtk.RadioButton(group,title)
|
2009-10-08 01:31:39 +05:30
|
|
|
button.set_tooltip_text(description)
|
2006-08-18 03:58:18 +05:30
|
|
|
if not group:
|
|
|
|
group = button
|
|
|
|
self.batch_op_buttons.append(button)
|
2006-08-18 05:14:49 +05:30
|
|
|
table.attach(button,0,2,2*ix,2*ix+1,yoptions=0)
|
2006-08-18 03:58:18 +05:30
|
|
|
|
|
|
|
box.add(table)
|
|
|
|
return box
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def on_help_clicked(self, obj):
|
2006-08-18 03:58:18 +05:30
|
|
|
"""Display the relevant portion of GRAMPS manual"""
|
2008-04-18 16:33:01 +05:30
|
|
|
GrampsDisplay.help(webpage=WIKI_HELP_PAGE, section=WIKI_HELP_SEC)
|
2006-08-18 03:58:18 +05:30
|
|
|
|
|
|
|
def build_batch_ops(self):
|
|
|
|
self.batch_ops = []
|
|
|
|
batches_to_use = [
|
2006-08-18 06:46:55 +05:30
|
|
|
PathChange,
|
2006-08-19 09:25:02 +05:30
|
|
|
Convert2Abs,
|
2006-08-19 10:45:44 +05:30
|
|
|
Convert2Rel,
|
2006-08-18 03:58:18 +05:30
|
|
|
]
|
|
|
|
|
|
|
|
for batch_class in batches_to_use:
|
2006-08-19 02:15:58 +05:30
|
|
|
self.batch_ops.append(batch_class(self.db,self.callback))
|
2006-08-18 03:58:18 +05:30
|
|
|
|
|
|
|
def get_selected_op_index(self):
|
|
|
|
"""
|
|
|
|
Query the selection radiobuttons and return the index number
|
|
|
|
of the selected batch op.
|
|
|
|
"""
|
|
|
|
for ix in range(len(self.batch_op_buttons)):
|
|
|
|
button = self.batch_op_buttons[ix]
|
|
|
|
if button.get_active():
|
|
|
|
return ix
|
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def build_settings_page(self):
|
|
|
|
"""
|
|
|
|
Build an extra page with the settings specific for the chosen batch-op.
|
|
|
|
If there's already an entry for this batch-op then do nothing,
|
|
|
|
otherwise add a page.
|
|
|
|
|
|
|
|
If the chosen batch-op does not have settings then remove the
|
|
|
|
settings page that is already there (from previous user passes
|
|
|
|
through the assistant).
|
|
|
|
"""
|
|
|
|
ix = self.get_selected_op_index()
|
2006-08-19 02:15:58 +05:30
|
|
|
config = self.batch_ops[ix].build_config()
|
|
|
|
if config:
|
2006-08-18 03:58:18 +05:30
|
|
|
if ix == self.batch_settings:
|
|
|
|
return
|
|
|
|
elif self.batch_settings:
|
|
|
|
self.w.remove_page(self.settings_page)
|
2006-08-19 09:25:02 +05:30
|
|
|
self.settings_page = None
|
|
|
|
self.confirm_page -= 1
|
|
|
|
self.conclusion_page -= 1
|
2006-08-18 03:58:18 +05:30
|
|
|
self.batch_settings = None
|
2006-08-19 02:15:58 +05:30
|
|
|
self.build_confirmation()
|
|
|
|
title,box = config
|
2006-08-18 03:58:18 +05:30
|
|
|
self.settings_page = self.w.insert_page(title,box,
|
|
|
|
self.selection_page+1)
|
|
|
|
self.confirm_page += 1
|
|
|
|
self.conclusion_page += 1
|
|
|
|
self.batch_settings = ix
|
|
|
|
box.show_all()
|
2006-08-19 09:25:02 +05:30
|
|
|
else:
|
2008-06-16 20:31:46 +05:30
|
|
|
if self.batch_settings is not None:
|
2006-08-19 09:25:02 +05:30
|
|
|
self.w.remove_page(self.settings_page)
|
|
|
|
self.settings_page = None
|
|
|
|
self.confirm_page -= 1
|
|
|
|
self.conclusion_page -= 1
|
|
|
|
self.batch_settings = None
|
2006-08-19 02:15:58 +05:30
|
|
|
self.build_confirmation()
|
2006-08-18 03:58:18 +05:30
|
|
|
|
2006-08-18 06:46:55 +05:30
|
|
|
def build_confirmation(self):
|
|
|
|
"""
|
2006-08-19 02:15:58 +05:30
|
|
|
Build the confirmation page.
|
|
|
|
|
|
|
|
This should query the selected settings and present the summary
|
|
|
|
of the proposed action, as well as the list of affected paths.
|
2006-08-18 06:46:55 +05:30
|
|
|
"""
|
2006-08-19 02:15:58 +05:30
|
|
|
|
2006-08-18 06:46:55 +05:30
|
|
|
ix = self.get_selected_op_index()
|
2006-08-19 02:15:58 +05:30
|
|
|
confirm_text = self.batch_ops[ix].build_confirm_text()
|
|
|
|
path_list = self.batch_ops[ix].build_path_list()
|
|
|
|
|
|
|
|
box = gtk.VBox()
|
|
|
|
box.set_spacing(12)
|
|
|
|
box.set_border_width(12)
|
|
|
|
|
|
|
|
label1 = gtk.Label(confirm_text)
|
|
|
|
label1.set_line_wrap(True)
|
|
|
|
label1.set_use_markup(True)
|
|
|
|
label1.set_alignment(0,0.5)
|
|
|
|
box.pack_start(label1,expand=False)
|
|
|
|
|
|
|
|
scrolled_window = gtk.ScrolledWindow()
|
|
|
|
scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
|
|
|
|
scrolled_window.set_shadow_type(gtk.SHADOW_IN)
|
|
|
|
tree = gtk.TreeView()
|
2008-01-18 22:33:55 +05:30
|
|
|
model = gtk.ListStore(gobject.TYPE_STRING)
|
2006-08-19 02:15:58 +05:30
|
|
|
tree.set_model(model)
|
|
|
|
tree_view_column = gtk.TreeViewColumn(_('Affected path'),
|
|
|
|
gtk.CellRendererText(),text=0)
|
|
|
|
tree_view_column.set_sort_column_id(0)
|
|
|
|
tree.append_column(tree_view_column)
|
|
|
|
for path in path_list:
|
|
|
|
model.append(row=[path])
|
|
|
|
scrolled_window.add(tree)
|
|
|
|
box.pack_start(scrolled_window,expand=True,fill=True)
|
|
|
|
|
|
|
|
label3 = gtk.Label(_('Press OK to proceed, Cancel to abort, '
|
|
|
|
'or Back to revisit your options.'))
|
|
|
|
box.pack_start(label3,expand=False)
|
|
|
|
box.show_all()
|
|
|
|
|
2006-08-18 06:46:55 +05:30
|
|
|
self.w.remove_page(self.confirm_page)
|
2006-08-19 02:15:58 +05:30
|
|
|
self.confirm_page = self.w.insert_page(_('Final confirmation'),
|
|
|
|
box,self.confirm_page)
|
2006-08-18 06:46:55 +05:30
|
|
|
|
2006-08-18 03:58:18 +05:30
|
|
|
def run(self):
|
|
|
|
"""
|
|
|
|
Run selected batch op with selected settings.
|
|
|
|
"""
|
|
|
|
ix = self.get_selected_op_index()
|
|
|
|
self.pre_run()
|
2006-08-19 02:15:58 +05:30
|
|
|
success = self.batch_ops[ix].run_tool()
|
2006-08-18 03:58:18 +05:30
|
|
|
self.post_run()
|
|
|
|
return success
|
|
|
|
|
|
|
|
def pre_run(self):
|
|
|
|
self.uistate.set_busy_cursor(1)
|
|
|
|
self.w.set_busy_cursor(1)
|
|
|
|
self.uistate.progress.show()
|
|
|
|
|
|
|
|
def post_run(self):
|
|
|
|
self.uistate.set_busy_cursor(0)
|
|
|
|
self.w.set_busy_cursor(0)
|
|
|
|
self.uistate.progress.hide()
|
|
|
|
|
|
|
|
def build_conclusion(self,success):
|
|
|
|
if success:
|
|
|
|
conclusion_title = _('Operation succesfully finished.')
|
|
|
|
conclusion_text = _(
|
2006-08-19 10:45:44 +05:30
|
|
|
'The operation you requested has finished successfully. '
|
|
|
|
'You may press OK button now to continue.')
|
2006-08-18 03:58:18 +05:30
|
|
|
else:
|
|
|
|
conclusion_title = _('Operation failed'),
|
|
|
|
conclusion_text = _(
|
|
|
|
'There was an error while performing the requested '
|
|
|
|
'operation. You may try starting the tool again.')
|
|
|
|
self.w.remove_page(self.conclusion_page)
|
|
|
|
self.conclusion_page = self.w.insert_text_page(conclusion_title,
|
|
|
|
conclusion_text,
|
|
|
|
self.conclusion_page)
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# These are the actuall sub-tools (batch-ops) for use from Assistant
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2006-08-19 02:15:58 +05:30
|
|
|
class BatchOp(UpdateCallback):
|
2006-08-18 05:14:49 +05:30
|
|
|
"""
|
|
|
|
Base class for the sub-tools.
|
|
|
|
"""
|
2006-08-19 02:15:58 +05:30
|
|
|
title = 'Untitled operation'
|
2006-08-18 05:14:49 +05:30
|
|
|
description = 'This operation needs to be described'
|
|
|
|
|
2006-08-19 02:15:58 +05:30
|
|
|
def __init__(self,db,callback):
|
|
|
|
UpdateCallback.__init__(self,callback)
|
|
|
|
self.db = db
|
|
|
|
self.prepared = False
|
|
|
|
|
2006-08-18 03:58:18 +05:30
|
|
|
def build_config(self):
|
2006-08-18 05:14:49 +05:30
|
|
|
"""
|
|
|
|
This method should return either None (if the batch op requires
|
|
|
|
no settings to run) or a tuple (title,box) for the settings page.
|
|
|
|
"""
|
2006-08-18 03:58:18 +05:30
|
|
|
return None
|
|
|
|
|
2006-08-18 06:46:55 +05:30
|
|
|
def build_confirm_text(self):
|
|
|
|
"""
|
|
|
|
This method should return either None (if the batch op requires
|
|
|
|
no confirmation) or a string with the confirmation text.
|
|
|
|
"""
|
2006-08-19 10:45:44 +05:30
|
|
|
text = _(
|
|
|
|
'The following action is to be performed:\n\n'
|
|
|
|
'Operation:\t%s') % self.title.replace('_','')
|
|
|
|
return text
|
2006-08-18 06:46:55 +05:30
|
|
|
|
2006-08-19 02:15:58 +05:30
|
|
|
def build_path_list(self):
|
|
|
|
"""
|
|
|
|
This method returns a list of the path names that would be
|
|
|
|
affected by the batch op. Typically it would rely on prepare()
|
|
|
|
to do the actual job, but it does not have to be that way.
|
|
|
|
"""
|
|
|
|
self.prepare()
|
|
|
|
return self.path_list
|
|
|
|
|
|
|
|
def run_tool(self):
|
|
|
|
"""
|
|
|
|
This method runs the batch op, taking care of database signals
|
|
|
|
and transactions before and after the running.
|
|
|
|
Should not be overridden without good reasons.
|
|
|
|
"""
|
|
|
|
self._pre_run()
|
|
|
|
success = self._run()
|
|
|
|
self._post_run()
|
2006-08-18 06:46:55 +05:30
|
|
|
return success
|
|
|
|
|
2006-08-19 02:15:58 +05:30
|
|
|
def _pre_run(self):
|
|
|
|
"""
|
|
|
|
Low-level method for starting transaction and disabling signals.
|
|
|
|
Should not be overridden without good reasons.
|
|
|
|
"""
|
|
|
|
self.trans = self.db.transaction_begin("",batch=True)
|
|
|
|
self.db.disable_signals()
|
2006-08-18 06:46:55 +05:30
|
|
|
|
2006-08-19 02:15:58 +05:30
|
|
|
def _post_run(self):
|
|
|
|
"""
|
|
|
|
Low-level method for committing transaction and enabling signals.
|
|
|
|
Should not be overridden without good reasons.
|
|
|
|
"""
|
|
|
|
self.db.transaction_commit(self.trans,self.title)
|
|
|
|
self.db.enable_signals()
|
|
|
|
self.db.request_rebuild()
|
2006-08-18 06:46:55 +05:30
|
|
|
|
2006-08-19 02:15:58 +05:30
|
|
|
def _run(self):
|
|
|
|
"""
|
|
|
|
This method is the beef of the tool.
|
|
|
|
Needs to be overridden in the subclass.
|
|
|
|
"""
|
|
|
|
print "This method needs to be written."
|
2006-08-18 05:14:49 +05:30
|
|
|
print "Running BatchOp tool... done."
|
2006-08-18 03:58:18 +05:30
|
|
|
return True
|
|
|
|
|
2006-08-19 02:15:58 +05:30
|
|
|
def prepare(self):
|
|
|
|
"""
|
|
|
|
This method should prepare the tool for the actual run.
|
|
|
|
Typically this involves going over media objects and
|
|
|
|
selecting the ones that will be affected by the batch op.
|
|
|
|
|
|
|
|
This method should set self.prepared to True, to indicate
|
|
|
|
that it has already ran.
|
|
|
|
"""
|
2006-08-19 09:25:02 +05:30
|
|
|
self.handle_list = []
|
|
|
|
self.path_list = []
|
|
|
|
self._prepare()
|
2006-08-19 02:15:58 +05:30
|
|
|
self.prepared = True
|
2006-08-18 03:58:18 +05:30
|
|
|
|
2006-08-19 09:25:02 +05:30
|
|
|
def _prepare(self):
|
|
|
|
print "This method needs to be written."
|
|
|
|
print "Preparing BatchOp tool... done."
|
|
|
|
pass
|
|
|
|
|
2006-08-19 02:15:58 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
# Simple op to replace substrings in the paths
|
|
|
|
#------------------------------------------------------------------------
|
2006-08-18 05:14:49 +05:30
|
|
|
class PathChange(BatchOp):
|
2006-08-19 10:45:44 +05:30
|
|
|
title = _('Replace _substrings in the path')
|
2006-08-19 02:15:58 +05:30
|
|
|
description = _('This tool allows replacing specified substring in the '
|
|
|
|
'path of media objects with another substring. '
|
|
|
|
'This can be useful when you move your media files '
|
|
|
|
'from one directory to another')
|
|
|
|
|
2006-08-18 05:14:49 +05:30
|
|
|
def build_config(self):
|
2006-08-19 02:15:58 +05:30
|
|
|
title = _("Replace substring settings")
|
2006-08-18 05:14:49 +05:30
|
|
|
|
|
|
|
box = gtk.VBox()
|
|
|
|
box.set_spacing(12)
|
|
|
|
|
|
|
|
table = gtk.Table(2,2)
|
|
|
|
table.set_row_spacings(6)
|
|
|
|
table.set_col_spacings(6)
|
|
|
|
|
|
|
|
self.from_entry = gtk.Entry()
|
|
|
|
table.attach(self.from_entry,1,2,0,1,yoptions=0)
|
|
|
|
|
|
|
|
from_label = gtk.Label(_('_Replace:'))
|
|
|
|
from_label.set_use_underline(True)
|
|
|
|
from_label.set_alignment(0,0.5)
|
|
|
|
from_label.set_mnemonic_widget(self.from_entry)
|
|
|
|
table.attach(from_label,0,1,0,1,xoptions=0,yoptions=0)
|
|
|
|
|
|
|
|
self.to_entry = gtk.Entry()
|
|
|
|
table.attach(self.to_entry,1,2,1,2,yoptions=0)
|
|
|
|
|
|
|
|
to_label = gtk.Label(_('_With:'))
|
|
|
|
to_label.set_use_underline(True)
|
|
|
|
to_label.set_alignment(0,0.5)
|
|
|
|
to_label.set_mnemonic_widget(self.to_entry)
|
|
|
|
table.attach(to_label,0,1,1,2,xoptions=0,yoptions=0)
|
|
|
|
|
|
|
|
box.add(table)
|
|
|
|
|
|
|
|
return (title,box)
|
|
|
|
|
2006-08-18 06:46:55 +05:30
|
|
|
def build_confirm_text(self):
|
|
|
|
from_text = unicode(self.from_entry.get_text())
|
|
|
|
to_text = unicode(self.to_entry.get_text())
|
|
|
|
text = _(
|
|
|
|
'The following action is to be performed:\n\n'
|
2010-02-24 12:07:21 +05:30
|
|
|
'Operation:\t%(title)s\nReplace:\t\t%(source)s\nWith:\t\t%(dest_text)s') % {
|
|
|
|
'title' : self.title.replace('_',''), 'source' : from_text, 'dest_text' : to_text }
|
2006-08-18 06:46:55 +05:30
|
|
|
return text
|
|
|
|
|
2006-08-19 09:25:02 +05:30
|
|
|
def _prepare(self):
|
2006-08-18 05:14:49 +05:30
|
|
|
from_text = unicode(self.from_entry.get_text())
|
2006-08-19 02:15:58 +05:30
|
|
|
self.set_total(self.db.get_number_of_media_objects())
|
2009-06-16 21:19:17 +05:30
|
|
|
with self.db.get_media_cursor() as cursor:
|
|
|
|
for handle, data in cursor:
|
|
|
|
obj = MediaObject()
|
|
|
|
obj.unserialize(data)
|
|
|
|
if obj.get_path().find(from_text) != -1:
|
|
|
|
self.handle_list.append(handle)
|
|
|
|
self.path_list.append(obj.path)
|
|
|
|
self.update()
|
2006-08-19 02:15:58 +05:30
|
|
|
self.reset()
|
|
|
|
self.prepared = True
|
|
|
|
|
|
|
|
def _run(self):
|
|
|
|
if not self.prepared:
|
|
|
|
self.prepare()
|
|
|
|
self.set_total(len(self.handle_list))
|
|
|
|
from_text = unicode(self.from_entry.get_text())
|
|
|
|
to_text = unicode(self.to_entry.get_text())
|
|
|
|
for handle in self.handle_list:
|
|
|
|
obj = self.db.get_object_from_handle(handle)
|
|
|
|
new_path = obj.get_path().replace(from_text,to_text)
|
|
|
|
obj.set_path(new_path)
|
2006-08-19 09:25:02 +05:30
|
|
|
self.db.commit_media_object(obj,self.trans)
|
|
|
|
self.update()
|
|
|
|
return True
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#An op to convert relative paths to absolute
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class Convert2Abs(BatchOp):
|
|
|
|
title = _('Convert paths from relative to _absolute')
|
2008-04-17 23:49:27 +05:30
|
|
|
description = _("This tool allows converting relative media paths "
|
|
|
|
"to the absolute ones. It does this by prepending "
|
|
|
|
"the base path as given in the Preferences, or if "
|
|
|
|
"that is not set, it prepends user's directory.")
|
2006-08-19 09:25:02 +05:30
|
|
|
|
|
|
|
def _prepare(self):
|
|
|
|
self.set_total(self.db.get_number_of_media_objects())
|
2009-06-16 21:19:17 +05:30
|
|
|
with self.db.get_media_cursor() as cursor:
|
|
|
|
for handle, data in cursor:
|
|
|
|
obj = MediaObject()
|
|
|
|
obj.unserialize(data)
|
|
|
|
if not os.path.isabs(obj.path):
|
|
|
|
self.handle_list.append(handle)
|
|
|
|
self.path_list.append(obj.path)
|
|
|
|
self.update()
|
2006-08-19 09:25:02 +05:30
|
|
|
self.reset()
|
|
|
|
|
|
|
|
def _run(self):
|
|
|
|
if not self.prepared:
|
|
|
|
self.prepare()
|
|
|
|
self.set_total(len(self.handle_list))
|
|
|
|
for handle in self.handle_list:
|
|
|
|
obj = self.db.get_object_from_handle(handle)
|
2008-02-12 03:57:24 +05:30
|
|
|
new_path = media_path_full(self.db, obj.path)
|
2006-08-19 09:25:02 +05:30
|
|
|
obj.set_path(new_path)
|
2006-08-19 02:15:58 +05:30
|
|
|
self.db.commit_media_object(obj,self.trans)
|
2006-08-18 06:46:55 +05:30
|
|
|
self.update()
|
2006-08-18 05:14:49 +05:30
|
|
|
return True
|
|
|
|
|
2006-08-19 10:45:44 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#An op to convert absolute paths to relative
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class Convert2Rel(BatchOp):
|
2006-08-20 08:56:56 +05:30
|
|
|
title = _('Convert paths from absolute to r_elative')
|
2008-04-17 23:49:27 +05:30
|
|
|
description = _("This tool allows converting absolute media paths "
|
2008-12-11 15:42:40 +05:30
|
|
|
"to a relative path. The relative path is relative "
|
2008-04-17 23:49:27 +05:30
|
|
|
"viz-a-viz the base path as given in the Preferences, "
|
|
|
|
"or if that is not set, user's directory. "
|
|
|
|
"A relative path allows to tie the file location to "
|
|
|
|
"a base path that can change to your needs.")
|
2006-08-19 10:45:44 +05:30
|
|
|
|
|
|
|
def _prepare(self):
|
|
|
|
self.set_total(self.db.get_number_of_media_objects())
|
2009-06-16 21:19:17 +05:30
|
|
|
with self.db.get_media_cursor() as cursor:
|
|
|
|
for handle, data in cursor:
|
|
|
|
obj = MediaObject()
|
|
|
|
obj.unserialize(data)
|
|
|
|
if os.path.isabs(obj.path):
|
|
|
|
self.handle_list.append(handle)
|
|
|
|
self.path_list.append(obj.path)
|
|
|
|
self.update()
|
2006-08-19 10:45:44 +05:30
|
|
|
self.reset()
|
|
|
|
|
|
|
|
def _run(self):
|
|
|
|
if not self.prepared:
|
|
|
|
self.prepare()
|
|
|
|
self.set_total(len(self.handle_list))
|
2008-02-12 03:57:24 +05:30
|
|
|
base_dir = media_path(self.db)
|
2006-08-19 10:45:44 +05:30
|
|
|
for handle in self.handle_list:
|
|
|
|
obj = self.db.get_object_from_handle(handle)
|
2008-02-12 03:57:24 +05:30
|
|
|
new_path = relative_path(obj.path, base_dir)
|
2006-08-19 10:45:44 +05:30
|
|
|
obj.set_path(new_path)
|
|
|
|
self.db.commit_media_object(obj,self.trans)
|
|
|
|
self.update()
|
|
|
|
return True
|
|
|
|
|
2006-08-18 03:58:18 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class MediaManOptions(Tool.ToolOptions):
|
|
|
|
"""
|
|
|
|
Defines options and provides handling interface.
|
|
|
|
"""
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def __init__(self, name,person_id=None):
|
|
|
|
Tool.ToolOptions.__init__(self, name,person_id)
|