added substitute_shell_vars and shell_var_value functions.
git-svn-id: svn+ssh://rpmlint.zarb.org/home/projects/rpmlint/svn/trunk@577 9bc8b190-ac0f-0410-8968-dc7d1f502856
This commit is contained in:
parent
050d6b54a7
commit
7153aab8c6
24
Pkg.py
24
Pkg.py
|
@ -34,6 +34,8 @@ try:
|
|||
except AttributeError:
|
||||
v304=0
|
||||
|
||||
# utilities
|
||||
|
||||
def grep(regex, filename):
|
||||
fd=open(filename, "r")
|
||||
ret=0
|
||||
|
@ -49,6 +51,28 @@ def grep(regex, filename):
|
|||
print "unable to open", filename
|
||||
return ret
|
||||
|
||||
def shell_var_value(var, script):
|
||||
assign_regex=re.compile(var + '\s*=\s*(.+)\s*(#.*)*$', re.MULTILINE)
|
||||
res=assign_regex.search(script)
|
||||
if res:
|
||||
return substitute_shell_vars(res.group(1), script)
|
||||
else:
|
||||
return None
|
||||
|
||||
var_regex=re.compile('^(.*)\${?([^}]+)}?(.*)$')
|
||||
|
||||
def substitute_shell_vars(val, script):
|
||||
res=var_regex.search(val)
|
||||
if res:
|
||||
value=shell_var_value(res.group(2), script)
|
||||
if not value:
|
||||
value=''
|
||||
return res.group(1) + value + substitute_shell_vars(res.group(3), script)
|
||||
else:
|
||||
return val
|
||||
|
||||
# classes representing package
|
||||
|
||||
class Pkg:
|
||||
file_regex=re.compile("(?:\.)?([^:]+):\s+(.*)")
|
||||
|
||||
|
|
Loading…
Reference in New Issue