Skip to main content

Add support for `os.chmod('script.sh', 'ug+x')` syntax style.

Project description

python-chmod-monkey

PyPI PyPI - Python Version PyPI - License Build Status Code coverage

Add support for os.chmod('script.sh', 'ug+x') syntax style.

Almost any expression supported by GNU Coreutils chmod should be supported by this module.

[ugoa]*([-+=]([rwx]*|[ugo]))+|[-+=][0-7]+

Xst flags are not supported though.

Install

pip install chmod-monkey

Usage

There are two ways to use chmod-monkey.

Using os.chmod MonkeyPatch

import os

import chmod_monkey
chmod_monkey.install()  # Install monkeypatch because we are evil !

os.chmod('script.sh', 'ug+x')  # Magic :)

Using to_mode converter

import os

from chmod_monkey import to_mode

os.chmod('script.sh', to_mode('script.sh', 'ug+x'))  # For serious people.

Other features

Context manager

You may use the following syntax to temporary change a file mode.

from chmod_monkey import tmp_chmod

with tmp_chmod('script.sh', "+w"):
    pass # File permissions are modified in this block only
# File permissions are restored here

History

1.1.1 (2020-05-12)

  • Add exception_in_context option to tmp_chmod and more data in context manager.

1.1.0 (2020-05-12)

  • Add tmp_chmod function to temporary apply a permission on a file in a with statement.

1.0.0 (2020-05-11)

  • First version

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for chmod-monkey, version 1.1.1
Filename, size File type Python version Upload date Hashes
Filename, size chmod-monkey-1.1.1.tar.gz (13.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page