xmpp: Fix hacky quoted strings in ejabberd config

- Use a parser generated data type exposed by ruamel.yaml library to get
  the necessary double-quoted strings that we want in the output file.

- Simplify reading and writing to a YAML file.

- Fix incorrect dependency of ruamel.yaml Debian package.  The correct
  one is python3-ruamel.yaml.
This commit is contained in:
Sunil Mohan Adapa 2016-08-28 15:07:00 +05:30
parent edecd74ccf
commit d2800ab6ce
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
2 changed files with 13 additions and 19 deletions

View File

@ -29,7 +29,7 @@
python3-gi \ python3-gi \
python3-psutil \ python3-psutil \
python3-requests \ python3-requests \
python3-ruamel-yaml \ python3-ruamel.yaml \
python3-setuptools \ python3-setuptools \
xmlto xmlto

View File

@ -100,9 +100,8 @@ def subcommand_pre_install(arguments):
def subcommand_setup(_): def subcommand_setup(_):
"""Enabled LDAP authentication and setup jwchat apache conf""" """Enabled LDAP authentication and setup jwchat apache conf"""
with open(EJABBERD_CONFIG, 'r') as conffile: with open(EJABBERD_CONFIG, 'r') as file_handle:
confdata = conffile.read() conf = ruamel.yaml.round_trip_load(file_handle, preserve_quotes=True)
conf = ruamel.yaml.round_trip_load(confdata, preserve_quotes=True)
for listen_port in conf['listen']: for listen_port in conf['listen']:
if 'starttls' in listen_port: if 'starttls' in listen_port:
@ -112,13 +111,11 @@ def subcommand_setup(_):
conf['auth_method'] = 'ldap' conf['auth_method'] = 'ldap'
conf['ldap_servers'] = ['localhost'] conf['ldap_servers'] = ['localhost']
conf['ldap_base'] = '"ou=users,dc=thisbox"' conf['ldap_base'] = ruamel.yaml.scalarstring.DoubleQuotedScalarString(
'ou=users,dc=thisbox')
confdata = ruamel.yaml.round_trip_dump(conf) with open(EJABBERD_CONFIG, 'w') as file_handle:
confdata = confdata.replace( ruamel.yaml.round_trip_dump(conf, file_handle)
'\'"ou=users,dc=thisbox"\'', '"ou=users,dc=thisbox"')
with open(EJABBERD_CONFIG, 'w') as conffile:
conffile.write(confdata)
try: try:
subprocess.check_output(['ejabberdctl', 'restart']) subprocess.check_output(['ejabberdctl', 'restart'])
@ -221,17 +218,14 @@ def subcommand_change_domainname(arguments):
subprocess.call(['pkill', '-u', 'ejabberd']) subprocess.call(['pkill', '-u', 'ejabberd'])
# Add updated domainname to ejabberd hosts list. # Add updated domainname to ejabberd hosts list.
with open(EJABBERD_CONFIG, 'r') as conffile: with open(EJABBERD_CONFIG, 'r') as file_handle:
confdata = conffile.read() conf = ruamel.yaml.round_trip_load(file_handle, preserve_quotes=True)
conf = ruamel.yaml.round_trip_load(confdata, preserve_quotes=True)
conf['hosts'].append('"' + domainname + '"') conf['hosts'].append(ruamel.yaml.scalarstring.DoubleQuotedScalarString(
domainname))
confdata = ruamel.yaml.round_trip_dump(conf) with open(EJABBERD_CONFIG, 'w') as file_handle:
confdata = confdata.replace( ruamel.yaml.round_trip_dump(conf, file_handle)
'\'"' + domainname + '"\'', '"' + domainname + '"')
with open(EJABBERD_CONFIG, 'w') as conffile:
conffile.write(confdata)
action_utils.service_start('ejabberd') action_utils.service_start('ejabberd')