Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 302937
Collapse All | Expand All

(-)bin/filter-bash-environment.py (-12 / +29 lines)
Lines 13-18 Link Here
13
var_assign_re = re.compile(r'(^|^declare\s+-\S+\s+|^declare\s+|^export\s+)([^=\s]+)=("|\')?.*$')
13
var_assign_re = re.compile(r'(^|^declare\s+-\S+\s+|^declare\s+|^export\s+)([^=\s]+)=("|\')?.*$')
14
close_quote_re = re.compile(r'(\\"|"|\')\s*$')
14
close_quote_re = re.compile(r'(\\"|"|\')\s*$')
15
readonly_re = re.compile(r'^declare\s+-(\S*)r(\S*)\s+')
15
readonly_re = re.compile(r'^declare\s+-(\S*)r(\S*)\s+')
16
# declare without assignment
17
var_declare_re = re.compile(r'^declare(\s+-\S+)?\s+([^=\s]+)\s*$')
16
18
17
def have_end_quote(quote, line):
19
def have_end_quote(quote, line):
18
	"""
20
	"""
Lines 25-30 Link Here
25
	return close_quote_match is not None and \
27
	return close_quote_match is not None and \
26
		close_quote_match.group(1) == quote
28
		close_quote_match.group(1) == quote
27
29
30
def filter_declare_readonly_opt(line):
31
	readonly_match = readonly_re.match(line)
32
	if readonly_match is not None:
33
		declare_opts = ''
34
		for i in (1, 2):
35
			group = readonly_match.group(i)
36
			if group is not None:
37
				declare_opts += group
38
		if declare_opts:
39
			line = 'declare -%s %s' % \
40
				(declare_opts, line[readonly_match.end():])
41
		else:
42
			line = 'declare ' + line[readonly_match.end():]
43
	return line
44
28
def filter_bash_environment(pattern, file_in, file_out):
45
def filter_bash_environment(pattern, file_in, file_out):
29
	# Filter out any instances of the \1 character from variable values
46
	# Filter out any instances of the \1 character from variable values
30
	# since this character multiplies each time that the environment
47
	# since this character multiplies each time that the environment
Lines 58-77 Link Here
58
					multi_line_quote = quote
75
					multi_line_quote = quote
59
					multi_line_quote_filter = filter_this
76
					multi_line_quote_filter = filter_this
60
				if not filter_this:
77
				if not filter_this:
61
					readonly_match = readonly_re.match(line)
78
					line = filter_declare_readonly_opt(line)
62
					if readonly_match is not None:
63
						declare_opts = ""
64
						for i in (1, 2):
65
							group = readonly_match.group(i)
66
							if group is not None:
67
								declare_opts += group
68
						if declare_opts:
69
							line = "declare -%s %s" % \
70
								(declare_opts, line[readonly_match.end():])
71
						else:
72
							line = "declare " + line[readonly_match.end():]
73
					file_out.write(line.replace("\1", ""))
79
					file_out.write(line.replace("\1", ""))
74
				continue
80
				continue
81
			else:
82
				declare_match = var_declare_re.match(line)
83
				if declare_match is not None:
84
					# declare without assignment
85
					filter_this = pattern.match(declare_match.group(2)) \
86
						is not None
87
					if not filter_this:
88
						line = filter_declare_readonly_opt(line)
89
						file_out.write(line)
90
					continue
91
75
		if here_doc_delim is not None:
92
		if here_doc_delim is not None:
76
			if here_doc_delim.match(line):
93
			if here_doc_delim.match(line):
77
				here_doc_delim = None
94
				here_doc_delim = None

Return to bug 302937