def _create_server_path(self): """creates the full server path from the server, user and port options.""" if not self._return_single_option('user'): raise BorgException("User is missing in config.") if not self._return_single_option('port'): raise BorgException("Port is missing in config.") server_path = ('ssh://' + self.config['borgqt']['user'] + "@" + self.config['borgqt']['server'] + ":" + self.config['borgqt']['port'] + self.config['borgqt']['repository_path']) return server_path
def mount_backup(self): """Mount the selected archive in the tmp directory. If it succeeds the mount_path gets written to a property of the main_window.""" try: archive_name = self.selected_archive except AttributeError: error = BorgException("Please create or select an archive first.") archive_name = None show_error(error) # only continue if the user selected an archive if archive_name: mount_path = os.path.join('/tmp/', archive_name) create_path(mount_path) # only continue if the mount_path is writeable if os.access(mount_path, os.W_OK): thread = borg.MountThread(archive_name, mount_path) try: thread.run() self.mount_paths.append(mount_path) open_path(mount_path) except BorgException as e: show_error(e) remove_path(mount_path) else: # Opens the path in a file manager open_path(mount_path)
def restore_backup(self): """Restores a selected backup to the given path.""" try: archive_name = self.selected_archive target_path = self._get_target_path() except AttributeError: error = BorgException("Please create or select an archive first.") archive_name = None target_path = None show_error(error) # Only restore the backup if the target is writeable and the archive # was selected. if check_path(target_path) and archive_name: try: restore_path = os.path.join(target_path, archive_name) create_path(restore_path) thread = borg.RestoreThread(archive_name, restore_path) dialog = ProgressDialog(thread) dialog.label_info.setText( "Borg-Qt is currently restoring a backup.") dialog.exec_() open_path(restore_path) except BorgException as e: show_error(e) remove_path(restore_path)
def _get_path(self): """searches for the configuration file and returns its full path.""" home = os.environ['HOME'] dir_path = os.path.dirname(os.path.realpath(__file__)) if os.path.exists(os.path.join(home, '.config/borg_qt/borg_qt.conf')): return os.path.join(home, '.config/borg_qt/borg_qt.conf') elif os.path.exists(os.path.join(dir_path, 'borg_qt.conf')): return os.path.join(dir_path, 'borg_qt.conf') else: raise BorgException("Configuration file not found!")
def process_json_error(self, json_err): """Looks in the returned json error string for errors and provides them as BorgException in case there are any. Ignores errors about stale locks of borg.""" if json_err: error = json_err.splitlines()[0] if 'stale' in error: return else: err = json.loads(error) raise BorgException(err['message'])
def delete_backup(self): """Deletes the selected archive from the repository.""" if not self._check_mounts(): return try: archive_name = self.selected_archive except AttributeError: error = BorgException("Please create or select an archive first.") archive_name = None show_error(error) # Only continue if an archive was selected. if archive_name: # Prompt the user before continuing. if self.yes_no("Do you want to delete this archive?"): try: thread = borg.DeleteThread(archive_name) dialog = ProgressDialog(thread) dialog.label_info.setText( "Borg-Qt is currently deleting an archive.") dialog.exec_() self.update_ui() except BorgException as e: show_error(e)
def _check_path(self): """Makes sure that the user selected a path to backup.""" message = ("Please select a file or directory " "before taking a backup.") if not hasattr(self, 'src_path'): raise BorgException(message)