From d42c59fd531dcabd3a0e39c9e0a9fe1dfa5d3259 Mon Sep 17 00:00:00 2001 From: Frederic Lepied Date: Thu, 8 Sep 2005 14:08:38 +0000 Subject: replace_line_matching: allow to pass the string to insert at the end if nothing is found. --- share/ConfigFile.py | 5 +++++ 1 file changed, 5 insertions(+) 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) -- cgit v1.2.1