2018-10-29 05:12:45 +00:00
|
|
|
from PyQt5 import uic
|
2018-10-27 17:24:34 +00:00
|
|
|
from PyQt5.QtWidgets import QFileDialog, QTableWidgetItem, QTableView, QHeaderView
|
|
|
|
|
2018-10-29 05:12:45 +00:00
|
|
|
from ..borg_runner import BorgThread
|
2018-11-01 07:02:56 +00:00
|
|
|
from ..utils import get_asset, keyring
|
2018-10-31 16:09:01 +00:00
|
|
|
from ..models import BackupProfileMixin
|
2018-10-27 17:24:34 +00:00
|
|
|
|
2018-10-29 05:49:25 +00:00
|
|
|
uifile = get_asset('UI/snapshottab.ui')
|
2018-10-27 17:24:34 +00:00
|
|
|
SnapshotUI, SnapshotBase = uic.loadUiType(uifile)
|
|
|
|
|
|
|
|
|
2018-10-31 16:09:01 +00:00
|
|
|
class SnapshotTab(SnapshotBase, SnapshotUI, BackupProfileMixin):
|
2018-10-27 17:24:34 +00:00
|
|
|
def __init__(self, parent=None):
|
|
|
|
super().__init__(parent)
|
|
|
|
self.setupUi(parent)
|
|
|
|
|
|
|
|
header = self.snapshotTable.horizontalHeader()
|
|
|
|
header.setVisible(True)
|
|
|
|
header.setSectionResizeMode(0, QHeaderView.Stretch)
|
|
|
|
header.setSectionResizeMode(1, QHeaderView.ResizeToContents)
|
|
|
|
|
|
|
|
self.snapshotTable.setSelectionBehavior(QTableView.SelectRows)
|
|
|
|
self.snapshotTable.setEditTriggers(QTableView.NoEditTriggers)
|
|
|
|
|
|
|
|
self.snapshotMountButton.clicked.connect(self.snapshot_mount)
|
|
|
|
self.snapshotDeleteButton.clicked.connect(self.snapshot_mount)
|
|
|
|
self.snapshotRefreshButton.clicked.connect(self.snapshot_mount)
|
|
|
|
|
|
|
|
self.populate()
|
|
|
|
|
2018-10-28 15:40:38 +00:00
|
|
|
def set_status(self, text):
|
|
|
|
self.mountErrors.setText(text)
|
|
|
|
self.mountErrors.repaint()
|
|
|
|
|
2018-10-27 17:24:34 +00:00
|
|
|
def populate(self):
|
|
|
|
if self.profile.repo:
|
|
|
|
snapshots = [s for s in self.profile.repo.snapshots.select()]
|
|
|
|
|
|
|
|
for row, snapshot in enumerate(snapshots):
|
|
|
|
self.snapshotTable.insertRow(row)
|
|
|
|
self.snapshotTable.setItem(row, 0, QTableWidgetItem(snapshot.name))
|
|
|
|
formatted_time = snapshot.time.strftime('%Y-%m-%d %H:%M')
|
|
|
|
self.snapshotTable.setItem(row, 1, QTableWidgetItem(formatted_time))
|
|
|
|
self.snapshotTable.setRowCount(len(snapshots))
|
|
|
|
|
|
|
|
def snapshot_mount(self):
|
2018-10-31 16:09:01 +00:00
|
|
|
profile = self.profile
|
2018-10-27 17:24:34 +00:00
|
|
|
cmd = ['borg', 'mount', '--log-json']
|
|
|
|
row_selected = self.snapshotTable.selectionModel().selectedRows()
|
|
|
|
if row_selected:
|
|
|
|
snapshot_cell = self.snapshotTable.item(row_selected[0].row(), 0)
|
|
|
|
if snapshot_cell:
|
|
|
|
snapshot_name = snapshot_cell.text()
|
2018-10-31 16:09:01 +00:00
|
|
|
cmd.append(f'{profile.repo.url}::{snapshot_name}')
|
2018-10-27 17:24:34 +00:00
|
|
|
else:
|
2018-10-31 16:09:01 +00:00
|
|
|
cmd.append(f'{profile.repo.url}')
|
2018-10-27 17:24:34 +00:00
|
|
|
else:
|
2018-10-31 16:09:01 +00:00
|
|
|
cmd.append(f'{profile.repo.url}')
|
2018-10-27 17:24:34 +00:00
|
|
|
|
|
|
|
options = QFileDialog.Options()
|
|
|
|
options |= QFileDialog.ShowDirsOnly
|
|
|
|
options |= QFileDialog.DontUseNativeDialog
|
|
|
|
mountPoint = QFileDialog.getExistingDirectory(
|
|
|
|
self, "Choose Mount Point", "", options=options)
|
|
|
|
if mountPoint:
|
|
|
|
cmd.append(mountPoint)
|
|
|
|
|
2018-10-28 15:40:38 +00:00
|
|
|
self.set_status('Mounting snapshot into folder...')
|
2018-10-31 16:09:01 +00:00
|
|
|
params = {'password': keyring.get_password("vorta-repo", profile.repo.url)}
|
|
|
|
thread = BorgThread(self, cmd, params, parent=self)
|
2018-10-27 17:24:34 +00:00
|
|
|
thread.updated.connect(self.mount_update_log)
|
|
|
|
thread.result.connect(self.mount_get_result)
|
|
|
|
thread.start()
|
|
|
|
|
|
|
|
def mount_update_log(self, text):
|
|
|
|
self.mountErrors.setText(text)
|
|
|
|
|
|
|
|
def mount_get_result(self, result):
|
|
|
|
if result['returncode'] == 0:
|
|
|
|
self.set_status('Mounted successfully.')
|