def _umount_archives(self): if self.mount_paths: for path in self.mount_paths: if os.path.exists(path): os.system('restic umount ' + path) remove_path(path) self.mount_paths = []
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 = ResticException( "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 = restic.MountThread(archive_name, mount_path) try: thread.run() self.mount_paths.append(mount_path) open_path(mount_path) except ResticException 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 = ResticException( "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 = restic.RestoreThread(archive_name, restore_path) dialog = ProgressDialog(thread) dialog.label_info.setText( "Restic-Qt is currently restoring a backup.") dialog.exec_() open_path(restore_path) except ResticException as e: show_error(e) remove_path(restore_path)
def repository(tmpdir_factory): repository_path = tmpdir_factory.mktemp('test-resticqt') os.environ['RESTIC_REPOSITORY'] = repository_path.strpath os.environ['RESTIC_PASSWORD'] = '******' subprocess.run(['restic', 'init'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) yield remove_path(repository_path)
def target_path(tmpdir): yield str(tmpdir) remove_path(str(tmpdir))
def mock_home(tmpdir): envs = { 'HOME': tmpdir.strpath, } yield envs remove_path(envs['HOME'])