mirror of
https://github.com/borgbase/vorta
synced 2024-12-22 07:43:09 +00:00
Move umount logic from archive_tab.py
into existing BorgUmountJob
. By @real-yfprojects (#1404)
* src/vorta/borg/umount.py (BorgUmountJob.prepare): Add parameters `mount_point` and optional `archive_name`. Handle them correctly. * src/vorta/views/archive_tab.py : Remove code that can now be found in `umount.py`. Translate error messages returned by `BorgUmountJob.prepare`. Co-authored-by: real-yfprojects <real-yfprojects@users.noreply.github.com>
This commit is contained in:
parent
e275215c71
commit
b4a7c5494e
2 changed files with 21 additions and 24 deletions
|
@ -9,24 +9,32 @@ def started_event(self):
|
|||
self.updated.emit(self.tr('Unmounting archive…'))
|
||||
|
||||
@classmethod
|
||||
def prepare(cls, profile):
|
||||
def prepare(cls, profile, mount_point, archive_name=None):
|
||||
ret = super().prepare(profile)
|
||||
if not ret['ok']:
|
||||
return ret
|
||||
else:
|
||||
ret['ok'] = False # Set back to false, so we can do our own checks here.
|
||||
|
||||
ret['active_mount_points'] = []
|
||||
archive_mount_points = []
|
||||
partitions = psutil.disk_partitions(all=True)
|
||||
for p in partitions:
|
||||
if p.device == 'borgfs':
|
||||
ret['active_mount_points'].append(os.path.normpath(p.mountpoint))
|
||||
archive_mount_points.append(os.path.normpath(p.mountpoint))
|
||||
ret['active_mount_points'] = archive_mount_points
|
||||
|
||||
if len(ret['active_mount_points']) == 0:
|
||||
if len(archive_mount_points) == 0:
|
||||
ret['message'] = trans_late('messages', 'No active Borg mounts found.')
|
||||
return ret
|
||||
if os.path.normpath(mount_point) not in archive_mount_points:
|
||||
ret['message'] = trans_late('messages', 'Mount point not active.')
|
||||
return ret
|
||||
|
||||
cmd = ['borg', 'umount', '--log-json']
|
||||
if archive_name:
|
||||
ret['current_archive'] = archive_name
|
||||
ret['mount_point'] = mount_point
|
||||
|
||||
cmd = ['borg', 'umount', '--log-json', mount_point]
|
||||
|
||||
ret['ok'] = True
|
||||
ret['cmd'] = cmd
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import logging
|
||||
import os.path
|
||||
import sys
|
||||
from datetime import timedelta
|
||||
from typing import Dict, Optional
|
||||
|
@ -31,8 +30,9 @@
|
|||
from vorta.borg.prune import BorgPruneJob
|
||||
from vorta.borg.rename import BorgRenameJob
|
||||
from vorta.borg.umount import BorgUmountJob
|
||||
from vorta.i18n import translate
|
||||
from vorta.store.models import ArchiveModel, BackupProfileMixin
|
||||
from vorta.utils import choose_file_dialog, format_archive_name, get_asset, get_mount_points, pretty_bytes, borg_compat
|
||||
from vorta.utils import choose_file_dialog, format_archive_name, get_asset, get_mount_points, pretty_bytes
|
||||
from vorta.views import diff_result, extract_dialog
|
||||
from vorta.views.diff_result import DiffResultDialog, DiffTree
|
||||
from vorta.views.extract_dialog import ExtractDialog, ExtractTree
|
||||
|
@ -638,25 +638,15 @@ def unmount_action(self, archive_name=None):
|
|||
|
||||
if mount_point is not None:
|
||||
profile = self.profile()
|
||||
params = BorgUmountJob.prepare(profile)
|
||||
params = BorgUmountJob.prepare(profile, mount_point, archive_name=archive_name)
|
||||
if not params['ok']:
|
||||
self._set_status(params['message'])
|
||||
self._set_status(translate('message', params['message']))
|
||||
return
|
||||
|
||||
if archive_name:
|
||||
params['current_archive'] = archive_name
|
||||
params['mount_point'] = mount_point
|
||||
|
||||
if os.path.normpath(mount_point) in params['active_mount_points']:
|
||||
params['cmd'].append(mount_point)
|
||||
|
||||
job = BorgUmountJob(params['cmd'], params, self.profile().repo.id)
|
||||
job.updated.connect(self.mountErrors.setText)
|
||||
job.result.connect(self.umount_result)
|
||||
self.app.jobs_manager.add_job(job)
|
||||
else:
|
||||
self._set_status(self.tr('Mount point not active.'))
|
||||
return
|
||||
job = BorgUmountJob(params['cmd'], params, self.profile().repo.id)
|
||||
job.updated.connect(self.mountErrors.setText)
|
||||
job.result.connect(self.umount_result)
|
||||
self.app.jobs_manager.add_job(job)
|
||||
|
||||
def umount_result(self, result):
|
||||
self._toggle_all_buttons(True)
|
||||
|
@ -908,7 +898,6 @@ def show_diff_result(self, archive_newer, archive_older, model):
|
|||
def rename_action(self):
|
||||
profile = self.profile()
|
||||
|
||||
|
||||
archive_name = self.selected_archive_name()
|
||||
if archive_name is not None:
|
||||
new_name, finished = QInputDialog.getText(
|
||||
|
|
Loading…
Reference in a new issue