Simplify *NIX Permissions
This package primarily provides a command-line script, simple-perms, which suggests and can optionally apply
permission bits from a small set of “simple” permissions (0o444, 0o555, 0o644, 0o755, 0o664, 0o775) based on
the original file’s permissions and type, as follows.
- The basic suggested permission bits are 0o444.
- If the file is a directory, or it has its user execute bit set, the suggested permissions are 0o555.
- If the file has its user write bit set, then the suggested permissions are 0o644 or 0o755.
- If the file has its user write bit set, then the suggested group write permissions (0o664 or 0o775) depend on the options:
- No option or
--ignore-group-write: The suggestion is based on the original group write bit. --group-write: The suggestion always has the group write bit set.--no-group-write: The suggestion never has the group write bit set.
- No option or
- Additionally, the command-line interface allows the setting and masking of permission bits.
No changes are ever suggested for symbolic links.
The motivation for this tool comes from a few different needs, such as:
- When copying files from FAT media, they will often have 0o777 permissions
- When working on a website while having a restrictive umask, files may not be accessible to the webserver
Command-Line Interface
usage: simple-perms [-h] [-v] [-r] [-m] [-g] [-G] [--ignore-group-write] [-a ADD] [-d ADD_DIR] [-f ADD_FILE] [-k] [-u MASK] paths [paths ...]
Check for Simple Permissions
positional arguments:
paths the files to check
optional arguments:
-h, --help show this help message and exit
-v, --verbose list all files
-r, --recurse recurse into directories
-m, --modify automatically modify files' permissions
-g, --group-write the group should have write permission
-G, --no-group-write the group should never have write permission
--ignore-group-write use original group write permission (default)
-a ADD, --add ADD add these permission bits to all files/dirs (octal)
-d ADD_DIR, --add-dir ADD_DIR
add these permission bits to dirs (octal)
-f ADD_FILE, --add-file ADD_FILE
add these permission bits to non-dirs (octal)
-k, --umask apply os.umask() to suggested permission bits
-u MASK, --mask MASK mask (remove) these permission bits from suggestion (octal)
Functions
simple_perms.suggest_perms(st_mode: int, *, group_write: bool | None = None) → tuple[int, int]
Given a set of file mode bits (st_mode), this function suggests new permissions
from a small set of “simple” permissions (0o444, 0o555, 0o644, 0o755, 0o664, 0o775).
- Parameters:
-
st_mode – The original mode bits including the file type information. Usually, you would take this from
os.stat_result.st_modeas returned byos.lstat()orpathlib.Path.lstat(). -
group_write –
Whether the suggestion should have the group write bit set. Note that the group write bit is never suggested unless the original has the user write bit set.
-
- Returns: A tuple consisting of the file’s original permissions and suggested permissions to use instead, based on the arguments to this function, the file’s original user permission bits, and whether it is a directory or not. The two values may be equal indicating that no change is suggested. No changes are ever suggested for symbolic links.
Author, Copyright, and License
Copyright (c) 2022-2024 Hauke Dämpfling (haukex@zero-g.net) at the Leibniz Institute of Freshwater Ecology and Inland Fisheries (IGB), Berlin, Germany, https://www.igb-berlin.de/
This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this program. If not, see https://www.gnu.org/licenses/
Metadata
Release files for simple-perms 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| simple_perms-1.0.0.tar.gz | 13.9 kB | Without provenance | Details for simple_perms-1.0.0.tar.gz |
Release files / simple_perms-1.0.0.tar.gz
| Download URL | simple_perms-1.0.0.tar.gz |
|---|---|
| Size | 13.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ee4df237d98b1e4ace8247c849660ee8691fffbd9162ab55b20e7e3db8de9159
|
|
BLAKE2b-256 checksum How to use checksums |
21d9066cf38f0f1753b8fc3da4722f7b28fafb111bb88d08010ce8251607b473
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.20
|
Security for simple-perms 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.