aboutsummaryrefslogtreecommitdiffstats
path: root/share/ConfigFile.py
diff options
context:
space:
mode:
authorFrederic Lepied <flepied@mandriva.com>2002-08-25 19:30:59 +0000
committerFrederic Lepied <flepied@mandriva.com>2002-08-25 19:30:59 +0000
commita03e3ab3b6b2df09fbd9840f391647d1effb4c45 (patch)
treee57c9eaed92c1acf30515b0358d9d20f69e6c90b /share/ConfigFile.py
parentf60e3356bfcfa15ede388f1fef7ea2e3442dc3b3 (diff)
downloadmsec-a03e3ab3b6b2df09fbd9840f391647d1effb4c45.tar
msec-a03e3ab3b6b2df09fbd9840f391647d1effb4c45.tar.gz
msec-a03e3ab3b6b2df09fbd9840f391647d1effb4c45.tar.bz2
msec-a03e3ab3b6b2df09fbd9840f391647d1effb4c45.tar.xz
msec-a03e3ab3b6b2df09fbd9840f391647d1effb4c45.zip
enhanced get_shell_variable to be able to specify a region to do the search.
Diffstat (limited to 'share/ConfigFile.py')
-rw-r--r--share/ConfigFile.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/share/ConfigFile.py b/share/ConfigFile.py
index 64ba296..7d9362a 100644
--- a/share/ConfigFile.py
+++ b/share/ConfigFile.py
@@ -241,10 +241,31 @@ class ConfigFile:
log(_('set variable %s to %s in %s') % (var, value, self.path,))
return self
- def get_shell_variable(self, var):
+ def get_shell_variable(self, var, start=None, end=None):
+ if end:
+ end=re.compile(end)
+ if start:
+ start=re.compile(start)
regex = re.compile('^' + var + '="?([^#"]+)"?(.*)')
lines = self.get_lines()
- for idx in range(len(lines) - 1, -1, -1):
+ llen = len(lines)
+ start_idx = 0
+ end_idx = llen
+ if start:
+ found = 0
+ for idx in range(0, llen):
+ if start.search(lines[idx]):
+ start_idx = idx
+ found = 1
+ break
+ if found:
+ for idx in range(start_idx, llen):
+ if end.search(lines[idx]):
+ end_idx = idx
+ break
+ else:
+ start_idx = 0
+ for idx in range(end_idx - 1, start_idx - 1, -1):
res = regex.search(lines[idx])
if res:
return res.group(1)