vorta/src/vorta/application.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

357 lines
14 KiB
Python
Raw Permalink Normal View History

import logging
import os
import sys
from pathlib import Path
from typing import Any, Dict, List, Tuple
from PyQt6 import QtCore
from PyQt6.QtWidgets import QMessageBox
from vorta import config
from vorta.borg.break_lock import BorgBreakJob
from vorta.borg.create import BorgCreateJob
from vorta.borg.jobs_manager import JobsManager
from vorta.borg.version import BorgVersionJob
from vorta.i18n import init_translations, translate
from vorta.notifications import VortaNotifications
from vorta.profile_export import ProfileExport
from vorta.qt_single_application import QtSingleApplication
from vorta.scheduler import VortaScheduler
from vorta.store.connection import cleanup_db
from vorta.store.models import BackupProfileModel, SettingsModel
from vorta.tray_menu import TrayMenu
from vorta.utils import borg_compat, parse_args
from vorta.views.main_window import MainWindow
2018-10-31 11:14:12 +00:00
logger = logging.getLogger(__name__)
APP_ID = config.TEMP_DIR / "socket"
2018-10-31 11:14:12 +00:00
class VortaApp(QtSingleApplication):
"""
All windows and QWidgets are children of this app.
When running Borg-commands, the class `BorgJob` will emit events
via the `VortaApp` class to which other windows will subscribe to.
"""
backup_started_event = QtCore.pyqtSignal()
backup_finished_event = QtCore.pyqtSignal(dict)
backup_cancelled_event = QtCore.pyqtSignal()
backup_log_event = QtCore.pyqtSignal(str, dict)
backup_progress_event = QtCore.pyqtSignal(str)
check_failed_event = QtCore.pyqtSignal(dict)
def __init__(self, args_raw, single_app=False):
super().__init__(str(APP_ID), args_raw)
args = parse_args()
if self.isRunning():
if single_app:
self.sendMessage("open main window")
logger.info('An instance of Vorta is already running. Opening main window.')
sys.exit()
elif args.profile:
self.sendMessage(f"create {args.profile}")
logger.info('Creating backup using existing Vorta instance.')
sys.exit()
elif args.profile:
sys.exit('Vorta must already be running for --create to work')
init_translations(self)
2018-10-31 11:14:12 +00:00
self.setQuitOnLastWindowClosed(False)
self.jobs_manager = JobsManager()
self.scheduler = VortaScheduler()
2020-09-22 03:15:07 +00:00
self.setApplicationName("Vorta")
2018-10-31 11:14:12 +00:00
# Import profile from ~/.vorta-init.json or add empty "Default" profile.
self.bootstrap_profile()
# Prepare tray and main window
2018-10-31 11:14:12 +00:00
self.tray = TrayMenu(self)
self.main_window = MainWindow(self)
if getattr(args, 'daemonize', False):
pass
elif SettingsModel.get(key='foreground').value:
self.open_main_window_action()
2018-10-31 11:14:12 +00:00
self.backup_started_event.connect(self.backup_started_event_response)
self.backup_finished_event.connect(self.backup_finished_event_response)
self.backup_cancelled_event.connect(self.backup_cancelled_event_response)
self.message_received_event.connect(self.message_received_event_response)
2021-11-17 09:29:22 +00:00
self.check_failed_event.connect(self.check_failed_response)
self.backup_log_event.connect(self.react_to_log)
self.aboutToQuit.connect(self.quit_app_action)
self.set_borg_details_action()
if sys.platform == 'darwin':
self.check_darwin_permissions()
def create_backups_cmdline(self, profile_name):
profile = BackupProfileModel.get_or_none(name=profile_name)
if profile is not None:
if profile.repo is None:
logger.warning(f"Add a repository to {profile_name}")
2021-10-28 11:02:09 +00:00
self.create_backup_action(profile_id=profile.id)
else:
logger.warning(f"Invalid profile name {profile_name}")
def quit_app_action(self):
self.backup_cancelled_event.emit()
del self.main_window
self.tray.deleteLater()
del self.tray
cleanup_db()
def create_backup_action(self, profile_id=None):
if not profile_id:
profile_id = self.main_window.current_profile.id
profile = BackupProfileModel.get(id=profile_id)
msg = BorgCreateJob.prepare(profile)
if msg['ok']:
job = BorgCreateJob(msg['cmd'], msg, profile.repo.id)
self.jobs_manager.add_job(job)
2018-11-02 11:14:54 +00:00
else:
notifier = VortaNotifications.pick()
notifier.deliver(
self.tr('Vorta Backup'),
translate('messages', msg['message']),
level='error',
)
self.backup_progress_event.emit(f"[{profile.name}] {translate('messages', msg['message'])}")
return None
2018-10-31 11:14:12 +00:00
def open_main_window_action(self):
2018-10-31 11:14:12 +00:00
self.main_window.show()
self.main_window.raise_()
self.main_window.activateWindow()
def toggle_main_window_visibility(self):
if self.main_window.isVisible():
2019-03-25 15:14:04 +00:00
self.main_window.close()
else:
self.open_main_window_action()
def backup_started_event_response(self):
self.tray.set_tray_icon(active=True)
2018-10-31 12:42:11 +00:00
def backup_finished_event_response(self):
if not self.jobs_manager.is_worker_running():
self.tray.set_tray_icon()
def backup_cancelled_event_response(self):
self.jobs_manager.cancel_all_jobs()
self.tray.set_tray_icon()
def message_received_event_response(self, message):
if message == "open main window":
self.open_main_window_action()
elif message.startswith("create"):
message = message[7:] # Remove create
if self.jobs_manager.is_worker_running():
logger.warning("Cannot run while backups are already running")
else:
self.create_backups_cmdline(message)
# No need to add this function to JobsManager because it doesn't require to lock a repo.
def set_borg_details_action(self):
params = BorgVersionJob.prepare()
if not params['ok']:
self._alert_missing_borg()
return
job = BorgVersionJob(params['cmd'], params)
job.result.connect(self.set_borg_details_result)
self.jobs_manager.add_job(job)
def set_borg_details_result(self, result):
"""
Receive result from BorgVersionJob.
If no valid version was found, display an error.
"""
if 'version' in result['data']:
borg_compat.set_version(result['data']['version'], result['data']['path'])
self.main_window.aboutTab.set_borg_details(borg_compat.version, borg_compat.path)
self.main_window.repoTab.toggle_available_compression()
self.main_window.archiveTab.toggle_compact_button_visibility()
self.scheduler.reload_all_timers() # Start timer after Borg version is set.
else:
self._alert_missing_borg()
def _alert_missing_borg(self):
msg = QMessageBox()
msg.setIcon(QMessageBox.Icon.Critical)
msg.setText(self.tr("No Borg Binary Found"))
msg.setInformativeText(self.tr("Vorta was unable to locate a usable Borg Backup binary."))
msg.setStandardButtons(QMessageBox.StandardButton.Ok)
msg.exec()
def check_darwin_permissions(self):
"""
macOS restricts access to certain folders by default. For some folders, the user
will get a prompt (e.g. Documents, Downloads), while others will cause file access
errors.
This function tries reading a file that is known to be restricted and warn the user about
incomplete backups.
"""
if not SettingsModel.get(key="check_full_disk_access").value:
return
test_path = Path('~/Library/Cookies').expanduser()
if test_path.exists() and not os.access(test_path, os.R_OK):
msg = QMessageBox()
msg.setIcon(QMessageBox.Icon.Warning)
msg.setTextInteractionFlags(QtCore.Qt.TextInteractionFlag.LinksAccessibleByMouse)
msg.setText(self.tr("Vorta needs Full Disk Access for complete Backups"))
msg.setInformativeText(
self.tr(
Improve UX and HIG-conformity. By @real-yfprojects (#1176) * Remove fullstops in the labels of the settings. * src/vorta/store/settings.py (get_misc_setting): Remove fullstops in the `label` fields of each setting. * Fix *Add Profile*-Dialog. * src/vorta/assets/UI/profileadd.ui (label_2): Rename to `profileExplainer`. * src/vorta/assets/UI/profileadd.ui (profileExplainer): Remove unnecessary text and rephrase it in simpler terms. * src/vorta/assets/UI/profileadd.ui (formLayout): Move into frame for better layout in dialog. * src/vorta/assets/UI/profileadd.ui (Dialog): Make dialog modal. * src/vorta/assets/UI/profileadd.ui : Modify spacing a bit and change all widgets to `expanding` mode. * src/vorta/assets/UI/profileadd.ui (Dialog): Set title to `Add Profile`. * src/vorta/assets/UI/profileadd.ui : Make `label_3` a buddy of `profileNameField`. * Add colon after entry label in `Add Profile`-Dialog. * src/vorta/assets/UI/profileadd.ui (label_3): Add colon at the end of label. * Fix capitalization in schedule tab. * src/vorta/assets/UI/scheduletab.ui (pruneCheckBox): Replace `Archive` by `archive`. * Fix tooltips. Ensure sentence capitalization. Rephrase some tooltips that do not mention the action they provide a tip for. (There are still many to go.) Remove fullstop from tooltips that aren't a sentence. Add fullstop to tooltips that are a sentence. * src/vorta/assets/UI/archivetab.ui * src/vorta/assets/UI/mainwindow.ui * src/vorta/assets/UI/repoadd.ui * src/vorta/assets/UI/repotab.ui * src/vorta/assets/UI/sourcetab.ui * src/vorta/views/export_window.py * src/vorta/views/import_window.py * src/vorta/views/source_tab.py * Replace `n't` by `not` in GUI strings. * src/vorta/application.py * src/vorta/assets/UI/repotab.ui * src/vorta/assets/UI/scheduletab.ui * src/vorta/assets/UI/sshadd.ui * src/vorta/notifications.py * src/vorta/views/main_window.py * src/vorta/views/main_window.py * src/vorta/views/repo_tab.py * Shorten unlink button tooltip. * src/vorta/assets/UI/repotab.ui (repoRemoveToolbutton): Shorten tooltip by only keeping the most valuable information needed to understand the feature. * Fix entry being embedded in label text. Sentences should not be constructed from text in several controls. Sentences that run from one control to another will often not make sense when translated into other languages. * src/vorta/assets/UI/archivetab.ui * src/vorta/assets/UI/scheduletab.ui * Rewrite tooltips to make them HIG conform. The KDE HIG was used. * src/vorta/assets/UI/exportwindow.ui * src/vorta/assets/UI/importwindow.ui * src/vorta/assets/UI/mainwindow.ui * src/vorta/assets/UI/repoadd.ui * src/vorta/assets/UI/repotab.ui * src/vorta/assets/UI/sourcetab.ui * src/vorta/views/export_window.py * src/vorta/views/import_window.py (ImportWindow.init_overwrite_profile_checkbox): Make tooltip static as the HIG suggests. * src/vorta/views/main_window.py * Replace `...` with unicode ellipses `…` (U+2028) in GUI text. * src/vorta/borg/break_lock.py * src/vorta/borg/check.py * src/vorta/borg/create.py * src/vorta/borg/delete.py * src/vorta/borg/diff.py * src/vorta/borg/extract.py * src/vorta/borg/info_archive.py * src/vorta/borg/info_repo.py * src/vorta/borg/init.py * src/vorta/borg/list_archive.py * src/vorta/borg/list_archive.py * src/vorta/borg/list_repo.py * Clean prune tab in `archivetab.ui`. * src/vorta/assets/UI/archivetab.ui * Prettify `repotab`. * src/vorta/assets/UI/repotab.ui * Fix tooltips for pruning in `archivetab.ui`. * src/vorta/assets/UI/archivetab.ui * Use affirmative phrase in checkbox for metered networks. * src/vorta/assets/UI/scheduletab.ui (dontRunOnMeteredNetworksCheckbox): Rename to `meteredNetworksCheckBox`. * src/vorta/assets/UI/scheduletab.ui (meteredNetworksCheckBox): Change text into affirmative phrase. * src/vorta/views/schedule_tab.py : Invert values for `meteredNetworksCheckBox`. * Add label in shell commands pane in `scheduletab` and fix placeholders. Placeholders shouldn't be a replacement for a label. * src/vorta/assets/UI/scheduletab.ui * Group settings widgets in `misctab`. * src/vorta/assets/UI/misctab.ui (checkboxLayout): Replace with frame `frameSettings` containing a form layout. * src/vorta/utils.py (search): Added. Searches for a key inside an iterable applying a given function before comparison. * src/vorta/store/models.py (SettingsModel): Add field `group` to assign settings to a group. * src/vorta/store/migrations.py (run_migrations): Add new schema version `19` and implement migration adding the `group` field. * src/vorta/store/connection.py (SCHEMA_VERSION): Update to `19`. * src/vorta/store/settings.py (get_misc_settings): Add and assign settings groups. * src/vorta/store/connection.py (init_db): Update group and type of settings if needed. * src/vorta/views/misc_tab.py (Imports): Import `search` from `..utils`. * src/vorta/views/misc_tab.py : Instanciate logger. * src/vorta/views/misc_tab.py (MiscTab.__init__): Create a checkboxLayout for `frameSettings`. * src/vorta/views/misc_tab.py (populate): Add settings widgets in groups with labels in spacer in between. * Fix tests for `misctab`. * tests/test_misc.py * Fix margins. * src/vorta/assets/UI/archivetab.ui * src/vorta/assets/UI/misctab.ui * src/vorta/assets/UI/repotab.ui * src/vorta/assets/UI/scheduletab.ui * src/vorta/assets/UI/sourcetab.ui * Morph buttons in `sourcetab` into toolbuttons with icons. Adds gradient buttons along the way. Fixes #933. * src/vorta/assets/UI/sourcetab.ui : Change layout and buttons. Merge buttons with adding capabilities into one toolbutton (with menu). * src/vorta/assets/UI/sourcetab.ui : Rename `sourceRemove` to `removeButton`. Rename `sourceUpdate` to `updateButton`. Add `addButton`. * src/vorta/assets/icons/minus.svg : Add minus sign icon from *fontawesome* v6.0. * src/vorta/views/source_tab.py (SourceTab.set_icons): Added. * src/vorta/views/source_tab.py (SourceTab.__init__): Create Menu for the `addButton` with actions to add files and folders and to paste. * src/vorta/application.py (VortaApp.eventFilter): Call `set_icons` of `sourceTab` as well. * Fix tests for `sourcetab`. * tests/test_source.py * Add paste icon to paste action in `sourcetab`. * src/vorta/assets/icons/paste.svg : Added from fontawesome (paste-solid, v6.0) * src/vorta/views/source_tab.py (SourceTab.__init__): Save paste action in `pasteAction`. * src/vorta/views/source_tab.py (SourceTab.set_icons): Set icon for `pasteAction`. * Add icons to open actions in `sourcetab`. * src/vorta/assets/icons/file.svg : Added `file-solid` from fontawesome, v6.0 * src/vorta/assets/icons/folder.svg : Added `folder-solid` from fontawesome, v6.0 * src/vorta/views/source_tab.py (SourceTab.__init__): Save files and folders action to `addFilesAction` and `addFoldersAction`. * src/vorta/views/source_tab.py (SourceTab.set_icons): Set icons for `addFilesAction` and `addFolderAction`. * Fix icon size of `file.svg`. * src/vorta/assets/icons/file.svg * Set fill of added svgs to `#000000`. * src/vorta/assets/icons/file.svg * src/vorta/assets/icons/folder.svg * src/vorta/assets/icons/minus.svg * src/vorta/assets/icons/paste.svg * Improve UX and consistency within the app for `scheduletab`. * src/vorta/assets/UI/scheduletab.ui : Arrange schedule pane in a form layout. * src/vorta/views/schedule_tab.py (ScheduleTab.__init__): Connect enabled state of entries to radiobuttons and checkboxes. * Workaround scheduletab tests being broken in github actions. For some unknown reason clicking the `scheduleFixedRadio` won't work when running using github action on ubuntu. * tests/test_schedule.py * Fix labels and spacing in `scheduletab`. * src/vorta/assets/UI/scheduletab.ui * Make archive operations more accessible and rename actions of `ArchiveTab`. * src/vorta/views/archive_tab.py (ArchiveTab): Rename `list_action` to `refresh_archive_list`. Rename `refresh_archive_action` to `refresh_archive_info`. Rename `refresh_archive_result` to `info_result`. Rename `list_archive_action` to `extract_action`. Rename `list_archive_result` to `extract_list_result`. * src/vorta/views/main_window.py : Apply renaming. * src/vorta/assets/UI/archivetab.ui : Create own buttons for the archive actions. Remove `archiveActionButton`. And some other layout changes. * src/vorta/assets/UI/archivetab.ui : Rename `pruneButton` to `bPrune`. Rename `checkButton` to `bCheck`. Rename `diffButton` to `bDiff`. Rename `listButton` to `bList`. * tests/test_archives.py : Apply renaming. * src/vorta/views/archive_tab.py : Connect new action buttons. * src/vorta/views/archive_tab.py : Remove `archiveActionButton`. * tests/test_archives.py : Fix tests. * Enable and disable archive actions depending on selection. * src/vorta/assets/UI/archivetab.ui : Put archive actions into a frame. * src/vorta/views/archive_tab.py (ArchiveTab): Added `on_selection_change` that enables/disables the frame depending on the selection count. * src/vorta/views/archive_tab.py (ArchiveTab.populate_from_profile): Clear selection. * src/vorta/views/archive_tab.py (ArchiveTab.__toggle_all_buttons): Add `fArchiveActions`. Call `on_selection_change` at the end. * Fix tests for `archivetab`. * tests/test_archives.py * Replace line by spacer in repotab. * src/vorta/assets/UI/repotab.ui * Show labels for archive action buttons. * src/vorta/assets/UI/archivetab.ui * Add tooltips and ellipses to archivetab. * src/vorta/assets/UI/archivetab.ui * src/vorta/views/archive_tab.py * Fix tooltips. * src/vorta/assets/UI/sourcetab.ui : Add tooltips. * src/vorta/views/archive_tab.py (ArchiveTab.on_selection_change): Add reason for disabled state dynamically to archive action buttons. * Add context menu to source view. * src/vorta/views/source_tab.py (SourceTab): Implement `sourceitem_contextmenu` and `source_copy`. Set context menu policiy of `sourceFilesWidget` to `CustomContextMenu`. * src/vorta/assets/UI/sourcetab.ui: Change size hints. * Add context menu to archive view. * src/vorta/views/archive_tab.py (ArchiveTab): Set context menu policy of `archiveTable` to `CustomContextMenu`. Implement `archiveitem_contextmenu`. * Replace `Type` column in sources view by icon. * src/vorta/views/source_tab.py (SourceColumn): Remove `Type` column. * src/vorta/views/source_tab.py (SourceTab.set_icons): Set icon for each item in source view. * src/vorta/views/source_tab.py (SourceTab.set_path_info): Set icon instead of `Type` column. * src/vorta/assets/UI/sourcetab.ui : Remove `Type` column. * Fix initial sort indicator of source view. * src/vorta/views/source_tab.py * Fix adding items while sorting enabled. * src/vorta/views/source_tab.py * Remove status bar and remove fix size hint for log text label. * src/vorta/assets/UI/mainwindow.ui * src/vorta/views/main_window.py (MainWindow.__init__): Set minimum height of `logText` to two times the height of a line calculated by `QFontMetrics`. * Resize main window height to `670`. * src/vorta/assets/UI/mainwindow.ui * Replace `QToolbutton` by `QPushbutton`. * src/vorta/assets/UI/archivetab.ui * src/vorta/assets/UI/repotab.ui * src/vorta/assets/UI/sourcetab.ui * src/vorta/views/source_tab.py * Fix flake8 * Improve label of entry for `borg create` extra arguments. * src/vorta/assets/UI/scheduletab.ui * Unify label font size in `repotab`. * src/vorta/assets/UI/repotab.ui * Morph `QPushButton`s into `QToolButton`s. Some exceptions were made, especially in the dialog windows. * src/vorta/assets/UI/archivetab.ui * src/vorta/assets/UI/mainwindow.ui * src/vorta/assets/UI/repotab.ui * src/vorta/assets/UI/sourcetab.ui * Add copy capabilities to archive view and a copy shortcut to it and to source tab. * src/vorta/views/source_tab.py (SourceTab): Add QShortcut for copying. * src/vorta/views/archive_tab.py (ArchiveTab.archiveitem_contextmenu): Add copy action. * src/vorta/views/archive_tab.py (ArchiveTab): Add QShortcut for copying. * Move actions in comboBoxes to buttons. * src/vorta/assets/UI/repotab.ui : Add `bAddSSHKey` and `bAddRepo`. * src/vorta/views/repo_tab.py : Move code out of `ssh_select_action` and `repo_select_action` into `add_existing_repo`, `new_repo` and `create_ssh_key`. * src/vorta/views/repo_tab.py * Make tooltip of `storePassword` checkbox more fluent. * src/vorta/assets/UI/exportwindow.ui * Introduce `QDialogButtonBox` to modal dialogs in vorta. * src/vorta/assets/UI/extractdialog.ui * src/vorta/views/extract_dialog.py * src/vorta/assets/UI/repoadd.ui * src/vorta/views/repo_add_dialog.py * src/vorta/assets/UI/sshadd.ui * src/vorta/views/ssh_dialog.py * Move some options in scheduletab to the side. This results in two columns of options and fixes vertical scrolling. * src/vorta/assets/UI/scheduletab.ui * Changes for macOS layout * Set `sizeAdjustPolicy` of comboBoxes to `AdustToContents`. * src/vorta/assets/UI/mainwindow.ui * src/vorta/assets/UI/repotab.ui * Fix some icons, translations strings and link * Lint Co-authored-by: real-yfprojects <real-yfprojects@users.noreply.github.com> Co-authored-by: Manu <3916435+m3nu@users.noreply.github.com> Co-authored-by: Manu <manu@snapdragon.cc>
2022-03-24 06:27:07 +00:00
"Without this, some files will not be accessible and you may end up with an incomplete "
"backup. Please set <b>Full Disk Access</b> permission for Vorta in "
"<a href='x-apple.systempreferences:com.apple.preference.security?Privacy'>"
"System Preferences > Security & Privacy</a>."
2022-08-15 05:21:14 +00:00
)
)
msg.setStandardButtons(QMessageBox.StandardButton.Ok)
msg.exec()
def react_to_log(self, mgs, context):
"""
Trigger Vorta actions based on Borg logs. E.g. repo lock.
"""
msgid = context.get('msgid')
if msgid == 'LockTimeout':
profile = BackupProfileModel.get(name=context['profile_name'])
repo_url = context.get('repo_url')
msg = QMessageBox()
msg.setWindowTitle(self.tr("Repository In Use"))
msg.setIcon(QMessageBox.Icon.Critical)
abortButton = msg.addButton(self.tr("Abort"), QMessageBox.ButtonRole.RejectRole)
msg.addButton(self.tr("Continue"), QMessageBox.ButtonRole.AcceptRole)
msg.setDefaultButton(abortButton)
msg.setText(self.tr(f"The repository at {repo_url} might be in use elsewhere."))
msg.setInformativeText(
self.tr(
"Only break the lock if you are certain no other Borg process "
"on any machine is accessing the repository. Abort or break the lock?"
)
2022-08-15 05:21:14 +00:00
)
msg.accepted.connect(lambda: self.break_lock(profile))
self._msg = msg
msg.show()
elif msgid == 'LockFailed':
repo_url = context.get('repo_url')
msg = QMessageBox()
msg.setText(
self.tr(
f"You do not have permission to access the repository at {repo_url}. Gain access and try again."
2022-08-15 05:21:14 +00:00
)
) # noqa: E501
msg.setWindowTitle(self.tr("No Repository Permissions"))
self._msg = msg
msg.show()
def break_lock(self, profile):
params = BorgBreakJob.prepare(profile)
if not params['ok']:
self.backup_progress_event.emit(f"[{profile.name}] {params['message']}")
return
job = BorgBreakJob(params['cmd'], params)
self.jobs_manager.add_job(job)
def bootstrap_profile(self, bootstrap_file=None):
# Necessary to dynamically load the variable from config during runtime
# Check out pull request for #1682 for context
bootstrap_file = bootstrap_file or config.PROFILE_BOOTSTRAP_FILE
"""
Make sure there is at least one profile when first starting Vorta.
Will either import a profile placed in ~/.vorta-init.json
or add an empty "Default" profile.
"""
if bootstrap_file.is_file():
try:
profile_export = ProfileExport.from_json(bootstrap_file)
profile = profile_export.to_db(overwrite_profile=True, overwrite_settings=True)
except Exception as exception:
double_newline = os.linesep + os.linesep
QMessageBox.critical(
None,
self.tr('Failed to import profile'),
"{}{}\"{}\"{}{}".format(
self.tr('Failed to import a profile from {}:').format(bootstrap_file),
double_newline,
str(exception),
double_newline,
self.tr('Consider removing or repairing this file to ' 'get rid of this message.'),
),
)
return
bootstrap_file.unlink()
notifier = VortaNotifications.pick()
notifier.deliver(
self.tr('Profile import successful!'),
self.tr('Profile {} imported.').format(profile.name),
level='info',
)
logger.info('Profile {} imported.'.format(profile.name))
if BackupProfileModel.select().count() == 0:
default_profile = BackupProfileModel(name='Default')
default_profile.save()
2021-11-17 09:29:22 +00:00
def check_failed_response(self, result: Dict[str, Any]):
"""
Process the signal that a repo consistency check failed.
Displays a `QMessageBox` with an error message depending on the
return code of the `BorgJob`.
"""
# extract data from the params for the borg job
repo_url = result['params']['repo_url']
returncode = result['returncode']
errors: List[Tuple[int, str]] = result['errors']
error_message = errors[0][1] if errors else ''
# Switch over returncodes
if returncode == 0:
# No fail
logger.warning('VortaApp.check_failed_response was called with returncode 0')
elif returncode == 130:
# Keyboard interrupt
pass
else: # Real error
# Create QMessageBox
msg = QMessageBox()
msg.setIcon(QMessageBox.Icon.Critical) # changed for warning
msg.setStandardButtons(QMessageBox.StandardButton.Ok)
msg.setWindowTitle(self.tr('Repo Check Failed'))
if returncode == 1:
# warning
msg.setIcon(QMessageBox.Icon.Warning)
text = translate(
'VortaApp', 'Borg exited with warning status (rc 1). See the <a href="{0}">logs</a> for details.'
).format(config.LOG_DIR.as_uri())
infotext = error_message
elif returncode > 128:
# 128+N - killed by signal N (e.g. 137 == kill -9)
signal = returncode - 128
text = self.tr('Repository data check for repo was killed by signal %s.') % signal
infotext = self.tr('The process running the check job got a kill signal. Try again.')
else:
# Real error
text = self.tr('Repository data check for repo %s failed. Error code %s') % (
repo_url,
returncode,
)
infotext = error_message + '\n'
infotext += self.tr('Consider repairing or recreating the repository soon to avoid missing data.')
msg.setText(text)
msg.setInformativeText(infotext)
# Display messagebox
msg.exec()