Skip to content

Commit

Permalink
Assign names to repos. By @diivi (#1665)
Browse files Browse the repository at this point in the history
  • Loading branch information
diivi authored Jun 24, 2023
1 parent f76195e commit 92608f9
Show file tree
Hide file tree
Showing 13 changed files with 332 additions and 278 deletions.
557 changes: 289 additions & 268 deletions src/vorta/assets/UI/repoadd.ui

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/vorta/assets/icons/eye-slash.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/vorta/assets/icons/eye.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/vorta/borg/borg_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
db_lock = Lock()
logger = logging.getLogger(__name__)

FakeRepo = namedtuple('Repo', ['url', 'id', 'extra_borg_arguments', 'encryption'])
FakeRepo = namedtuple('Repo', ['url', 'name', 'id', 'extra_borg_arguments', 'encryption'])
FakeProfile = namedtuple('FakeProfile', ['id', 'repo', 'name', 'ssh_key'])

"""
Expand Down Expand Up @@ -190,6 +190,7 @@ def prepare(cls, profile):
ret['ssh_key'] = profile.ssh_key
ret['repo_id'] = profile.repo.id
ret['repo_url'] = profile.repo.url
ret['repo_name'] = profile.repo.name
ret['extra_borg_arguments'] = profile.repo.extra_borg_arguments
ret['profile_name'] = profile.name
ret['profile_id'] = profile.id
Expand Down
8 changes: 5 additions & 3 deletions src/vorta/borg/info_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def prepare(cls, params):
# Build fake profile because we don't have it in the DB yet. Assume unencrypted.
profile = FakeProfile(
999,
FakeRepo(params['repo_url'], 999, params['extra_borg_arguments'], 'none'),
FakeRepo(params['repo_url'], params['repo_name'], 999, params['extra_borg_arguments'], 'none'),
'New Repo',
params['ssh_key'],
)
Expand Down Expand Up @@ -47,14 +47,17 @@ def prepare(cls, params):
ret['message'] = trans_late('messages', 'Please unlock your password manager.')
return ret

ret['repo_name'] = params['repo_name']
ret['ok'] = True
ret['cmd'] = cmd

return ret

def process_result(self, result):
if result['returncode'] == 0:
new_repo, _ = RepoModel.get_or_create(url=result['cmd'][-1])
new_repo, _ = RepoModel.get_or_create(
url=result['cmd'][-1], defaults={'name': result['params']['repo_name']}
)
if 'cache' in result['data']:
stats = result['data']['cache']['stats']
new_repo.total_size = stats['total_size']
Expand All @@ -64,7 +67,6 @@ def process_result(self, result):
new_repo.encryption = result['data']['encryption']['mode']
if new_repo.encryption != 'none':
self.keyring.set_password("vorta-repo", new_repo.url, result['params']['password'])

new_repo.extra_borg_arguments = result['params']['extra_borg_arguments']

new_repo.save()
2 changes: 2 additions & 0 deletions src/vorta/borg/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def prepare(cls, params):
999,
FakeRepo(
params['repo_url'],
params['repo_name'],
999,
params['extra_borg_arguments'],
params['encryption'],
Expand Down Expand Up @@ -61,6 +62,7 @@ def process_result(self, result):
defaults={
'encryption': result['params']['encryption'],
'extra_borg_arguments': result['params']['extra_borg_arguments'],
'name': result['params']['repo_name'],
},
)
if new_repo.encryption != 'none':
Expand Down
2 changes: 1 addition & 1 deletion src/vorta/store/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
)
from .settings import get_misc_settings

SCHEMA_VERSION = 21
SCHEMA_VERSION = 22


@signals.post_save(sender=SettingsModel)
Expand Down
11 changes: 11 additions & 0 deletions src/vorta/store/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,17 @@ def run_migrations(current_schema, db_connection):
),
)

if current_schema.version < 22:
_apply_schema_update(
current_schema,
22,
migrator.add_column(
RepoModel._meta.table_name,
'name',
pw.CharField(default=''),
),
)


def _apply_schema_update(current_schema, version_after, *operations):
with DB.atomic():
Expand Down
1 change: 1 addition & 0 deletions src/vorta/store/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class RepoModel(BaseModel):
"""A single remote repo with unique URL."""

url = pw.CharField(unique=True)
name = pw.CharField(default='')
added_at = pw.DateTimeField(default=datetime.now)
encryption = pw.CharField(null=True)
unique_size = pw.IntegerField(null=True)
Expand Down
7 changes: 6 additions & 1 deletion src/vorta/views/archive_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,12 @@ def populate_from_profile(self):
if repo_mount_points:
self.repo_mount_point = repo_mount_points[0]

self.toolBox.setItemText(0, self.tr('Archives for %s') % profile.repo.url)
if profile.repo.name:
repo_name = f"{profile.repo.name} ({profile.repo.url})"
else:
repo_name = profile.repo.url
self.toolBox.setItemText(0, self.tr('Archives for {}').format(repo_name))

archives = [s for s in profile.repo.archives.select().order_by(ArchiveModel.time.desc())]

# if no archive's name can be found in self.mount_points, then hide the mount point column
Expand Down
7 changes: 7 additions & 0 deletions src/vorta/views/repo_add_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def values(self):
out = dict(
ssh_key=self.sshComboBox.currentData(),
repo_url=self.repoURL.text(),
repo_name=self.repoName.text(),
password=self.passwordLineEdit.text(),
extra_borg_arguments=self.extraBorgArgumentsLineEdit.text(),
)
Expand All @@ -94,6 +95,7 @@ def receive():
folder = dialog.selectedFiles()
if folder:
self.repoURL.setText(folder[0])
self.repoName.setText(folder[0].split('/')[-1])
self.repoURL.setEnabled(False)
self.sshComboBox.setEnabled(False)
self.repoLabel.setText(self.tr('Repository Path:'))
Expand Down Expand Up @@ -126,6 +128,7 @@ def set_visibility(self, visible):
def use_remote_repo_action(self):
self.repoURL.setText('')
self.repoURL.setEnabled(True)
self.repoName.setText('')
self.sshComboBox.setEnabled(True)
self.extraBorgArgumentsLineEdit.setText('')
self.repoLabel.setText(self.tr('Repository URL:'))
Expand Down Expand Up @@ -199,6 +202,10 @@ def validate(self):
self._set_status(self.tr('Please enter a valid repo URL or select a local path.'))
return False

if len(self.values['repo_name']) > 64:
self._set_status(self.tr('Repository name must be less than 64 characters.'))
return False

if RepoModel.get_or_none(RepoModel.url == self.values['repo_url']) is not None:
self._set_status(self.tr('This repo has already been added.'))
return False
Expand Down
4 changes: 3 additions & 1 deletion src/vorta/views/repo_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ def set_icons(self):
def set_repos(self):
self.repoSelector.clear()
self.repoSelector.addItem(self.tr('No repository selected'), None)
# set tooltip = url for each item in the repoSelector
for repo in RepoModel.select():
self.repoSelector.addItem(repo.url, repo.id)
self.repoSelector.addItem(f"{repo.name + ' - ' if repo.name else ''}{repo.url}", repo.id)
self.repoSelector.setItemData(self.repoSelector.count() - 1, repo.url, QtCore.Qt.ItemDataRole.ToolTipRole)

def populate_from_profile(self):
try:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ def test_repo_add_success(qapp, qtbot, mocker, borg_json_output):
main.repoTab.new_repo() # couldn't click menu
add_repo_window = main.repoTab._window
test_repo_url = f'vorta-test-repo.{uuid.uuid4()}.com:repo' # Random repo URL to avoid macOS keychain
test_repo_name = 'Test Repo'

qtbot.keyClicks(add_repo_window.repoURL, test_repo_url)
qtbot.keyClicks(add_repo_window.repoName, test_repo_name)
qtbot.keyClicks(add_repo_window.passwordLineEdit, LONG_PASSWORD)
qtbot.keyClicks(add_repo_window.confirmLineEdit, LONG_PASSWORD)

Expand All @@ -103,7 +105,7 @@ def test_repo_add_success(qapp, qtbot, mocker, borg_json_output):

keyring = VortaKeyring.get_keyring()
assert keyring.get_password("vorta-repo", RepoModel.get(id=2).url) == LONG_PASSWORD
assert main.repoTab.repoSelector.currentText() == test_repo_url
assert main.repoTab.repoSelector.currentText() == f"{test_repo_name} - {test_repo_url}"


def test_ssh_dialog(qapp, qtbot, tmpdir):
Expand Down

0 comments on commit 92608f9

Please sign in to comment.