Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Launch Add new repository when Add existing repository fails/is not initialized. #1816

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6abd0f5
added peewee to requirements.d/dev.txt
SAMAD101 Sep 1, 2023
7b80066
removed peewee from requirements: not necessary
SAMAD101 Sep 6, 2023
5f07abd
Merge branch 'borgbase:master' into master
SAMAD101 Sep 6, 2023
b4f2e64
Merge branch 'borgbase:master' into master
SAMAD101 Sep 9, 2023
55ede38
some enhancements to ExistingRepoWindow: to allow creation of a new r…
SAMAD101 Sep 9, 2023
690d837
added qmessagebox for an extra alert
SAMAD101 Sep 12, 2023
e8afe15
added qmessagebox
SAMAD101 Sep 12, 2023
44639da
added differentiation for adding repo via folder and remote, implemen…
SAMAD101 Sep 15, 2023
7023ab6
added differentiation for adding repo via folder and remote, implemen…
SAMAD101 Sep 15, 2023
780082e
shortened
SAMAD101 Sep 19, 2023
92cc9ae
Merge branch 'borgbase:master' into issue1799
SAMAD101 Sep 20, 2023
0ec083e
Merge branch 'borgbase:master' into issue1799
SAMAD101 Sep 29, 2023
b0ec304
Merge branch 'borgbase:master' into issue1799
SAMAD101 Oct 5, 2023
45176f8
Simplify code, make it more modular.
real-yfprojects Oct 6, 2023
f71c8f8
Store full error (log) messages for borg jobs and fix new feature.
real-yfprojects Oct 6, 2023
cff9e3a
Pass is_remote_repo attribute between the dialog.
real-yfprojects Oct 20, 2023
1b57400
Merge branch 'borgbase:master' into issue1799
SAMAD101 Nov 8, 2023
75f276e
Merge branch 'borgbase:master' into issue1799
SAMAD101 Nov 17, 2023
115ec28
Merge branch 'master' into issue1799
m3nu Jan 9, 2024
d332042
Merge branch 'borgbase:master' into issue1799
SAMAD101 Jan 11, 2024
88cb2dc
Merge branch 'borgbase:master' into issue1799
SAMAD101 Feb 22, 2024
41ea359
fix for remote repos
SAMAD101 Feb 25, 2024
978304f
Merge branch 'master' into issue1799
real-yfprojects Apr 1, 2024
49bfe55
Merge branch 'borgbase:master' into issue1799
SAMAD101 Apr 1, 2024
3c3c197
Merge branch 'master' into issue1799
SAMAD101 May 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/vorta/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ def check_failed_response(self, result: Dict[str, Any]):
# 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 ''
errors: List[Tuple[int, dict]] = result['errors']
error_message = errors[0]['message'] if errors else ''

# Switch over returncodes
if returncode == 0:
Expand Down
5 changes: 3 additions & 2 deletions src/vorta/borg/borg_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def read_async(fd):
if stderr:
for line in stderr.split('\n'):
try:
parsed = json.loads(line)
parsed: dict = json.loads(line)

if parsed['type'] == 'log_message':
context = {
Expand All @@ -281,7 +281,8 @@ def read_async(fd):

if level_int >= logging.WARNING:
# Append log to list of error messages
error_messages.append((level_int, parsed["message"]))
parsed['level'] = level_int
error_messages.append(parsed)

elif parsed['type'] == 'file_status':
self.app.backup_log_event.emit(
Expand Down
63 changes: 62 additions & 1 deletion src/vorta/views/repo_add_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
QDialogButtonBox,
QFormLayout,
QLabel,
QMessageBox,
QSizePolicy,
)

Expand Down Expand Up @@ -124,11 +125,28 @@ def values(self):
repo_name=self.repoName.text(),
password=self.passwordInput.get_password(),
extra_borg_arguments=self.extraBorgArgumentsLineEdit.text(),
is_remote_repo=self.is_remote_repo,
)
return out

@classmethod
def from_values(cls, values: dict):
"""Instantiate window from a values dict as returned by values property."""
window = cls()
window.sshComboBox.setCurrentIndex(window.sshComboBox.findData(values['ssh_key']))
window.repoURL.setText(values['repo_url'])
window.repoName.setText(values['repo_name'])
window.passwordInput.passwordLineEdit.setText(values['password'])
# do not set confirmLineEdit, let user confirm password
window._set_status("Autofilled password from previous window.")
window.extraBorgArgumentsLineEdit.setText(values['extra_borg_arguments'])
window.is_remote_repo = values['is_remote_repo']
return window


class AddRepoWindow(RepoWindow):
"""Dialog for initializing a new repository and adding it."""

def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("Add New Repository")
Expand Down Expand Up @@ -163,6 +181,14 @@ def values(self):
out['encryption'] = self.encryptionComboBox.currentData()
return out

@classmethod
def from_values(cls, values: dict):
"""Instantiate window from a values dict as returned by values property."""
window = super().from_values(values)
if 'encryption' in values:
window.encryptionComboBox.setCurrentIndex(window.encryptionComboBox.findData(values['encryption']))
return window

def init_encryption(self):
if borg_compat.check('V2'):
encryption_algos = [
Expand Down Expand Up @@ -224,6 +250,8 @@ def run(self):


class ExistingRepoWindow(RepoWindow):
"""Dialog for adding an existing repository."""

def __init__(self):
super().__init__()
self.title.setText(self.tr('Connect to existing Repository'))
Expand All @@ -234,12 +262,45 @@ def __init__(self):
self.repoDataFormLayout.addRow(self.passwordLabel, self.passwordInput)

def set_password(self, URL):
'''Autofill password from keyring only if current entry is empty'''
"""Autofill password from keyring only if current entry is empty"""
password = VortaKeyring.get_keyring().get_password('vorta-repo', URL)
if password and self.passwordInput.get_password() == "":
self._set_status(self.tr("Autofilled password from password manager."))
self.passwordInput.setText(password)

def run_result(self, result):
"""Handle result of BorgInfoRepoJob."""
self.saveButton.setEnabled(True)
if result['returncode'] == 0:
self.added_repo.emit(result)
self.accept()
else:
self._set_status(self.tr('Unable to add your repository.'))
for error in result['errors']:
if 'msgid' in error and error['msgid'] in [
'Repository.DoesNotExist',
'Repository.InvalidRepository',
'InvalidRepository',
]:
self.init_new_repo()
break

def init_new_repo(self):
"""Ask user if they want to initialize a new repository instead."""
answer = QMessageBox.question(
self,
'Add new Repository instead',
self.tr("This repository doesn't seem to exist. Do you want to initialize a new repository?"),
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
)
if answer == QMessageBox.StandardButton.Yes:
init_dialog = AddRepoWindow.from_values(self.values)
repo_tab = self.parent()
init_dialog.setParent(repo_tab, QtCore.Qt.WindowType.Sheet)
init_dialog.added_repo.connect(repo_tab.process_new_repo)
init_dialog.open()
self.close()

def run(self):
if self.validate():
params = BorgInfoRepoJob.prepare(self.values)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def test_repo_check_failed_response(qapp, qtbot, mocker, response):
mock_result: Dict[str, Any] = {
'params': {'repo_url': 'test_repo_url'},
'returncode': response["return_code"],
'errors': [(0, 'test_error_message')] if response["return_code"] not in [0, 130] else None,
'errors': [{'level': 0, 'message': 'test_error_message'}] if response["return_code"] not in [0, 130] else None,
}

mock_exec = mocker.patch.object(QMessageBox, "exec")
Expand Down
Loading