~bcsaller/pyjuju/relation-get-shell

« back to all changes in this revision

Viewing changes to ensemble/hooks/commands.py

  • Committer: Benjamin Saller
  • Date: 2011-08-08 16:57:06 UTC
  • Revision ID: bcsaller@gmail.com-20110808165706-qjdzfq7r97an8lmr
uses pipes.quote for shell value output to ensure proper quoting

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import logging
2
2
import os
 
3
import pipes
3
4
import re
4
5
import sys
5
6
 
40
41
 
41
42
        if result:
42
43
            errs = []
43
 
            for k, v in result.items():
 
44
            for k, v in sorted(result.items()):
44
45
                if k.startswith("VAR_"):
45
46
                    errs.append(k)
46
47
                    print >>stream, '%s=' % (k.upper(), )
47
48
                else:
48
49
                    k = BAD_CHARS.sub("_", k.upper())
49
 
                    print >>stream, 'VAR_%s="%s"' % (k.upper(), v)
 
50
                    v = pipes.quote(v)
 
51
                    print >>stream, 'VAR_%s=%s' % (k.upper(), v)
50
52
 
51
53
                # order of output within streams is assured but we
52
54
                # output on (commonly) two streams here and the
57
59
                print >>sys.stderr, "The following were omitted from " \
58
60
                "the environment.  VAR_ prefixed variables indicate a " \
59
61
                "usage error."
60
 
                print >> sys.stderr, " ".join(errs)
 
62
                print >> sys.stderr, "".join(errs)
61
63
 
62
64
def relation_get():
63
65
    """Entry point for relation-get"""