Skip to content

Commit

Permalink
Merge branch 'master' into log_text
Browse files Browse the repository at this point in the history
  • Loading branch information
aadityasinha-dotcom authored Apr 3, 2023
2 parents 6c056b6 + e0fe766 commit 830c510
Show file tree
Hide file tree
Showing 28 changed files with 165 additions and 131 deletions.
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ package_dir =
include_package_data = true
python_requires = >=3.7
install_requires =
appdirs
platformdirs >=3.0.0, <4.0.0; sys_platform == 'darwin' # for macOS: breaking changes in 3.0.0,
platformdirs >=2.6.0, <4.0.0; sys_platform != 'darwin' # for others: 2.6+ works consistently.
paramiko
pyqt5
peewee
Expand Down
2 changes: 1 addition & 1 deletion src/vorta/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def exception_handler(type, value, tb):

# Init database
sqlite_db = SqliteDatabase(
os.path.join(SETTINGS_DIR, 'settings.db'),
SETTINGS_DIR / 'settings.db',
pragmas={
'journal_mode': 'wal',
},
Expand Down
19 changes: 11 additions & 8 deletions src/vorta/application.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import logging
import os
import sys
from pathlib import Path
from typing import Any, Dict, List, Tuple
from PyQt5 import QtCore
from PyQt5.QtWidgets import QMessageBox
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.config import PROFILE_BOOTSTRAP_FILE, TEMP_DIR
from vorta.config import LOG_DIR, PROFILE_BOOTSTRAP_FILE, TEMP_DIR
from vorta.i18n import init_translations, translate
from vorta.notifications import VortaNotifications
from vorta.profile_export import ProfileExport
Expand All @@ -22,7 +23,7 @@

logger = logging.getLogger(__name__)

APP_ID = os.path.join(TEMP_DIR, "socket")
APP_ID = TEMP_DIR / "socket"


class VortaApp(QtSingleApplication):
Expand All @@ -41,7 +42,7 @@ class VortaApp(QtSingleApplication):
check_failed_event = QtCore.pyqtSignal(dict)

def __init__(self, args_raw, single_app=False):
super().__init__(APP_ID, args_raw)
super().__init__(str(APP_ID), args_raw)
args = parse_args()
if self.isRunning():
if single_app:
Expand Down Expand Up @@ -118,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):
Expand Down Expand Up @@ -193,8 +194,8 @@ def check_darwin_permissions(self):
This function tries reading a file that is known to be restricted and warn the user about
incomplete backups.
"""
test_path = os.path.expanduser('~/Library/Cookies')
if os.path.exists(test_path) and not os.access(test_path, os.R_OK):
test_path = Path('~/Library/Cookies').expanduser()
if test_path.exists() and not os.access(test_path, os.R_OK):
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByMouse)
Expand Down Expand Up @@ -249,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)
Expand Down Expand Up @@ -325,7 +326,9 @@ def check_failed_response(self, result: Dict[str, Any]):
if returncode == 1:
# warning
msg.setIcon(QMessageBox.Icon.Warning)
text = self.tr('Borg exited with a warning message. See logs for details.')
text = translate(
'VortaApp', 'Borg exited with warning status (rc 1). See the <a href="{0}">logs</a> for details.'
).format(LOG_DIR.as_uri())
infotext = error_message
elif returncode > 128:
# 128+N - killed by signal N (e.g. 137 == kill -9)
Expand Down
3 changes: 3 additions & 0 deletions src/vorta/assets/UI/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1" alignment="Qt::AlignTop">
Expand Down
4 changes: 2 additions & 2 deletions src/vorta/autostart.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def open_app_at_startup(enabled=True):

elif sys.platform.startswith('linux'):
from pathlib import Path
from appdirs import user_config_dir
from platformdirs import user_config_path

is_flatpak = Path('/.flatpak-info').exists()

Expand All @@ -58,7 +58,7 @@ def open_app_at_startup(enabled=True):
if is_flatpak:
autostart_path = Path.home() / '.config' / 'autostart'
else:
autostart_path = Path(user_config_dir("autostart"))
autostart_path = user_config_path("autostart")

if not autostart_path.exists():
autostart_path.mkdir(parents=True, exist_ok=True)
Expand Down
1 change: 1 addition & 0 deletions src/vorta/borg/_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'ZSTD': parse_version('1.1.4'),
'JSON_LOG': parse_version('1.1.0'),
'DIFF_JSON_LINES': parse_version('1.1.16'),
'DIFF_CONTENT_ONLY': parse_version('1.2.4'),
'COMPACT_SUBCOMMAND': parse_version('1.2.0a1'),
'V122': parse_version('1.2.2'),
'V2': parse_version('2.0.0b1'),
Expand Down
14 changes: 9 additions & 5 deletions src/vorta/borg/borg_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand All @@ -279,21 +281,23 @@ 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']}, "
f"{translate('BorgJob','Original')}: {pretty_bytes(parsed['original_size'])}, "
# 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:
Expand Down
6 changes: 4 additions & 2 deletions src/vorta/borg/break_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions src/vorta/borg/check.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from typing import Any, Dict
from vorta.config import LOG_DIR
from vorta.i18n import translate
from vorta.utils import borg_compat
from .borg_job import BorgJob


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]):
"""
Expand All @@ -20,10 +22,15 @@ def finished_event(self, result: Dict[str, Any]):
self.app.backup_finished_event.emit(result)
self.result.emit(result)
if result['returncode'] != 0:
self.app.backup_progress_event.emit(self.tr('Repo check failed. See logs for details.'))
self.app.backup_progress_event.emit(
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):
Expand Down
16 changes: 12 additions & 4 deletions src/vorta/borg/compact.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from typing import Any, Dict
from vorta.i18n import trans_late
from vorta.config import LOG_DIR
from vorta.i18n import trans_late, translate
from vorta.utils import borg_compat
from .borg_job import BorgJob


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]):
"""
Expand All @@ -21,9 +24,14 @@ def finished_event(self, result: Dict[str, Any]):
self.app.backup_finished_event.emit(result)
self.result.emit(result)
if result['returncode'] != 0:
self.app.backup_progress_event.emit(self.tr('Errors during compaction. See logs for details.'))
self.app.backup_progress_event.emit(
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):
Expand Down
17 changes: 12 additions & 5 deletions src/vorta/borg/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import subprocess
import tempfile
from datetime import datetime as dt
from vorta.i18n import trans_late
from vorta.config import LOG_DIR
from vorta.i18n import trans_late, translate
from vorta.store.models import ArchiveModel, RepoModel, SourceFileModel, WifiSettingModel
from vorta.utils import borg_compat, format_archive_name, get_network_status_monitor
from .borg_job import BorgJob
Expand Down Expand Up @@ -33,17 +34,23 @@ def process_result(self, result):
repo.save()

if result['returncode'] == 1:
self.app.backup_progress_event.emit(self.tr('Backup finished with warnings. See logs for details.'))
self.app.backup_progress_event.emit(
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_log_event.emit('', {})

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)
Expand Down
4 changes: 2 additions & 2 deletions src/vorta/borg/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]):
Expand Down
11 changes: 9 additions & 2 deletions src/vorta/borg/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,6 +28,9 @@ def prepare(cls, profile, archive_name_1, archive_name_2):
ret['cmd'].append('--json-lines')
ret['json_lines'] = True

if borg_compat.check('DIFF_CONTENT_ONLY'):
ret['cmd'].append('--content-only')

if borg_compat.check('V2'):
ret['cmd'].extend(['-r', profile.repo.url, archive_name_1, archive_name_2])
else:
Expand Down
8 changes: 6 additions & 2 deletions src/vorta/borg/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions src/vorta/borg/info_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 4 additions & 2 deletions src/vorta/borg/list_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 830c510

Please sign in to comment.