summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2008-03-06 01:03:42 +0000
committerZac Medico <zmedico@gentoo.org>2008-03-06 01:03:42 +0000
commit602f6eacef5ab3eb73f3846078ff42a1920ac6ca (patch)
tree7ab4b75a3c5d4e4f8687252237a5ae43e7178a1c /bin/filter-bash-environment.py
parentMove the variable name validation regexes (for bug 211949) into (diff)
downloadportage-multirepo-602f6eacef5ab3eb73f3846078ff42a1920ac6ca.tar.gz
portage-multirepo-602f6eacef5ab3eb73f3846078ff42a1920ac6ca.tar.bz2
portage-multirepo-602f6eacef5ab3eb73f3846078ff42a1920ac6ca.zip
Implement the sed-based declare -r filter in python.
svn path=/main/trunk/; revision=9446
Diffstat (limited to 'bin/filter-bash-environment.py')
-rwxr-xr-xbin/filter-bash-environment.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/bin/filter-bash-environment.py b/bin/filter-bash-environment.py
index ab348d99..5e109295 100755
--- a/bin/filter-bash-environment.py
+++ b/bin/filter-bash-environment.py
@@ -17,6 +17,7 @@ func_end_re = re.compile(r'^\}$')
var_assign_re = re.compile(r'(^|^declare\s+-\S+\s+|^export\s+)([^=\s]+)=("|\')?.*$')
close_quote_re = re.compile(r'(\\"|"|\')\s*$')
+readonly_re = re.compile(r'^declare\s+-(\S*)r(\S*)\s+')
def compile_egrep_pattern(s):
for k, v in egrep_compat_map.iteritems():
@@ -57,6 +58,18 @@ def filter_bash_environment(pattern, file_in, file_out):
multi_line_quote = quote
multi_line_quote_filter = filter_this
if not filter_this:
+ readonly_match = readonly_re.match(line)
+ if readonly_match is not None:
+ declare_opts = ""
+ for i in (1, 2):
+ group = readonly_match.group(i)
+ if group is not None:
+ declare_opts += group
+ if declare_opts:
+ line = "declare -%s %s" % \
+ (declare_opts, line[readonly_match.end():])
+ else:
+ line = "declare " + line[readonly_match.end():]
file_out.write(line)
continue
if here_doc_delim is not None: