-
-
Save kergoth/09de93347bb62238ad5bede58e41bcd4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def shell_get_vars(d, bbvars): | |
"""Return var/value pairs for use in a shell while loop. | |
Example usage: | |
while read -r var value; do | |
done <<END | |
$'{@shell_get_vars(d, 'FOO BAR')} | |
END | |
""" | |
if isinstance(bbvars, str): | |
bbvars = bbvars.split() | |
lines = [] | |
for var in bbvars: | |
lines.append('{0} {1}\n'.format(var, d.getVar(var, True))) | |
return ''.join(lines) | |
def shell_vars(d, bbvars, indent=' '): | |
"""Return var=value lines to set them as shell variables.""" | |
import subprocess | |
if isinstance(bbvars, str): | |
bbvars = bbvars.split() | |
lines = [] | |
for var in bbvars: | |
value = d.getVar(var, True) | |
lines.append('{0}{1}={2}\n'.format(indent, var, subprocess.list2cmdline([value]))) | |
return ''.join(lines)[len(indent):] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment