aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2008-03-05 09:20:27 +0000
committerZac Medico <zmedico@gentoo.org>2008-03-05 09:20:27 +0000
commitf16908081b5de56550a2cc0b49701f66673ae1a0 (patch)
tree17f7da35b32aad98959bd2fa9acdcb45cad1bacd /bin/filter-bash-environment.py
parentRemove redundant CUSTOM_PROFILE_PATH from the PROFILE_PATHS variable so (diff)
downloadportage-f16908081b5de56550a2cc0b49701f66673ae1a0.tar.gz
portage-f16908081b5de56550a2cc0b49701f66673ae1a0.tar.bz2
portage-f16908081b5de56550a2cc0b49701f66673ae1a0.zip
Implement variable assignment handling in python so that we can eventually
make it more flexible and robust. svn path=/main/trunk/; revision=9436
Diffstat (limited to 'bin/filter-bash-environment.py')
-rwxr-xr-xbin/filter-bash-environment.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/bin/filter-bash-environment.py b/bin/filter-bash-environment.py
index 93b049768..c35bf11ff 100755
--- a/bin/filter-bash-environment.py
+++ b/bin/filter-bash-environment.py
@@ -15,6 +15,8 @@ here_doc_re = re.compile(r'.*\s<<[-]?(\w+)$')
func_start_re = re.compile(r'^[-\w]+\s*\(\)\s*$')
func_end_re = re.compile(r'^\}$')
+var_assign_re = re.compile(r'(^|^declare\s+-\S+\s+|^export\s+)([^=\s]+)=.*$')
+
def compile_egrep_pattern(s):
for k, v in egrep_compat_map.iteritems():
s = s.replace(k, v)
@@ -46,8 +48,14 @@ def filter_bash_environment(pattern, file_in, file_out):
if in_func is not None:
file_out.write(line)
continue
- if pattern.match(line) is None:
- file_out.write(line)
+ var_assign_match = var_assign_re.match(line)
+ if var_assign_match is not None:
+ if pattern.match(var_assign_match.group(2)) is None:
+ file_out.write(line)
+ continue
+ # TODO: properly handle multi-line variable assignments
+ # like those which the 'export' builtin can produce.
+ file_out.write(line)
if __name__ == "__main__":
description = "Filter out any lines that match a given PATTERN " + \