diff --git a/bin/Makefile.am b/bin/Makefile.am index 8cc87b5..b0be3d9 100644 --- a/bin/Makefile.am +++ b/bin/Makefile.am @@ -7,7 +7,8 @@ python_scripts = \ sugar-session \ sugar-ui-check \ journal-backup-volume \ - journal-restore-volume + journal-restore-volume \ + journal-reindex bin_SCRIPTS = \ sugar \ diff --git a/bin/journal-reindex b/bin/journal-reindex new file mode 100644 index 0000000..29e64ff --- /dev/null +++ b/bin/journal-reindex @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# Copyright (C) 2010, Plan Ceibal +# +# 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 3 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, see . +# + +import os +import subprocess +from gettext import gettext as _ +from sugar import env +import logging + +logging.debug('Reindex started') + +reindex_file = os.path.join(env.get_profile_path(), 'datastore/index_updated') + +subprocess.call(['pkill', '-9', '-f', 'python.*datastore-service']) + +if os.path.exists(reindex_file): + result = 0 + try: + os.remove(reindex_file) + except Exception, e: + logging.error(_('Reindex failed: %s'), str(e)) + result = 1 + +logging.debug('Reindex finished') +exit(result) diff --git a/src/jarabe/journal/processdialog.py b/src/jarabe/journal/processdialog.py index 181174d..f5f9c5d 100644 --- a/src/jarabe/journal/processdialog.py +++ b/src/jarabe/journal/processdialog.py @@ -293,3 +293,22 @@ class XSRestoreDialog(ProcessDialog): def _check_prerequisites(self): return len(shell.get_model()) <= 1 + +class ReindexDialog(ProcessDialog): + def __init__(self): + ProcessDialog.__init__(self, 'journal-reindex') + self._resetup_information() + + def _resetup_information(self): + self._start_message = '%s.' % (_('Please wait, repair journal content')) + + self._finished_message = _('The journal content has been reindexed.') + + self._title.set_markup('%s' % _('Repair')) + + self._message.set_text('%s.' % (_('Journal content will be repaired'))) + + self._prerequisite_message = _(', please close all the running activities.') + + def _check_prerequisites(self): + return len(shell.get_model()) <= 1 diff --git a/src/jarabe/view/palettes.py b/src/jarabe/view/palettes.py index f6e5456..95c41a8 100644 --- a/src/jarabe/view/palettes.py +++ b/src/jarabe/view/palettes.py @@ -33,7 +33,7 @@ from sugar.graphics.xocolor import XoColor from sugar.activity import activityfactory from sugar.activity.activityhandle import ActivityHandle -from jarabe.journal.processdialog import VolumeBackupDialog, VolumeRestoreDialog, XSBackupDialog, XSRestoreDialog +from jarabe.journal.processdialog import VolumeBackupDialog, VolumeRestoreDialog, XSBackupDialog, XSRestoreDialog, ReindexDialog from jarabe.model import shell from jarabe.view import launcher from jarabe.view.viewsource import setup_view_source @@ -188,6 +188,22 @@ class JournalPalette(BasePalette): self.menu.append(menu_item) menu_item.show() + menu_item_reindex = MenuItem(_('Repair')) + + icon_reindex = Icon(icon_name='journal-reindex', + icon_size=gtk.ICON_SIZE_MENU) + menu_item_reindex.set_image(icon_reindex) + icon_reindex.show() + + menu_item_reindex.connect('activate', self.__reindex_activate_cb) + self.menu.append(menu_item_reindex) + menu_item_reindex.show() + + def __reindex_activate_cb(self, menu_item): + dialog = ReindexDialog() + dialog.show() + + def __open_activate_cb(self, menu_item): self._home_activity.get_window().activate(gtk.get_current_event_time())