aboutsummaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorFrederic Lepied <flepied@mandriva.com>2005-09-08 14:08:38 +0000
committerFrederic Lepied <flepied@mandriva.com>2005-09-08 14:08:38 +0000
commitd42c59fd531dcabd3a0e39c9e0a9fe1dfa5d3259 (patch)
treea05c1364d093be94dc31aed8526b9b4120223c11 /share
parent89e99f5a00638b3291aa974c23fce524a579990c (diff)
downloadmsec-d42c59fd531dcabd3a0e39c9e0a9fe1dfa5d3259.tar
msec-d42c59fd531dcabd3a0e39c9e0a9fe1dfa5d3259.tar.gz
msec-d42c59fd531dcabd3a0e39c9e0a9fe1dfa5d3259.tar.bz2
msec-d42c59fd531dcabd3a0e39c9e0a9fe1dfa5d3259.tar.xz
msec-d42c59fd531dcabd3a0e39c9e0a9fe1dfa5d3259.zip
replace_line_matching: allow to pass the string to insert at the end if nothing
is found.
Diffstat (limited to 'share')
-rw-r--r--share/ConfigFile.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/share/ConfigFile.py b/share/ConfigFile.py
index 4a044f8..4b89d53 100644
--- a/share/ConfigFile.py
+++ b/share/ConfigFile.py
@@ -18,6 +18,8 @@ import commands
from Log import *
import gettext
+STRING_TYPE = type('')
+
try:
cat = gettext.Catalog('msec')
_ = cat.gettext
@@ -286,6 +288,7 @@ class ConfigFile:
return None
def replace_line_matching(self, regex, value, at_end_if_not_found=0, all=0, start=None, end=None):
+ # if at_end_if_not_found is a string its value will be used as the string to inster
r=re.compile(regex)
lines = self.get_lines()
matches = 0
@@ -320,6 +323,8 @@ class ConfigFile:
if not all:
return matches
if matches == 0 and at_end_if_not_found:
+ if type(at_end_if_not_found) == STRING_TYPE:
+ value = at_end_if_not_found
log(_("appended in %s the line:\n%s") % (self.path, value))
if idx == None or idx == len(lines):
self.append(value)