3 0Q=j@s4ddlZddlmZmZddZddZddZdS) N)PIPEPopencCsftjjdstdd}t|dttd}dd|jD\}}|rPtd|t|d d jd 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|]}|jjqS)decodestrip).0resultrr /usr/lib/python3.6/statistics.py sz.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|jS)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 rc Cs*y t}Wntk r$t}YnX|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