1
0
Fork 0
mirror of https://github.com/borgbase/vorta synced 2024-12-21 23:33:13 +00:00

feat: add profile name to log messages (#1637)

* feat: add profile name to log messages

* update tests

* add profile name to all occurences of backup progress event emit

* update tests

* merge with logs link code

---------

Co-authored-by: Hofer-Julian <30049909+Hofer-Julian@users.noreply.github.com>
This commit is contained in:
Divyansh Singh 2023-03-22 16:46:46 +05:30 committed by GitHub
parent 1f1278270d
commit 3ebb078409
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 64 additions and 46 deletions

View file

@ -119,7 +119,7 @@ def create_backup_action(self, profile_id=None):
translate('messages', msg['message']),
level='error',
)
self.backup_progress_event.emit(translate('messages', msg['message']))
self.backup_progress_event.emit(f"[{profile.name}] {translate('messages', msg['message'])}")
return None
def open_main_window_action(self):
@ -250,7 +250,7 @@ def react_to_log(self, mgs, context):
def break_lock(self, profile):
params = BorgBreakJob.prepare(profile)
if not params['ok']:
self.backup_progress_event.emit(params['message'])
self.backup_progress_event.emit(f"[{profile.name}] {params['message']}")
return
job = BorgBreakJob(params['cmd'], params)
self.jobs_manager.add_job(job)

View file

@ -270,7 +270,9 @@ def read_async(fd):
'profile_name': self.params.get('profile_name'),
'cmd': self.params['cmd'][1],
}
self.app.backup_log_event.emit(f'{parsed["levelname"]}: {parsed["message"]}', context)
self.app.backup_log_event.emit(
f'[{self.params["profile_name"]}] {parsed["levelname"]}: {parsed["message"]}', context
)
level_int = getattr(logging, parsed["levelname"])
logger.log(level_int, parsed["message"])
@ -279,9 +281,11 @@ def read_async(fd):
error_messages.append((level_int, parsed["message"]))
elif parsed['type'] == 'file_status':
self.app.backup_log_event.emit(f'{parsed["path"]} ({parsed["status"]})', {})
self.app.backup_log_event.emit(
f'[{self.params["profile_name"]}] {parsed["path"]} ({parsed["status"]})', {}
)
elif parsed['type'] == 'progress_percent' and parsed.get("message"):
self.app.backup_log_event.emit(f'{parsed["message"]}', {})
self.app.backup_log_event.emit(f'[{self.params["profile_name"]}] {parsed["message"]}', {})
elif parsed['type'] == 'archive_progress' and not parsed.get('finished', False):
msg = (
f"{translate('BorgJob','Files')}: {parsed['nfiles']}, "
@ -289,11 +293,11 @@ def read_async(fd):
# f"{translate('BorgJob','Compressed')}: {pretty_bytes(parsed['compressed_size'])}, "
f"{translate('BorgJob','Deduplicated')}: {pretty_bytes(parsed['deduplicated_size'])}" # noqa: E501
)
self.app.backup_progress_event.emit(msg)
self.app.backup_progress_event.emit(f"[{self.params['profile_name']}] {msg}")
except json.decoder.JSONDecodeError:
msg = line.strip()
if msg: # Log only if there is something to log.
self.app.backup_log_event.emit(msg, {})
self.app.backup_log_event.emit(f'[{self.params["profile_name"]}] {msg}', {})
logger.warning(msg)
if p.poll() is not None:

View file

@ -4,11 +4,13 @@
class BorgBreakJob(BorgJob):
def started_event(self):
self.app.backup_started_event.emit()
self.app.backup_progress_event.emit(self.tr('Breaking repository lock…'))
self.app.backup_progress_event.emit(f"[{self.params['profile_name']}] {self.tr('Breaking repository lock…')}")
def finished_event(self, result):
self.app.backup_finished_event.emit(result)
self.app.backup_progress_event.emit(self.tr('Repository lock broken. Please redo your last action.'))
self.app.backup_progress_event.emit(
f"[{self.params['profile_name']}] {self.tr('Repository lock broken. Please redo your last action.')}"
)
self.result.emit(result)
@classmethod

View file

@ -8,7 +8,7 @@
class BorgCheckJob(BorgJob):
def started_event(self):
self.app.backup_started_event.emit()
self.app.backup_progress_event.emit(self.tr('Starting consistency check…'))
self.app.backup_progress_event.emit(f"[{self.params['profile_name']}] {self.tr('Starting consistency check…')}")
def finished_event(self, result: Dict[str, Any]):
"""
@ -23,13 +23,14 @@ def finished_event(self, result: Dict[str, Any]):
self.result.emit(result)
if result['returncode'] != 0:
self.app.backup_progress_event.emit(
translate('RepoCheckJob', 'Repo check failed. See the <a href="{0}">logs</a> for details.').format(
f"[{self.params['profile_name']}] "
+ translate('RepoCheckJob', 'Repo check failed. See the <a href="{0}">logs</a> for details.').format(
LOG_DIR.as_uri()
)
)
self.app.check_failed_event.emit(result)
else:
self.app.backup_progress_event.emit(self.tr('Check completed.'))
self.app.backup_progress_event.emit(f"[{self.params['profile_name']}] {self.tr('Check completed.')}")
@classmethod
def prepare(cls, profile):

View file

@ -8,7 +8,9 @@
class BorgCompactJob(BorgJob):
def started_event(self):
self.app.backup_started_event.emit()
self.app.backup_progress_event.emit(self.tr('Starting repository compaction...'))
self.app.backup_progress_event.emit(
f"[{self.params['profile_name']} {self.tr('Starting repository compaction...')}]"
)
def finished_event(self, result: Dict[str, Any]):
"""
@ -23,12 +25,13 @@ def finished_event(self, result: Dict[str, Any]):
self.result.emit(result)
if result['returncode'] != 0:
self.app.backup_progress_event.emit(
translate(
f"[{self.params['profile_name']}] "
+ translate(
'BorgCompactJob', 'Errors during compaction. See the <a href="{0}">logs</a> for details.'
).format(LOG_DIR.as_uri())
)
else:
self.app.backup_progress_event.emit(self.tr('Compaction completed.'))
self.app.backup_progress_event.emit(f"[{self.params['profile_name']}] {self.tr('Compaction completed.')}")
@classmethod
def prepare(cls, profile):

View file

@ -35,20 +35,21 @@ def process_result(self, result):
if result['returncode'] == 1:
self.app.backup_progress_event.emit(
translate(
f"[{self.params['profile_name']}] "
+ translate(
'BorgCreateJob',
'Backup finished with warnings. See the <a href="{0}">logs</a> for details.',
).format(LOG_DIR.as_uri())
)
else:
self.app.backup_progress_event.emit(self.tr('Backup finished.'))
self.app.backup_progress_event.emit(f"[{self.params['profile_name']}] {self.tr('Backup finished.')}")
def progress_event(self, fmt):
self.app.backup_progress_event.emit(fmt)
self.app.backup_progress_event.emit(f"[{self.params['profile_name']}] {fmt}")
def started_event(self):
self.app.backup_started_event.emit()
self.app.backup_progress_event.emit(self.tr('Backup started.'))
self.app.backup_progress_event.emit(f"[{self.params['profile_name']}] {self.tr('Backup started.')}")
def finished_event(self, result):
self.app.backup_finished_event.emit(result)

View file

@ -7,7 +7,7 @@
class BorgDeleteJob(BorgJob):
def started_event(self):
self.app.backup_started_event.emit()
self.app.backup_progress_event.emit(self.tr('Deleting archive…'))
self.app.backup_progress_event.emit(f"[{self.params['profile_name']}] {self.tr('Deleting archive…')}")
def finished_event(self, result):
# set repo stats to N/A
@ -20,7 +20,7 @@ def finished_event(self, result):
self.app.backup_finished_event.emit(result)
self.result.emit(result)
self.app.backup_progress_event.emit(self.tr('Archive deleted.'))
self.app.backup_progress_event.emit(f"[{self.params['profile_name']}] {self.tr('Archive deleted.')}")
@classmethod
def prepare(cls, profile, archives: List[str]):

View file

@ -5,11 +5,15 @@
class BorgDiffJob(BorgJob):
def started_event(self):
self.app.backup_started_event.emit()
self.app.backup_progress_event.emit(self.tr('Requesting differences between archives…'))
self.app.backup_progress_event.emit(
f"[{self.params['profile_name']}] {self.tr('Requesting differences between archives…')}"
)
def finished_event(self, result):
self.app.backup_finished_event.emit(result)
self.app.backup_progress_event.emit(self.tr('Obtained differences between archives.'))
self.app.backup_progress_event.emit(
f"[{self.params['profile_name']}] {self.tr('Obtained differences between archives.')}"
)
self.result.emit(result)
@classmethod

View file

@ -9,12 +9,16 @@
class BorgExtractJob(BorgJob):
def started_event(self):
self.app.backup_started_event.emit()
self.app.backup_progress_event.emit(self.tr('Downloading files from archive…'))
self.app.backup_progress_event.emit(
f"[{self.params['profile_name']}] {self.tr('Downloading files from archive…')}"
)
def finished_event(self, result):
self.app.backup_finished_event.emit(result)
self.result.emit(result)
self.app.backup_progress_event.emit(self.tr('Restored files from archive.'))
self.app.backup_progress_event.emit(
f"[{self.params['profile_name']}] {self.tr('Restored files from archive.')}"
)
@classmethod
def prepare(cls, profile, archive_name, model: ExtractTree, destination_folder):

View file

@ -6,12 +6,12 @@
class BorgInfoArchiveJob(BorgJob):
def started_event(self):
self.app.backup_started_event.emit()
self.app.backup_progress_event.emit(self.tr('Refreshing archive…'))
self.app.backup_progress_event.emit(f"[{self.params['profile_name']}] {self.tr('Refreshing archive…')}")
def finished_event(self, result):
self.app.backup_finished_event.emit(result)
self.result.emit(result)
self.app.backup_progress_event.emit(self.tr('Refreshing archive done.'))
self.app.backup_progress_event.emit(f"[{self.params['profile_name']}] {self.tr('Refreshing archive done.')}")
@classmethod
def prepare(cls, profile, archive_name):

View file

@ -5,11 +5,13 @@
class BorgListArchiveJob(BorgJob):
def started_event(self):
self.app.backup_started_event.emit()
self.app.backup_progress_event.emit(self.tr('Getting archive content…'))
self.app.backup_progress_event.emit(f"[{self.params['profile_name']}] {self.tr('Getting archive content…')}")
def finished_event(self, result):
self.app.backup_finished_event.emit(result)
self.app.backup_progress_event.emit(self.tr('Done getting archive content.'))
self.app.backup_progress_event.emit(
f"[{self.params['profile_name']}] {self.tr('Done getting archive content.')}"
)
self.result.emit(result)
@classmethod

View file

@ -7,12 +7,12 @@
class BorgListRepoJob(BorgJob):
def started_event(self):
self.app.backup_started_event.emit()
self.app.backup_progress_event.emit(self.tr('Refreshing archives…'))
self.app.backup_progress_event.emit(f"[{self.params['profile_name']}] {self.tr('Refreshing archives…')}")
def finished_event(self, result):
self.app.backup_finished_event.emit(result)
self.result.emit(result)
self.app.backup_progress_event.emit(self.tr('Refreshing archives done.'))
self.app.backup_progress_event.emit(f"[{self.params['profile_name']}] {self.tr('Refreshing archives done.')}")
@classmethod
def prepare(cls, profile):

View file

@ -6,7 +6,7 @@
class BorgPruneJob(BorgJob):
def started_event(self):
self.app.backup_started_event.emit()
self.app.backup_progress_event.emit(self.tr('Pruning old archives…'))
self.app.backup_progress_event.emit(f"[{self.params['profile_name']}] {self.tr('Pruning old archives…')}")
def finished_event(self, result):
# set repo stats to N/A
@ -19,7 +19,7 @@ def finished_event(self, result):
self.app.backup_finished_event.emit(result)
self.result.emit(result)
self.app.backup_progress_event.emit(self.tr('Pruning done.'))
self.app.backup_progress_event.emit(f"[{self.params['profile_name']}] {self.tr('Pruning done.')}")
@classmethod
def prepare(cls, profile):

View file

@ -43,9 +43,9 @@ def test_repo_list(qapp, qtbot, mocker, borg_json_output):
assert not tab.bCheck.isEnabled()
qtbot.waitUntil(lambda: main.progressText.text() == 'Refreshing archives done.', **pytest._wait_defaults)
qtbot.waitUntil(lambda: 'Refreshing archives done.' in main.progressText.text(), **pytest._wait_defaults)
assert ArchiveModel.select().count() == 6
assert main.progressText.text() == 'Refreshing archives done.'
assert 'Refreshing archives done.' in main.progressText.text()
assert tab.bCheck.isEnabled()
@ -60,7 +60,7 @@ def test_repo_prune(qapp, qtbot, mocker, borg_json_output):
qtbot.mouseClick(tab.bPrune, QtCore.Qt.LeftButton)
qtbot.waitUntil(lambda: main.progressText.text().startswith('Refreshing archives done.'), **pytest._wait_defaults)
qtbot.waitUntil(lambda: 'Refreshing archives done.' in main.progressText.text(), **pytest._wait_defaults)
def test_repo_compact(qapp, qtbot, mocker, borg_json_output):
@ -93,7 +93,7 @@ def test_check(qapp, mocker, borg_json_output, qtbot):
qtbot.mouseClick(tab.bCheck, QtCore.Qt.LeftButton)
success_text = 'INFO: Archive consistency check complete'
qtbot.waitUntil(lambda: main.logText.text().startswith(success_text), **pytest._wait_defaults)
qtbot.waitUntil(lambda: success_text in main.logText.text(), **pytest._wait_defaults)
def test_mount(qapp, qtbot, mocker, borg_json_output, monkeypatch, choose_file_dialog):
@ -147,7 +147,7 @@ def test_archive_extract(qapp, qtbot, mocker, borg_json_output):
model = tab._window.model
assert model.root.children[0].subpath == 'home'
assert tab._window.archiveNameLabel.text().startswith('test-archive, 2000')
assert 'test-archive, 2000' in tab._window.archiveNameLabel.text()
def test_archive_delete(qapp, qtbot, mocker, borg_json_output):
@ -164,8 +164,7 @@ def test_archive_delete(qapp, qtbot, mocker, borg_json_output):
mocker.patch.object(vorta.borg.borg_job, 'Popen', return_value=popen_result)
mocker.patch.object(vorta.views.archive_tab.ArchiveTab, 'confirm_dialog', lambda x, y, z: True)
tab.delete_action()
qtbot.waitUntil(lambda: main.progressText.text() == 'Archive deleted.', **pytest._wait_defaults)
qtbot.waitUntil(lambda: 'Archive deleted.' in main.progressText.text(), **pytest._wait_defaults)
assert ArchiveModel.select().count() == 1
assert tab.archiveTable.rowCount() == 1

View file

@ -41,4 +41,4 @@ def test_create_lock(qapp, borg_json_output, mocker, qtbot):
qtbot.waitUntil(lambda: main.createStartBtn.isEnabled(), **pytest._wait_defaults) # Prevent thread collision
qapp._msg.accept()
exp_message_text = 'Repository lock broken. Please redo your last action.'
qtbot.waitUntil(lambda: main.progressText.text() == exp_message_text, **pytest._wait_defaults)
qtbot.waitUntil(lambda: exp_message_text in main.progressText.text(), **pytest._wait_defaults)

View file

@ -57,10 +57,8 @@ def test_repo_unlink(qapp, qtbot):
qtbot.mouseClick(main.createStartBtn, QtCore.Qt.LeftButton)
# -1 is the repo id in this test
qtbot.waitUntil(
lambda: main.progressText.text().startswith('Select a backup repository first.'), **pytest._wait_defaults
)
assert main.progressText.text() == 'Select a backup repository first.'
qtbot.waitUntil(lambda: 'Select a backup repository first.' in main.progressText.text(), **pytest._wait_defaults)
assert 'Select a backup repository first.' in main.progressText.text()
def test_password_autofill(qapp, qtbot):
@ -138,7 +136,7 @@ def test_create(qapp, borg_json_output, mocker, qtbot):
mocker.patch.object(vorta.borg.borg_job, 'Popen', return_value=popen_result)
qtbot.mouseClick(main.createStartBtn, QtCore.Qt.LeftButton)
qtbot.waitUntil(lambda: main.progressText.text().startswith('Backup finished.'), **pytest._wait_defaults)
qtbot.waitUntil(lambda: 'Backup finished.' in main.progressText.text(), **pytest._wait_defaults)
qtbot.waitUntil(lambda: main.createStartBtn.isEnabled(), **pytest._wait_defaults)
assert EventLogModel.select().count() == 1
assert ArchiveModel.select().count() == 3