a ‚oe$ã@s\dZddlmZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z z8ddlmZdd lmZdd lmZdd lmZd ZWney®d ZYn0e e¡ZerÆgd¢ngZddœdd„Zddœdd„Zeee e dœdd„Z!ddddœZ"ddddœZ#e e dœdd „Z$e e d!œd"d#„Z%d'e e ee&e e'e e fd$œd%d&„Z(dS)(zk This compat module handles various platform specific calls that do not fall into one particular category. é)Úabsolute_importN)ÚOptional)ÚTuple)Úerrors)Úos)Úerror)Úshell)Ú GetStdHandle)ÚSTD_OUTPUT_HANDLEFT)z /usr/sbinz/usr/local/binz/usr/local/sbin)ÚreturncCstst ¡dkrt d¡‚dS)zÏ On Windows, raise if current shell does not have the administrative rights. Do nothing on Linux. :raises .errors.Error: If the current shell does not have administrative rights on Windows. rzAError, certbot must be run on a shell with administrative rights.N)Ú POSIX_MODEÚ shellwin32Z IsUserAnAdminrÚError©rrú4C:\Program Files\Certbot\pkgs\certbot\compat\misc.pyÚ+raise_for_non_administrative_windows_rights!srcCsTtrdSd}z"ttƒ}|r,| | ¡|B¡Wn tyNtjddd�Yn0dS)zR On Windows, ensure that Console Virtual Terminal Sequences are enabled. NézFailed to set console modeT)Úexc_info)r r r ZSetConsoleModeZGetConsoleModeÚ pywinerrorÚloggerÚdebug)Z"ENABLE_VIRTUAL_TERMINAL_PROCESSINGÚhrrrÚprepare_virtual_console,s r)ÚtimeoutÚpromptr cCsfzDt tjggg|¡\}}}|s8t d |r0|nd¡¡‚|d ¡WSty`tj ¡YS0dS)a( Read user input to return the first line entered, or raise after specified timeout. :param float timeout: The timeout in seconds given to the user. :param str prompt: The prompt message to display to the user. :returns: The first line entered by the user. :rtype: str z,Timed out waiting for answer to prompt '{0}'ÚrN)ÚselectÚsysÚstdinrrÚformatÚreadlineÚOSError)rrZrlistÚ_rrrÚreadline_with_timeout@s ÿ r#z C:\CertbotzC:\Certbot\libzC:\Certbot\log)ZconfigZworkZlogsz/etc/letsencryptz/var/lib/letsencryptz/var/log/letsencrypt)Ú folder_typer cCstjdkrt|St|S)zÏ Return the relevant default folder for the current OS :param str folder_type: The type of folder to retrieve (config, work or logs) :returns: The relevant default folder. :rtype: str Únt)rÚnameÚLINUX_DEFAULT_FOLDERSÚWINDOWS_DEFAULT_FOLDERS)r$rrrÚget_default_folderis r))Úpathr cCs.tjdkr|Stj |¡\}}|| dd¡S)z« Replace unsupported characters in path for current OS by underscores. :param str path: the path to normalize :return: the normalized path :rtype: str r%ú:r")rr&r*Ú splitdriveÚreplace)r*ÚdriveÚtailrrrÚ.underscores_for_unsupported_characters_in_pathzs r0)Úcmd_nameÚ shell_cmdÚenvr c Csnt d||¡tr0tj|dtjtjdd|d�}n$dd|g}tj|tjtjdd|d�}|j|j}}|j||fS)a# Run a command: - on Linux command will be run by the standard shell selected with subprocess.run(shell=True) - on Windows command will be run in a Powershell shell This function returns the exit code, and does not log the result and output of the command. :param str cmd_name: the user facing name of the hook being run :param str shell_cmd: shell command to execute :param dict env: environ to pass into subprocess.run :returns: `tuple` (`int` returncode, `str` stderr, `str` stdout) zRunning %s command: %sTF)rÚstdoutÚstderrÚuniversal_newlinesÚcheckr3zpowershell.exez-Command)r4r5r6r7r3) rÚinfor Ú subprocessÚrunÚPIPEr4r5Ú returncode)r1r2r3ÚprocÚlineÚoutÚerrrrrÚexecute_command_statusŠs þ ÿrA)N))Ú__doc__Z __future__rZloggingrr9rÚtypingrrZcertbotrZcertbot.compatrZ pywintypesrrZwin32com.shellrr Z win32consoler r r Ú ImportErrorZ getLoggerÚ__name__rZSTANDARD_BINARY_DIRSrrÚfloatÚstrr#r(r'r)r0ÚdictÚintrArrrrÚsH             ýýÿÿ