PyQuota
PyQuota is a simple python wrapper for C apis of quotactl.
Supported kernel versions: >=2.4.22, <5.
Supported commands in C APIs:
Q_QUOTAONQ_QUOTAOFFQ_GETQUOTAQ_GETNEXTQUOTA(requires kernel >= 4.6)Q_SETQUOTAQ_GETINFOQ_SETINFOQ_GETFMTQ_SYNC
Currently, none of the commands for XFS filesystem, e.g. Q_XQUOTAON, are supported due to lack of documentations and testing environments.
Installation
pip install pyquota
Usage
For each of the supported commands, as listed above, this package provides 3 Python methods, which corresponds to operations on user quotas, group quotas and project quotas. Project quota methods requires kernel >=4.1.
For illustration purpose, only examples of user quota methods are provided here. To use group/project quota methods, you only need to replace 'user' in the method names with 'group' or 'project'.
# Import package
import pyquota as pq
# Turn on user quota for a filesystem
pq.userQuotaOn("/dev/sda1", pq.QFMT_VFS_V0, "/aquota.user") # device path, quota format, quota file path
# quota format can be either pq.QFMT_VFS_OLD, pq.QFMT_VFS_V0 or pq.QFMT_VFS_V1.
# Turn off user quota for a filesystem
pq.userQuotaOn("/dev/sda1")
# Get quota of a user on a filesystem
quota = pq.getUserQuota("/dev/sda1", 1000) # 1000 is the uid, returns a tuple of 8 integers
block_hard_limit = quota[0]
block_soft_limit = quota[1]
block_current = quota[2]
inode_hard_limit = quota[3]
inode_soft_limit = quota[4]
inode_current = quota[5]
block_time = quota[6] # time limit for excessive disk use
inode_time = quota[7] # time limit for excessive files
# Get quota of the next user, whose ID is greater than or equal to the specified ID, on a filesystem
quota = pq.getNextUserQuota("/dev/sda1", 1000) # returns a tuple of 9 integers. The last integer is the user id.
uid = quota[8]
#Set quota of a user on a filesystem
pq.setUserQuota("/dev/sda1", 1000, 102400, 92160, 0, 0) # hard block limit 100MB, soft block limit 90MB, no inode limits
#Get information about the user quotafile for a filesystem
info = pq.getUserQuotaInfo("/dev/sda1") # returns a tuple of 3 integers
block_grace = info[0] # Time before block soft limit becomes hard limit
inode_grace = info[1] # Time before inode soft limit becomes hard limit
flags = info[2] # Flags for quotafile
is_root_squash_enabled = bool(flags & pq.DQF_ROOT_SQUASH)
is_stored_in_system_file = bool(flags & pq.DQF_SYS_FILE)
#Set information about the user quotafile for a filesystem
pq.setUserQuotaInfo("/dev/sda1")
#Get quota format used for user quotas on a filesystem
fmt = pq.getUserQuotaFormat("/dev/sda1") # returns an integer
# fmt should be either pq.QFMT_VFS_OLD, pq.QFMT_VFS_V0 or pq.QFMT_VFS_V1
#Update the on-disk copy of user quota usages for a filesystem
pq.syncUserQuotas("/dev/sda1")
#Update the on-disk copy of user quota usages for all filesystems with active quotas
pq.syncUserQuotas(None)
Since this package is only a wrapper for the C APIs, it almost keeps the original flavor and input/output formats. Thus, if you want more details about the what each of these commands do, meaning of the arguments and meaning of the returned values, please read the man page.
Error Messages
Any internal error that comes from the C apis is translated to a pyquota.APIError instance with a text description according to the ERRORS section in the man page.
Metadata
Release files for PyQuota 0.0.2
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 |
|---|---|---|---|---|
| PyQuota-0.0.2.tar.gz | 5.7 kB | Without provenance | Details for PyQuota-0.0.2.tar.gz |
Release files / PyQuota-0.0.2.tar.gz
| Download URL | PyQuota-0.0.2.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9373ec9bda96d03f91198ffd908784e7577838fa1f993f00e8938a50cc4c1fa0
|
|
BLAKE2b-256 checksum How to use checksums |
3a0c74641a3d0464d8d02d940e6776fe538de05a68c00ffbe4168a4bf0c46f94
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8
|
Security for PyQuota 0.0.2
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.