/pysyslimit

A system limitor of linux system build by python.

Primary LanguagePythonApache License 2.0Apache-2.0

pysyslimit

PyPI PyPI - Python Version Loc Comments

Docs Deploy Code Test Badge Creation Package Release codecov

GitHub stars GitHub forks GitHub commit activity GitHub issues GitHub pulls Contributors GitHub license

pysyslimit is a light-weight library which can manage the permission in linux system.

Installation

Just install this package with the pip command

pip install pysyslimit

For further information, take a look at the Installation Page.

Quick Start

Please attention that many function in this library need root permission, so It is strongly recommended to run this with root.

Take a look at who I am

from pysyslimit import *

if __name__ == "__main__":
    print("current user:", SystemUser.current())
    print("current user's groups:", SystemUser.current().groups)
    print("current group:", SystemGroup.current())

The output should be

current user: root
current user's groups: [<SystemGroup root, id: 0>]
current group: root

Get and update the permission of files

from pysyslimit import *

if __name__ == "__main__":
    print(FilePermission.load_from_file("test_file"))

    chmod_del("test_file", "004")
    print(FilePermission.load_from_file("test_file"))

    chmod_add("test_file", "014")
    print(FilePermission.load_from_file("test_file"))

The output shall be

rw-rw-r--
rw-rw----
rw-rwxr--

Do calculation between permissions

from pysyslimit import *

if __name__ == "__main__":
    print(FilePermission.loads('463') + FilePermission.loads('615'))
    print(FilePermission.loads('463') | FilePermission.loads('615'))  # the same as +
    print(FilePermission.loads('463') - FilePermission.loads('615'))
    print(FilePermission.loads('463') & FilePermission.loads('615'))

The output shall be

rw-rwxrwx
rw-rwxrwx
---rw--w-
r-------x

Contributing

We appreciate all contributions to improve pysyslimit ,both logic and system designs. Please refer to CONTRIBUTING.md for more guides.

License

pysyslimit released under the Apache 2.0 license.