From 79276f14df995a80c40d89153840c6ee6153a230 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 20 Feb 2018 10:01:57 +0530 Subject: [PATCH] Don't use async for method parameters async is a reserved keyword in Python 3.7. It can no longer be used as method parameter. Change the name so that we are ready for Python 3.7. See: https://www.python.org/dev/peps/pep-0492/#deprecation-plans Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/actions.py | 22 ++++++++++++---------- plinth/modules/ejabberd/__init__.py | 4 ++-- plinth/modules/letsencrypt/__init__.py | 11 ++++++----- plinth/modules/letsencrypt/views.py | 9 +++++---- plinth/modules/monkeysphere/views.py | 3 ++- plinth/modules/openvpn/views.py | 3 ++- plinth/modules/power/views.py | 4 ++-- plinth/modules/tor/views.py | 5 +++-- plinth/package.py | 3 ++- 9 files changed, 36 insertions(+), 28 deletions(-) diff --git a/plinth/actions.py b/plinth/actions.py index 7758d9618..461f83823 100644 --- a/plinth/actions.py +++ b/plinth/actions.py @@ -100,40 +100,42 @@ from plinth.errors import ActionError LOGGER = logging.getLogger(__name__) -def run(action, options=None, input=None, async=False): +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, async, False) + return _run(action, options, input, run_in_background, False) -def superuser_run(action, options=None, input=None, async=False, +def superuser_run(action, options=None, input=None, run_in_background=False, log_error=True): """Safely run a specific action as root. See actions._run for more information. """ - return _run(action, options, input, async, True, log_error=log_error) + return _run(action, options, input, run_in_background, True, + log_error=log_error) -def run_as_user(action, options=None, input=None, async=False, +def run_as_user(action, options=None, input=None, run_in_background=False, become_user=None): """Run a command as a different user. If become_user is None, run as current user. """ - return _run(action, options, input, async, False, become_user) + return _run(action, options, input, run_in_background, False, become_user) -def _run(action, options=None, input=None, async=False, run_as_root=False, - become_user=None, log_error=True): +def _run(action, options=None, input=None, run_in_background=False, + 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. - options are added to the action command. - input: data (as bytes) that will be sent to the action command's stdin. - - async: run asynchronously or wait for the command to complete. + - run_in_background: run asynchronously or wait for the command to + complete. - run_as_root: execute the command through sudo. """ if options is None: @@ -178,7 +180,7 @@ def _run(action, options=None, input=None, async=False, run_as_root=False, proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False) - if not async: + if not run_in_background: output, error = proc.communicate(input=input) output, error = output.decode(), error.decode() if proc.returncode != 0: diff --git a/plinth/modules/ejabberd/__init__.py b/plinth/modules/ejabberd/__init__.py index 83356198b..ed4092a6f 100644 --- a/plinth/modules/ejabberd/__init__.py +++ b/plinth/modules/ejabberd/__init__.py @@ -161,7 +161,7 @@ def on_post_hostname_change(sender, old_hostname, new_hostname, **kwargs): ['change-hostname', '--old-hostname', old_hostname, '--new-hostname', new_hostname], - async=True) + run_in_background=True) def on_domainname_change(sender, old_domainname, new_domainname, **kwargs): @@ -173,7 +173,7 @@ def on_domainname_change(sender, old_domainname, new_domainname, **kwargs): actions.superuser_run('ejabberd', ['change-domainname', '--domainname', new_domainname], - async=True) + run_in_background=True) def diagnose(): diff --git a/plinth/modules/letsencrypt/__init__.py b/plinth/modules/letsencrypt/__init__.py index 232863c86..10feffc81 100644 --- a/plinth/modules/letsencrypt/__init__.py +++ b/plinth/modules/letsencrypt/__init__.py @@ -123,11 +123,12 @@ def on_domainname_change(sender, old_domainname, new_domainname, **kwargs): del kwargs # Unused for module in MODULES_WITH_HOOKS: - actions.superuser_run(module, ['letsencrypt', 'drop', - '--domain', old_domainname], async=True) - actions.superuser_run('letsencrypt', ['manage_hooks', 'disable', - '--domain', old_domainname], - async=True) + actions.superuser_run( + module, ['letsencrypt', 'drop', '--domain', + old_domainname], run_in_background=True) + actions.superuser_run( + 'letsencrypt', ['manage_hooks', 'disable', '--domain', + old_domainname], run_in_background=True) def get_manage_hooks_status(): diff --git a/plinth/modules/letsencrypt/views.py b/plinth/modules/letsencrypt/views.py index 71b695beb..650523dfb 100644 --- a/plinth/modules/letsencrypt/views.py +++ b/plinth/modules/letsencrypt/views.py @@ -116,7 +116,7 @@ def toggle_hooks(request, domain): if module in manage_hooks_status] for module in enabled_modules: actions.superuser_run(module, ['letsencrypt', 'drop'], - async=True) + run_in_background=True) actions.superuser_run('letsencrypt', ['manage_hooks', subcommand]) if subcommand == 'enable': msg = _('Certificate renewal management enabled for {domain}.')\ @@ -178,9 +178,10 @@ def delete(request, domain): try: for module in enabled_modules: - actions.superuser_run(module, ['letsencrypt', 'drop'], async=True) - actions.superuser_run('letsencrypt', ['manage_hooks', 'disable', - '--domain', domain]) + actions.superuser_run(module, ['letsencrypt', 'drop'], + run_in_background=True) + actions.superuser_run('letsencrypt', + ['manage_hooks', 'disable', '--domain', domain]) except ActionError as exception: messages.error( request, diff --git a/plinth/modules/monkeysphere/views.py b/plinth/modules/monkeysphere/views.py index 28a77010e..c7dc71b7d 100644 --- a/plinth/modules/monkeysphere/views.py +++ b/plinth/modules/monkeysphere/views.py @@ -76,7 +76,8 @@ def publish(request, fingerprint): global publish_process if not publish_process: publish_process = actions.superuser_run( - 'monkeysphere', ['host-publish-key', fingerprint], async=True) + 'monkeysphere', ['host-publish-key', fingerprint], + run_in_background=True) return redirect(reverse_lazy('monkeysphere:index')) diff --git a/plinth/modules/openvpn/views.py b/plinth/modules/openvpn/views.py index 7c486b84a..88d48d6a7 100644 --- a/plinth/modules/openvpn/views.py +++ b/plinth/modules/openvpn/views.py @@ -69,7 +69,8 @@ def setup(request): global setup_process if not openvpn.is_setup() and not setup_process: - setup_process = actions.superuser_run('openvpn', ['setup'], async=True) + setup_process = actions.superuser_run('openvpn', ['setup'], + run_in_background=True) openvpn.add_shortcut() diff --git a/plinth/modules/power/views.py b/plinth/modules/power/views.py index 8a4e45098..92960ce33 100644 --- a/plinth/modules/power/views.py +++ b/plinth/modules/power/views.py @@ -41,7 +41,7 @@ def restart(request): form = None if request.method == 'POST': - actions.superuser_run('power', ['restart'], async=True) + actions.superuser_run('power', ['restart'], run_in_background=True) return redirect(reverse('apps')) else: form = Form(prefix='power') @@ -57,7 +57,7 @@ def shutdown(request): form = None if request.method == 'POST': - actions.superuser_run('power', ['shutdown'], async=True) + actions.superuser_run('power', ['shutdown'], run_in_background=True) return redirect(reverse('apps')) else: form = Form(prefix='power') diff --git a/plinth/modules/tor/views.py b/plinth/modules/tor/views.py index 886e757b0..dd5e8d959 100644 --- a/plinth/modules/tor/views.py +++ b/plinth/modules/tor/views.py @@ -121,7 +121,7 @@ def __apply_changes(request, old_status, new_status): arg_value = 'enable' if new_status['enabled'] else 'disable' arguments.extend(['--service', arg_value]) config_process = actions.superuser_run( - 'tor', ['configure'] + arguments, async=True) + 'tor', ['configure'] + arguments, run_in_background=True) return if arguments: @@ -130,7 +130,8 @@ def __apply_changes(request, old_status, new_status): messages.success(request, _('Configuration updated.')) if needs_restart and new_status['enabled']: - config_process = actions.superuser_run('tor', ['restart'], async=True) + config_process = actions.superuser_run('tor', ['restart'], + run_in_background=True) if not arguments: messages.info(request, _('Setting unchanged')) diff --git a/plinth/package.py b/plinth/package.py index cc9f94992..de41429eb 100644 --- a/plinth/package.py +++ b/plinth/package.py @@ -89,7 +89,8 @@ class Transaction(object): """Run apt-get and update progress.""" self._reset_status() - process = actions.superuser_run('packages', arguments, async=True) + process = actions.superuser_run('packages', arguments, + run_in_background=True) process.stdin.close() stdout_thread = threading.Thread(target=self._read_stdout,