a mi@s4ddlZddlmZmZddZddZddZdS) N)PIPEPopencCsftjdstdd}t|dttd}dd|D\}}|rPtd|t|d d d S) z Get user count using the common CloudLinux library. This number is more accurate for systems with a control panel installed. z/opt/cloudlinux/venv/binz(CloudLinux virtual environment not foundzZ/opt/cloudlinux/venv/bin/python3 -c "from clcommon.cpapi import cpusers; print(cpusers())"T)shellstdoutstderrcSsg|]}|qS)decodestrip).0resultrr=/usr/lib/python3.9/site-packages/up2date_client/statistics.py z.get_users_count_from_cllib..z-Failed to get users from CloudLinux library: z, ) ospathexists ValueErrorrrZ communicatelensplit)cmdZprocessoutputerrorsrrr get_users_count_from_cllibs rcCsddlm}|}t|S)zY Fallback method to get the user count by looking into the /etc/passwd file. r)ClPwd)Zup2date_client.clpwdrrZ get_uid_dict)rpwdrrr get_users_count_generics rcCs(z t}Wnty"t}Yn0|S)z Get the total count of users on the server. Tries the CloudLinux library first, falls back to generic method if it fails. )r Exceptionr)Z users_countrrr count_server_users"s    r)r subprocessrrrrrrrrr s