diff --git a/src/vorta/application.py b/src/vorta/application.py index 3c9327db6..5051d8d36 100644 --- a/src/vorta/application.py +++ b/src/vorta/application.py @@ -52,49 +52,50 @@ 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: + 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}") + self.reply("failed - invalid profile name") def quit_app_action(self): self.backup_cancelled_event.emit() @@ -103,7 +104,7 @@ 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 @@ -111,6 +112,8 @@ def create_backup_action(self, profile_id=None): 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() @@ -122,6 +125,12 @@ 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): + if result['returncode'] == 0: + self.reply(f"created {result['data']['archive']['name']}") + else: + self.reply(f"failed {result['errors']}") + def open_main_window_action(self): self.main_window.show() self.main_window.raise_() @@ -147,6 +156,12 @@ 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.info(f"Backup created: {message[8:]}") + sys.exit() + elif message.startswith("failed"): + logger.info(f"Backup failed: {message[7:]}") + sys.exit() elif message.startswith("create"): message = message[7:] # Remove create if self.jobs_manager.is_worker_running(): diff --git a/src/vorta/qt_single_application.py b/src/vorta/qt_single_application.py index 8e5be661f..5f4f69ab0 100644 --- a/src/vorta/qt_single_application.py +++ b/src/vorta/qt_single_application.py @@ -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 @@ -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()