mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 11:42:52 +01:00
Added perlVariableSubstitute.
This commit is contained in:
parent
df1a964a0f
commit
288c6785a8
18
src/utils.py
18
src/utils.py
@ -262,6 +262,24 @@ def perlReToReplacer(s):
|
||||
else:
|
||||
return lambda s: r.sub(replace, s, 1)
|
||||
|
||||
_perlVarSubstituteRe = re.compile(r'\$\{([^}]+)\}|\$(\S+)')
|
||||
def perlVariableSubstitute(vars, text):
|
||||
def replacer(m):
|
||||
(braced, unbraced) = m.groups()
|
||||
var = braced or unbraced
|
||||
try:
|
||||
x = vars[var]
|
||||
if callable(x):
|
||||
return x()
|
||||
else:
|
||||
return str(x)
|
||||
except KeyError:
|
||||
if braced:
|
||||
return '${%s}' % braced
|
||||
else:
|
||||
return '$' + unbraced
|
||||
return _perlVarSubstituteRe.sub(replacer, text)
|
||||
|
||||
def findBinaryInPath(s):
|
||||
"""Return full path of a binary if it's in PATH, otherwise return None."""
|
||||
cmdLine = None
|
||||
|
Loading…
Reference in New Issue
Block a user