Use workaround for shlex.join() on older python

This commit is contained in:
Lance Edgar 2022-11-21 20:09:51 -06:00
parent f1ecf9a1e4
commit 5acf8d5304

View file

@ -24,9 +24,8 @@
Fabric library for Postfix
"""
import shlex
from rattail_fabric2 import apt
from rattail.util import shlex_join
def install(c):
@ -45,15 +44,15 @@ def alias(c, name, alias_to, path='/etc/aliases'):
if c.run("grep '^{}:' /etc/aliases".format(name), warn=True).failed:
# append new entry
entry = '{}: {}'.format(name, alias_to)
echo = shlex.join(['echo', entry])
echo = shlex_join(['echo', entry])
cmd = '{} >> /etc/aliases'.format(echo)
cmd = shlex.join(['bash', '-c', cmd])
cmd = shlex_join(['bash', '-c', cmd])
c.sudo(cmd)
else:
# update existing entry
alias_to = alias_to.replace('|', '\\|')
sub = "s|^{}: .*|{}: {}|".format(name, name, alias_to)
cmd = shlex.join(['sed', '-i.bak', '-E', sub, '/etc/aliases'])
cmd = shlex_join(['sed', '-i.bak', '-E', sub, '/etc/aliases'])
c.sudo(cmd)
c.sudo('newaliases')