Ubuntu Pastebin

Paste from smoser at Fri, 11 Sep 2015 13:53:13 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/python

import sys
import subprocess
import yaml

yaml_blob = """
smoser_anchors:
 - &foo_script |
   echo "this blob is free from even yaml iterpretation"
   cat <<"EOF"
     you can use this as shown below
   EOF
runcmd:
 - echo this is interpreted by shell home=$HOME essentially by "sh -c string"
 - [sh, -c, 'echo "this explicitly asks for shell interpretation"']
 - [echo, 'this $& can have ** anything ($HOME) ** in it. its safe from shell']
 - [sh, -c, *foo_script]
"""

data = yaml.load(yaml_blob)
for i in data['runcmd']:
    if isinstance(i, str):
        # strings get shell=True
        subprocess.check_call(args=[i], shell=True)
    else:
        # lists do not get shell=True
        subprocess.check_call(args=i)
Download as text