Fix octal values for python 2.4

reviewable/pr18780/r1
Monty Taylor 10 years ago committed by Greg DeKoenigsberg
parent e7ed08f762
commit ce93a91a59

@ -18,6 +18,7 @@
import json import json
import os import os
import pipes import pipes
import stat
DOCUMENTATION = ''' DOCUMENTATION = '''
--- ---
@ -82,8 +83,13 @@ def _write_structured_data(basedir, basename, data):
if not os.path.exists(basedir): if not os.path.exists(basedir):
os.makedirs(basedir) os.makedirs(basedir)
file_path = os.path.join(basedir, "{0}.json".format(basename)) file_path = os.path.join(basedir, "{0}.json".format(basename))
# This is more complex than you might normally expect because we want to
# open the file with only u+rw set. Also, we use the stat constants
# because ansible still supports python 2.4 and the octal syntax changed
out_file = os.fdopen( out_file = os.fdopen(
os.open(file_path, os.O_CREAT | os.O_WRONLY, 0o600), 'w') os.open(
file_path, os.O_CREAT | os.O_WRONLY,
stat.S_IRUSR | stat.S_IWUSR), 'w')
out_file.write(json.dumps(data).encode('utf8')) out_file.write(json.dumps(data).encode('utf8'))
out_file.close() out_file.close()

Loading…
Cancel
Save