diff --git a/plinth/actions.py b/plinth/actions.py index 50ee23988..f4a1d7295 100644 --- a/plinth/actions.py +++ b/plinth/actions.py @@ -100,38 +100,35 @@ from plinth.errors import ActionError LOGGER = logging.getLogger(__name__) -def run(action, options=None, input=None, run_in_background=False, - bufsize=None): +def run(action, options=None, input=None, run_in_background=False): """Safely run a specific action as the current user. See actions._run for more information. """ - return _run(action, options, input, run_in_background, False, - bufsize=bufsize) + return _run(action, options, input, run_in_background, False) def superuser_run(action, options=None, input=None, run_in_background=False, - bufsize=None, log_error=True): + log_error=True): """Safely run a specific action as root. See actions._run for more information. """ return _run(action, options, input, run_in_background, True, - bufsize=bufsize, log_error=log_error) + log_error=log_error) def run_as_user(action, options=None, input=None, run_in_background=False, - bufsize=None, become_user=None): + become_user=None): """Run a command as a different user. If become_user is None, run as current user. """ - return _run(action, options, input, run_in_background, False, become_user, - bufsize=bufsize) + return _run(action, options, input, run_in_background, False, become_user) def _run(action, options=None, input=None, run_in_background=False, - run_as_root=False, become_user=None, log_error=True, bufsize=None): + run_as_root=False, become_user=None, log_error=True): """Safely run a specific action as a normal user or root. Actions are pulled from the actions directory. @@ -196,8 +193,7 @@ def _run(action, options=None, input=None, run_in_background=False, if cfg.develop: # In development mode pass on local pythonpath to access Plinth kwargs['env'] = {'PYTHONPATH': cfg.root} - if bufsize is not None: - kwargs['bufsize'] = bufsize + proc = subprocess.Popen(cmd, **kwargs) if not run_in_background: diff --git a/plinth/modules/backups/repository.py b/plinth/modules/backups/repository.py index fd69d9d35..9c20b8cf1 100644 --- a/plinth/modules/backups/repository.py +++ b/plinth/modules/backups/repository.py @@ -139,9 +139,7 @@ class BorgRepository(object): archive_path = self.get_archive_path(archive_name) args = ['export-tar', '--path', archive_path] args = self.append_encryption_passphrase(args, self.credentials) - kwargs = {'run_in_background': True, - 'bufsize': 1} - proc = self._run('backups', args, kwargs=kwargs) + proc = self._run('backups', args, run_in_background=True) return zipstream.ZipStream(proc.stdout, 'readline') def get_archive(self, name): @@ -166,15 +164,13 @@ class BorgRepository(object): def get_archive_path(self, archive_name): return "::".join([self.repo_path, archive_name]) - def _run(self, cmd, arguments, superuser=True, kwargs=None): + def _run(self, cmd, arguments, superuser=True, **kwargs): """Run a backups or sshfs action script command.""" - if kwargs is None: - kwargs = {} try: if superuser: return actions.superuser_run(cmd, arguments, **kwargs) - else: - return actions.run(cmd, arguments, **kwargs) + + return actions.run(cmd, arguments, **kwargs) except ActionError as err: self.reraise_known_error(err) @@ -293,7 +289,7 @@ class SshBorgRepository(BorgRepository): self._path] arguments, kwargs = self._append_sshfs_arguments(arguments, self.credentials) - self._run('sshfs', arguments, kwargs=kwargs) + self._run('sshfs', arguments, **kwargs) def umount(self): if not self.is_mounted: @@ -314,14 +310,16 @@ class SshBorgRepository(BorgRepository): except Exception as err: logger.error(err) - def _append_sshfs_arguments(self, arguments, credentials, kwargs=None): + def _append_sshfs_arguments(self, arguments, credentials): """Add credentials to a run command and kwargs""" - if kwargs is None: - kwargs = {} + kwargs = {} + if 'ssh_password' in credentials and credentials['ssh_password']: kwargs['input'] = credentials['ssh_password'].encode() + if 'ssh_keyfile' in credentials and credentials['ssh_keyfile']: arguments += ['--ssh-keyfile', credentials['ssh_keyfile']] + return (arguments, kwargs) def run(self, arguments, superuser=True):