Skip to main content

Simplify *NIX Permissions

Project description

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.

  1. The basic suggested permission bits are 0o444.
  2. If the file is a directory, or it has its user execute bit set, the suggested permissions are 0o555.
  3. If the file has its user write bit set, then the suggested permissions are 0o644 or 0o755.
  4. 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.
  5. Additionally, the command-line interface allows the setting and masking of permission bits.

No changes are ever suggested for symbolic links.

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)

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_mode as returned by os.lstat() or pathlib.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.

      • When None (the default), the suggestion is based on the original group write bit.
      • When False, the suggestion never has the group write bit set.
      • When True, the suggestion always has the group 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/

Project details


Download files

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

Source Distribution

simple-perms-0.9.1.tar.gz (13.3 kB view details)

Uploaded Source

File details

Details for the file simple-perms-0.9.1.tar.gz.

File metadata

  • Download URL: simple-perms-0.9.1.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for simple-perms-0.9.1.tar.gz
Algorithm Hash digest
SHA256 1edbf20c818308ef2de30edaf8226a9b333892a5ce2ae4dfb391e55f865b91e5
MD5 e40b65a085d196268610fb670c146300
BLAKE2b-256 43133933b4924446044ff6dc2f4f65ec40f2d9962ea5a9863a841c9b49d75403

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page