1 |
Author: zmedico |
2 |
Date: 2010-01-31 20:38:18 +0000 (Sun, 31 Jan 2010) |
3 |
New Revision: 15304 |
4 |
|
5 |
Modified: |
6 |
main/trunk/bin/filter-bash-environment.py |
7 |
Log: |
8 |
Bug #302937 - Handle declare -r without assignment. |
9 |
|
10 |
|
11 |
Modified: main/trunk/bin/filter-bash-environment.py |
12 |
=================================================================== |
13 |
--- main/trunk/bin/filter-bash-environment.py 2010-01-31 16:06:34 UTC (rev 15303) |
14 |
+++ main/trunk/bin/filter-bash-environment.py 2010-01-31 20:38:18 UTC (rev 15304) |
15 |
@@ -13,6 +13,8 @@ |
16 |
var_assign_re = re.compile(r'(^|^declare\s+-\S+\s+|^declare\s+|^export\s+)([^=\s]+)=("|\')?.*$') |
17 |
close_quote_re = re.compile(r'(\\"|"|\')\s*$') |
18 |
readonly_re = re.compile(r'^declare\s+-(\S*)r(\S*)\s+') |
19 |
+# declare without assignment |
20 |
+var_declare_re = re.compile(r'^declare(\s+-\S+)?\s+([^=\s]+)\s*$') |
21 |
|
22 |
def have_end_quote(quote, line): |
23 |
""" |
24 |
@@ -25,6 +27,21 @@ |
25 |
return close_quote_match is not None and \ |
26 |
close_quote_match.group(1) == quote |
27 |
|
28 |
+def filter_declare_readonly_opt(line): |
29 |
+ readonly_match = readonly_re.match(line) |
30 |
+ if readonly_match is not None: |
31 |
+ declare_opts = '' |
32 |
+ for i in (1, 2): |
33 |
+ group = readonly_match.group(i) |
34 |
+ if group is not None: |
35 |
+ declare_opts += group |
36 |
+ if declare_opts: |
37 |
+ line = 'declare -%s %s' % \ |
38 |
+ (declare_opts, line[readonly_match.end():]) |
39 |
+ else: |
40 |
+ line = 'declare ' + line[readonly_match.end():] |
41 |
+ return line |
42 |
+ |
43 |
def filter_bash_environment(pattern, file_in, file_out): |
44 |
# Filter out any instances of the \1 character from variable values |
45 |
# since this character multiplies each time that the environment |
46 |
@@ -58,20 +75,20 @@ |
47 |
multi_line_quote = quote |
48 |
multi_line_quote_filter = filter_this |
49 |
if not filter_this: |
50 |
- readonly_match = readonly_re.match(line) |
51 |
- if readonly_match is not None: |
52 |
- declare_opts = "" |
53 |
- for i in (1, 2): |
54 |
- group = readonly_match.group(i) |
55 |
- if group is not None: |
56 |
- declare_opts += group |
57 |
- if declare_opts: |
58 |
- line = "declare -%s %s" % \ |
59 |
- (declare_opts, line[readonly_match.end():]) |
60 |
- else: |
61 |
- line = "declare " + line[readonly_match.end():] |
62 |
+ line = filter_declare_readonly_opt(line) |
63 |
file_out.write(line.replace("\1", "")) |
64 |
continue |
65 |
+ else: |
66 |
+ declare_match = var_declare_re.match(line) |
67 |
+ if declare_match is not None: |
68 |
+ # declare without assignment |
69 |
+ filter_this = pattern.match(declare_match.group(2)) \ |
70 |
+ is not None |
71 |
+ if not filter_this: |
72 |
+ line = filter_declare_readonly_opt(line) |
73 |
+ file_out.write(line) |
74 |
+ continue |
75 |
+ |
76 |
if here_doc_delim is not None: |
77 |
if here_doc_delim.match(line): |
78 |
here_doc_delim = None |