Mini Shell
# -*- coding: utf-8 -*-
# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2019 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENSE.TXT
#
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import re
import os
from clcommon.utils import run_command, ExternalProgramFailed
USER_QUOTA_ON_PATTERN = re.compile('user quota on .+ \(.+\) is on')
def is_subpath(path, subpath):
"""
>>> is_subpath('/', '/home')
True
>>> is_subpath('/home', '/home')
True
>>> is_subpath('/', '/')
True
>>> is_subpath('/d', '/f')
False
"""
path = (os.path.abspath(path) + '/').replace('//', '/')
subpath = (os.path.abspath(subpath) + '/').replace('//', '/')
return subpath.startswith(path)
def get_mount_point(path, _mounts='/proc/mounts'):
stream = open(_mounts)
mount_point = None
for line in stream:
mount_point_ = line.split(' ')[1]
if is_subpath(mount_point_, path):
mount_point = mount_point_
break
stream.close()
return mount_point
def check_quota_enabled(path='/home'):
"""
Check if quotas enabled and initialised for specific path
:return: string message with giagnostick information if disabled; None if enabled
"""
if not os.path.isfile('/sbin/quotaon'):
return 'Package "quota" not installed'
mount_point = get_mount_point(path)
try:
quotaon_output = run_command(['/sbin/quotaon', '-up', mount_point]) # old quotaon support only short options
except ExternalProgramFailed as e:
quotaon_output = str(e)
quotaon_output = quotaon_output.strip()
# detect "user quota on / (/dev/mapper/VolGroup-lv_root) is on"
if not USER_QUOTA_ON_PATTERN.search(quotaon_output):
return quotaon_output
Zerion Mini Shell 1.0