/usr/share/backintime/qt4/restoredialog.py is in backintime-qt4 1.1.12-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | # Back In Time
# Copyright (C) 2008-2016 Oprea Dan, Bart de Koning, Richard Bailey, Germar Reitze
#
# 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.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import os
import gettext
import tools
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import qt4tools
_=gettext.gettext
def restore( parent, snapshot_id, what, where = '', **kwargs ):
if where is None:
where = qt4tools.getExistingDirectory( parent, _('Restore to ...') )
if not where:
return
where = parent.config.prepare_path( where )
rd = RestoreDialog(parent, snapshot_id, what, where, **kwargs)
rd.exec()
class RestoreDialog( QDialog ):
def __init__( self, parent, snapshot_id, what, where = '', **kwargs ):
super(RestoreDialog, self).__init__(parent)
self.resize( 600, 500 )
self.config = parent.config
self.current_profile = self.config.get_current_profile()
self.snapshots = parent.snapshots
self.snapshot_id = snapshot_id
self.what = what
self.where = where
self.kwargs = kwargs
import icon
self.log_file = self.config.get_restore_log_file()
if os.path.exists(self.log_file):
os.remove(self.log_file)
self.setWindowIcon(icon.RESTORE_DIALOG)
self.setWindowTitle( _( 'Restore' ) )
self.main_layout = QVBoxLayout(self)
#text view
self.txt_log_view = QPlainTextEdit(self)
self.txt_log_view.setReadOnly(True)
self.txt_log_view.setLineWrapMode(QPlainTextEdit.NoWrap)
self.txt_log_view.setMaximumBlockCount(100000)
self.main_layout.addWidget(self.txt_log_view)
#buttons
button_box = QDialogButtonBox(QDialogButtonBox.Close)
showLog = button_box.addButton(_('Show full Log'), QDialogButtonBox.ActionRole)
self.main_layout.addWidget(button_box)
self.btn_close = button_box.button(QDialogButtonBox.Close)
self.btn_close.setEnabled(False)
button_box.rejected.connect(self.close)
showLog.clicked.connect(lambda: QDesktopServices.openUrl(QUrl(self.log_file)))
#restore in separate thread
self.thread = RestoreThread(self)
self.thread.finished.connect(self.threadFinished)
#refresh log every 200ms
self.refreshTimer = QTimer(self)
self.refreshTimer.setInterval(200)
self.refreshTimer.setSingleShot(False)
self.refreshTimer.timeout.connect(self.refreshLog)
def refreshLog(self):
"""get new log from thread
"""
newLog = self.thread.buffer[:]
size = len(newLog)
if size:
self.thread.mutex.lock()
self.thread.buffer = self.thread.buffer[size:]
self.thread.mutex.unlock()
self.txt_log_view.appendPlainText(newLog.rstrip('\n'))
def exec(self):
#inhibit suspend/hibernate during restore
self.config.inhibitCookie = tools.inhibitSuspend(toplevel_xid = self.config.xWindowId, reason = 'restoring')
self.show()
self.refreshTimer.start()
self.thread.start()
super(RestoreDialog, self).exec()
self.refreshTimer.stop()
self.thread.wait()
def threadFinished(self):
self.btn_close.setEnabled(True)
#release inhibit suspend
if self.config.inhibitCookie:
self.config.inhibitCookie = tools.unInhibitSuspend(*self.config.inhibitCookie)
class RestoreThread(QThread):
"""run restore in a separate Thread to prevent GUI freeze and speed up restore
"""
def __init__(self, parent):
super(RestoreThread, self).__init__()
self.parent = parent
self.log = open(parent.log_file, 'wt')
self.mutex = QMutex()
self.buffer = ''
def run(self):
self.parent.snapshots.restore(self.parent.snapshot_id, self.parent.what, self.callback, self.parent.where, **self.parent.kwargs)
self.log.close()
def callback(self, line, *args):
"""write into log file and provide thread save string for log window
"""
line += '\n'
self.log.write(line)
self.mutex.lock()
self.buffer += line
self.mutex.unlock()
|