#!/opt/imh-python/bin/python3
"""Wrapper around pkgacct for tier2c"""
sys.path.insert(0, '/opt/support/lib')
from arg_types import cpuser_safe_arg
from run_cmd import cpuwatch_execv
# This tool will ensure at least this much space is free after pkgacct
def check_acct_size(user: str):
"""Ensure the account is not too large to pkgacct in full"""
disk_usage = psutil.disk_usage('/home')
gb_free = int(disk_usage.free / 2 ** 30)
gb_total = int(disk_usage.total / 2 ** 30)
acct_gb = int(rads.QuotaCtl().getquota(user=user) / 2 ** 30)
except rads.QuotasDisabled as exc:
sys.exit(f"{exc} - try /scripts/fixquotas")
disk_needed = gb_total * DISK_PERCENT_LIMIT / 100
if gb_free - acct_gb > disk_needed:
print(f"Cannot package {user} without --skiphomedir")
print(f"The account would place the disk at < {DISK_PERCENT_LIMIT}% free")
print(f"Account size: {acct_gb} GB")
print(f"Disk free space: {gb_free} GB")
"""Parse commandline arguments"""
parser = argparse.ArgumentParser(
description='Wrapper around CPanel pkgacct. It is recommended to run '
'this in screen due to the amount of time it may take.'
help='Do not include the home directory in the CPanel package',
help='user to create a CPanel package for',
args = parser.parse_args()
"""main: parse args, determine size, run pkgacct"""
check_acct_size(user=args.user)
cmd = ['/usr/local/cpanel/scripts/pkgacct']
cmd.append('--skiphomedir')
if __name__ == '__main__':