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 <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2018-02-20 10:01:57 +05:30 committed by James Valleroy
parent 8c8e4ea3e8
commit 79276f14df
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
9 changed files with 36 additions and 28 deletions

View File

@ -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:

View File

@ -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():

View File

@ -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():

View File

@ -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,

View File

@ -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'))

View File

@ -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()

View File

@ -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')

View File

@ -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'))

View File

@ -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,