Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
62 changes: 35 additions & 27 deletions src/vorta/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,47 +52,47 @@ def __init__(self, args_raw, single_app=False):
elif args.profile:
self.sendMessage(f"create {args.profile}")
logger.info('Creating backup using existing Vorta instance.')
sys.exit()
elif args.profile:
sys.exit('Vorta must already be running for --create to work')

init_translations(self)
self.message_received_event.connect(self.message_received_event_response)
if not args.profile:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if True is generally quicker to read than if not XX. And since we have a large code block under this condition now, it should get at least a comment on when this path is chosen. Still, keeping most of the code on the default path and dealing with exceptions some other way is preferable.

init_translations(self)

self.setQuitOnLastWindowClosed(False)
self.jobs_manager = JobsManager()
self.scheduler = VortaScheduler()
self.setQuitOnLastWindowClosed(False)
self.jobs_manager = JobsManager()
self.scheduler = VortaScheduler()

self.setApplicationName("Vorta")
self.setApplicationName("Vorta")

# Import profile from ~/.vorta-init.json or add empty "Default" profile.
self.bootstrap_profile()
# Import profile from ~/.vorta-init.json or add empty "Default" profile.
self.bootstrap_profile()

# Prepare tray and main window
self.tray = TrayMenu(self)
self.main_window = MainWindow(self)
# Prepare tray and main window
self.tray = TrayMenu(self)
self.main_window = MainWindow(self)

if getattr(args, 'daemonize', False):
pass
elif SettingsModel.get(key='foreground').value:
self.open_main_window_action()
if getattr(args, 'daemonize', False):
pass
elif SettingsModel.get(key='foreground').value:
self.open_main_window_action()

self.backup_started_event.connect(self.backup_started_event_response)
self.backup_finished_event.connect(self.backup_finished_event_response)
self.backup_cancelled_event.connect(self.backup_cancelled_event_response)
self.message_received_event.connect(self.message_received_event_response)
self.check_failed_event.connect(self.check_failed_response)
self.backup_log_event.connect(self.react_to_log)
self.aboutToQuit.connect(self.quit_app_action)
self.set_borg_details_action()
if sys.platform == 'darwin':
self.check_darwin_permissions()
self.backup_started_event.connect(self.backup_started_event_response)
self.backup_finished_event.connect(self.backup_finished_event_response)
self.backup_cancelled_event.connect(self.backup_cancelled_event_response)
self.check_failed_event.connect(self.check_failed_response)
self.backup_log_event.connect(self.react_to_log)
self.aboutToQuit.connect(self.quit_app_action)
self.set_borg_details_action()
if sys.platform == 'darwin':
self.check_darwin_permissions()

def create_backups_cmdline(self, profile_name):
profile = BackupProfileModel.get_or_none(name=profile_name)
if profile is not None:
if profile.repo is None:
logger.warning(f"Add a repository to {profile_name}")
self.create_backup_action(profile_id=profile.id)
self.create_backup_action(profile_id=profile.id, cmd_line=True)
else:
logger.warning(f"Invalid profile name {profile_name}")

Expand All @@ -103,14 +103,16 @@ def quit_app_action(self):
del self.tray
cleanup_db()

def create_backup_action(self, profile_id=None):
def create_backup_action(self, profile_id=None, cmd_line=False):
if not profile_id:
profile_id = self.main_window.current_profile.id

profile = BackupProfileModel.get(id=profile_id)
msg = BorgCreateJob.prepare(profile)
if msg['ok']:
job = BorgCreateJob(msg['cmd'], msg, profile.repo.id)
if cmd_line:
job.result.connect(self.create_backup_cmdline_response)
self.jobs_manager.add_job(job)
else:
notifier = VortaNotifications.pick()
Expand All @@ -122,6 +124,9 @@ def create_backup_action(self, profile_id=None):
self.backup_progress_event.emit(translate('messages', msg['message']))
return None

def create_backup_cmdline_response(self, result):
self.reply(f"created {result['data']['archive']['name']}")

def open_main_window_action(self):
self.main_window.show()
self.main_window.raise_()
Expand All @@ -147,6 +152,9 @@ def backup_cancelled_event_response(self):
def message_received_event_response(self, message):
if message == "open main window":
self.open_main_window_action()
elif message.startswith("created"):
logger.debug(f"Backup created: {message[8:]}")
Comment thread
diivi marked this conversation as resolved.
Outdated
sys.exit()
elif message.startswith("create"):
message = message[7:] # Remove create
if self.jobs_manager.is_worker_running():
Expand Down
13 changes: 13 additions & 0 deletions src/vorta/qt_single_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(self, id, *argv):
# Yes, there is.
self._outStream = QTextStream(self._outSocket)
self._outStream.setCodec('UTF-8')
self._outSocket.readyRead.connect(self._onReadyReply)
else:
# No, there isn't.
self._outSocket = None
Expand Down Expand Up @@ -93,3 +94,15 @@ def _onReadyRead(self):
if not msg:
break
self.message_received_event.emit(msg)

def _onReadyReply(self):
while True:
msg = self._outStream.readLine()
if not msg:
break
self.message_received_event.emit(msg)

def reply(self, msg):
self._inStream << msg << '\n'
self._inStream.flush()
self._inSocket.waitForBytesWritten()