aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-01-31 20:38:18 +0000
committerZac Medico <zmedico@gentoo.org>2010-01-31 20:38:18 +0000
commit3a4a9cad036abf3f011b223fd6fb2fdf9649e213 (patch)
treed167aae94ef51d3d721705b1bc8a14f1102d813a /bin/filter-bash-environment.py
parentFix AttributeError when adjusting incrementals. Thanks to Jonathan Callen (diff)
downloadportage-3a4a9cad036abf3f011b223fd6fb2fdf9649e213.tar.gz
portage-3a4a9cad036abf3f011b223fd6fb2fdf9649e213.tar.bz2
portage-3a4a9cad036abf3f011b223fd6fb2fdf9649e213.zip
Bug #302937 - Handle declare -r without assignment.
svn path=/main/trunk/; revision=15304
Diffstat (limited to 'bin/filter-bash-environment.py')
-rwxr-xr-xbin/filter-bash-environment.py41
1 files changed, 29 insertions, 12 deletions
diff --git a/bin/filter-bash-environment.py b/bin/filter-bash-environment.py
index e919572c9..8c0fdb9da 100755
--- a/bin/filter-bash-environment.py
+++ b/bin/filter-bash-environment.py
@@ -13,6 +13,8 @@ func_end_re = re.compile(r'^\}$')
var_assign_re = re.compile(r'(^|^declare\s+-\S+\s+|^declare\s+|^export\s+)([^=\s]+)=("|\')?.*$')
close_quote_re = re.compile(r'(\\"|"|\')\s*$')
readonly_re = re.compile(r'^declare\s+-(\S*)r(\S*)\s+')
+# declare without assignment
+var_declare_re = re.compile(r'^declare(\s+-\S+)?\s+([^=\s]+)\s*$')
def have_end_quote(quote, line):
"""
@@ -25,6 +27,21 @@ def have_end_quote(quote, line):
return close_quote_match is not None and \
close_quote_match.group(1) == quote
+def filter_declare_readonly_opt(line):
+ 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():]
+ return line
+
def filter_bash_environment(pattern, file_in, file_out):
# Filter out any instances of the \1 character from variable values
# since this character multiplies each time that the environment
@@ -58,20 +75,20 @@ 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():]
+ line = filter_declare_readonly_opt(line)
file_out.write(line.replace("\1", ""))
continue
+ else:
+ declare_match = var_declare_re.match(line)
+ if declare_match is not None:
+ # declare without assignment
+ filter_this = pattern.match(declare_match.group(2)) \
+ is not None
+ if not filter_this:
+ line = filter_declare_readonly_opt(line)
+ file_out.write(line)
+ continue
+
if here_doc_delim is not None:
if here_doc_delim.match(line):
here_doc_delim = None