summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrik Lundin <patrik.lundin.swe@gmail.com>2012-11-25 03:24:49 +0100
committerPatrik Lundin <patrik.lundin.swe@gmail.com>2012-11-25 13:09:54 +0100
commitd4af9e4c5c40e0e20831255346effc5696611384 (patch)
treed038fd7780098f7c9ebc820ec6c8a23ef2a8dead
parentfde00327b043a4ef6c9b358f6a92dc32f38e5077 (diff)
downloadansible-d4af9e4c5c40e0e20831255346effc5696611384.tar.gz
Use shlex for rc.conf parsing.
This makes the line parsing a lot more robust (and easier to read). Code supplied by @dhozac, thanks! Remove re import because this is not used anywhere.
-rw-r--r--library/service11
1 files changed, 5 insertions, 6 deletions
diff --git a/library/service b/library/service
index 355eb2be7c..3889e4fefe 100644
--- a/library/service
+++ b/library/service
@@ -72,8 +72,8 @@ examples:
import platform
import os
-import re
import tempfile
+import shlex
class Service(object):
"""
@@ -209,11 +209,10 @@ class Service(object):
# Build a list containing the possibly modified file.
for rcline in RCFILE:
- # Only parse non-comment and non-empty lines.
- if not re.search('^(#.*)?$', rcline):
- key = rcline.split('=')[0]
- # We need to strip any newline and " signs from the value.
- value = rcline.split('=')[1].strip('\n"')
+ # Parse line removing whitespaces, quotes, etc.
+ rcarray = shlex.split(rcline, comments=True)
+ if len(rcarray) >= 1 and '=' in rcarray[0]:
+ (key, value) = rcarray[0].split("=", 1)
if key == self.rcconf_key:
if value == self.rcconf_value:
# Since the proper entry already exists we can stop iterating.