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