Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/toilal/python-chmod-monkey
Add support for `os.chmod('script.sh', 'ug+x')` syntax style.
https://github.com/toilal/python-chmod-monkey
chmod monkeypatch python str string
Last synced: about 1 month ago
JSON representation
Add support for `os.chmod('script.sh', 'ug+x')` syntax style.
- Host: GitHub
- URL: https://github.com/toilal/python-chmod-monkey
- Owner: Toilal
- License: mit
- Created: 2020-05-10T19:20:37.000Z (over 4 years ago)
- Default Branch: develop
- Last Pushed: 2020-05-12T21:55:06.000Z (over 4 years ago)
- Last Synced: 2024-11-13T00:13:09.273Z (about 2 months ago)
- Topics: chmod, monkeypatch, python, str, string
- Language: Python
- Homepage:
- Size: 23.4 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# python-chmod-monkey
[![PyPI](https://img.shields.io/pypi/v/chmod-monkey)](https://pypi.org/project/chmod-monkey/)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/chmod-monkey)
![PyPI - License](https://img.shields.io/pypi/l/chmod-monkey)
[![Build Status](https://img.shields.io/travis/Toilal/python-chmod-monkey.svg)](https://travis-ci.org/Toilal/python-chmod-monkey)
[![Code coverage](https://img.shields.io/coveralls/github/Toilal/python-chmod-monkey)](https://coveralls.io/github/Toilal/python-chmod-monkey)Add support for `os.chmod('script.sh', 'ug+x')` syntax style.
Almost any expression supported by [GNU Coreutils chmod](https://linux.die.net/man/1/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
```python
import osimport chmod_monkey
chmod_monkey.install() # Install monkeypatch because we are evil !os.chmod('script.sh', 'ug+x') # Magic :)
```### Using to_mode converter
```python
import osfrom 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.
```python
from chmod_monkey import tmp_chmodwith tmp_chmod('script.sh', "+w"):
pass # File permissions are modified in this block only
# File permissions are restored here
```