Commit 8f11b54e authored by Jim Fulton's avatar Jim Fulton

Merge pull request #75 from reinout/use-umask

Use umask when doing "chmod +x". Improved version of pull request #18
parents bd0e565b 3f2a4d40
...@@ -117,6 +117,16 @@ def call_subprocess(args, **kw): ...@@ -117,6 +117,16 @@ def call_subprocess(args, **kw):
"Failed to run command:\n%s" "Failed to run command:\n%s"
% repr(args)[1:-1]) % repr(args)[1:-1])
def _execute_permission():
current_umask = os.umask(0o022)
# os.umask only returns the current umask if you also give it one, so we
# have to give it a dummy one and immediately set it back to the real
# value... Distribute does the same.
os.umask(current_umask)
return 0o777 - current_umask
_easy_install_cmd = 'from setuptools.command.easy_install import main; main()' _easy_install_cmd = 'from setuptools.command.easy_install import main; main()'
class Installer: class Installer:
...@@ -1099,7 +1109,7 @@ def _create_script(contents, dest): ...@@ -1099,7 +1109,7 @@ def _create_script(contents, dest):
script.endswith('-script.py') and script[:-10] or script) script.endswith('-script.py') and script[:-10] or script)
try: try:
os.chmod(dest, 493) # 0755 os.chmod(dest, _execute_permission())
except (AttributeError, os.error): except (AttributeError, os.error):
pass pass
...@@ -1167,7 +1177,7 @@ def _pyscript(path, dest, rsetup, initialization=''): ...@@ -1167,7 +1177,7 @@ def _pyscript(path, dest, rsetup, initialization=''):
if changed: if changed:
open(dest, 'w').write(contents) open(dest, 'w').write(contents)
try: try:
os.chmod(dest, 493) # 0755 os.chmod(dest, _execute_permission())
except (AttributeError, os.error): except (AttributeError, os.error):
pass pass
logger.info("Generated interpreter %r.", script) logger.info("Generated interpreter %r.", script)
......
...@@ -697,6 +697,25 @@ original script names to new script names. ...@@ -697,6 +697,25 @@ original script names to new script names.
>>> print_(system(os.path.join(bin, 'run')), end='') >>> print_(system(os.path.join(bin, 'run')), end='')
3 1 3 1
The scripts that are generated are made executable:
>>> if sys.platform == 'win32':
... os.access(os.path.join(bin, 'run.exe'), os.X_OK)
... else:
... os.access(os.path.join(bin, 'run'), os.X_OK)
True
For setting the executable permission, the user's umask is honored:
>>> orig_umask = os.umask(0o077) # Only user gets permissions.
>>> zc.buildout.easy_install._execute_permission() == 0o700
True
>>> tmp = os.umask(0o022) # User can write, the rest not.
>>> zc.buildout.easy_install._execute_permission() == 0o755
True
>>> tmp = os.umask(orig_umask) # Reset umask to the original value.
Including extra paths in scripts Including extra paths in scripts
-------------------------------- --------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment