Use workaround for shlex.join()
on older python
This commit is contained in:
parent
f1ecf9a1e4
commit
5acf8d5304
|
@ -24,9 +24,8 @@
|
||||||
Fabric library for Postfix
|
Fabric library for Postfix
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import shlex
|
|
||||||
|
|
||||||
from rattail_fabric2 import apt
|
from rattail_fabric2 import apt
|
||||||
|
from rattail.util import shlex_join
|
||||||
|
|
||||||
|
|
||||||
def install(c):
|
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:
|
if c.run("grep '^{}:' /etc/aliases".format(name), warn=True).failed:
|
||||||
# append new entry
|
# append new entry
|
||||||
entry = '{}: {}'.format(name, alias_to)
|
entry = '{}: {}'.format(name, alias_to)
|
||||||
echo = shlex.join(['echo', entry])
|
echo = shlex_join(['echo', entry])
|
||||||
cmd = '{} >> /etc/aliases'.format(echo)
|
cmd = '{} >> /etc/aliases'.format(echo)
|
||||||
cmd = shlex.join(['bash', '-c', cmd])
|
cmd = shlex_join(['bash', '-c', cmd])
|
||||||
c.sudo(cmd)
|
c.sudo(cmd)
|
||||||
else:
|
else:
|
||||||
# update existing entry
|
# update existing entry
|
||||||
alias_to = alias_to.replace('|', '\\|')
|
alias_to = alias_to.replace('|', '\\|')
|
||||||
sub = "s|^{}: .*|{}: {}|".format(name, name, alias_to)
|
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(cmd)
|
||||||
|
|
||||||
c.sudo('newaliases')
|
c.sudo('newaliases')
|
||||||
|
|
Loading…
Reference in a new issue