Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def repo_unlink_action(self):
profile = self.profile()
self.init_repo_stats()
msg = QMessageBox()
msg.setStandardButtons(QMessageBox.Ok)
msg.setParent(self, QtCore.Qt.Sheet)
selected_repo_id = self.repoSelector.currentData()
selected_repo_index = self.repoSelector.currentIndex()
if selected_repo_index > 2:
repo = RepoModel.get(id=selected_repo_id)
ArchiveModel.delete().where(ArchiveModel.repo_id == repo.id).execute()
profile.repo = None
profile.save()
repo.delete_instance(recursive=True) # This also deletes archives.
self.repoSelector.setCurrentIndex(0)
self.repoSelector.removeItem(selected_repo_index)
msg.setText(self.tr('Repository was Unlinked'))
msg.setInformativeText(self.tr('You can always connect it again later.'))
msg.exec_()
self.repo_changed.emit()
self.init_repo_stats()
def populate_from_profile(self):
"""Populate archive list and prune settings from profile."""
profile = self.profile()
if profile.repo is not None:
self.mount_points = get_mount_points(profile.repo.url)
self.toolBox.setItemText(0, self.tr('Archives for %s') % profile.repo.url)
archives = [s for s in profile.repo.archives.select().order_by(ArchiveModel.time.desc())]
for row, archive in enumerate(archives):
self.archiveTable.insertRow(row)
formatted_time = archive.time.strftime('%Y-%m-%d %H:%M')
self.archiveTable.setItem(row, 0, QTableWidgetItem(formatted_time))
self.archiveTable.setItem(row, 1, QTableWidgetItem(pretty_bytes(archive.size)))
if archive.duration is not None:
formatted_duration = str(timedelta(seconds=round(archive.duration)))
else:
formatted_duration = ''
self.archiveTable.setItem(row, 2, QTableWidgetItem(formatted_duration))
mount_point = self.mount_points.get(archive.name)
if mount_point is not None:
def list_archive_result(self, result):
self._set_status('')
if result['returncode'] == 0:
archive = ArchiveModel.get(name=result['params']['archive_name'])
window = ExtractDialog(result['data'], archive)
self._toggle_all_buttons(True)
window.setParent(self, QtCore.Qt.Sheet)
self._window = window # for testing
window.show()
if window.exec_():
def receive():
extraction_folder = dialog.selectedFiles()
if extraction_folder:
params = BorgExtractThread.prepare(
self.profile(), archive.name, window.selected, extraction_folder[0])
if params['ok']:
self._toggle_all_buttons(False)
thread = BorgExtractThread(params['cmd'], params, parent=self)
thread.updated.connect(self.mountErrors.setText)
def process_result(self, result):
if result['returncode'] in [0, 1] and 'archive' in result['data']:
new_archive, created = ArchiveModel.get_or_create(
snapshot_id=result['data']['archive']['id'],
defaults={
'name': result['data']['archive']['name'],
'time': parser.parse(result['data']['archive']['start']),
'repo': result['params']['repo_id'],
'duration': result['data']['archive']['duration'],
'size': result['data']['archive']['stats']['deduplicated_size']
}
)
new_archive.save()
if 'cache' in result['data'] and created:
stats = result['data']['cache']['stats']
repo = RepoModel.get(id=result['params']['repo_id'])
repo.total_size = stats['total_size']
repo.unique_csize = stats['unique_csize']
repo.unique_size = stats['unique_size']