Skip to content

Instantly share code, notes, and snippets.

@hampelm
Created January 16, 2012 22:26
Show Gist options
  • Save hampelm/1623371 to your computer and use it in GitHub Desktop.
Save hampelm/1623371 to your computer and use it in GitHub Desktop.
import stat
def is_world_readable(path):
return os.stat(path).st_mode & stat.S_IROTH
tempdir = tempfile.gettempdir()
if not is_world_readable(tempdir):
if not is_world_readable('/tmp'):
print "ERROR: Can't create temporary file."
exit()
# The postgres user probably can't read
# from the temp dir, so let's set
# it to /tmp.
tempfile.tempdir = '/tmp'
script_content = """#!/bin/sh
echo 'Hello!'
"""
fd, temp_path = tempfile.mkstemp()
f = os.fdopen(fd, 'w')
f.write(script_content)
f.close()
os.chmod(temp_path, 0775)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment