Created
January 16, 2012 22:26
-
-
Save hampelm/1623371 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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