3 0Q=jã@s4ddlZddlmZmZdd„Zdd„Zdd„ZdS) éN)ÚPIPEÚPopencCsftjjdƒstdƒ‚d}t|dttd�}dd„|jƒDƒ\}}|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)ÚshellÚstdoutÚstderrcSsg|]}|jƒjƒ‘qS©)ÚdecodeÚstrip)Ú.0Úresultrrú /usr/lib/python3.6/statistics.pyú sz.get_users_count_from_cllib..z-Failed to get users from CloudLinux library: éz, éÿÿÿÿ) ÚosÚpathÚexistsÚ ValueErrorrrZ communicateÚlenÚsplit)ÚcmdZprocessÚoutputÚerrorsrrr Úget_users_count_from_cllibs rcCsddlm}|ƒ}t|jƒƒS)zY Fallback method to get the user count by looking into the /etc/passwd file. r)ÚClPwd)Zup2date_client.clpwdrrZ get_uid_dict)rÚpwdrrr Ú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