U Ce@szddlZddlZddlZddlZddlZddlZddlZddlm Z dZ dZ ddZ ddZ d d Zdd d ZddZdS)NPathz0.0.1 cGsdtjkrtjd}nHt}|s*tdt}|dkrPtj|dddd}ntj|d}zt|j d d Wnt k rYnX|D]}tj||}q|S) zReturns the MySQL Shell's user directory The directory will be created if it does not exist yet Args: *argv: The list of directories to be added to the path Returns: The plugin directory path as string ZMYSQLSH_USER_CONFIG_HOMEzNo home directory setZWindowsZAppDataZRoamingZMySQLmysqlshz.mysqlshTparents) osenvironrhome ExceptionplatformsystempathjoinmkdirFileExistsError)argvZ shell_dirZhome_diros_nameargrB/usr/lib/mysqlsh/python-packages/mysqlsh/plugin_manager/general.pyget_shell_user_dir&s,  rcGsNtd}zt|jddWntk r0YnX|D]}tj||}q6|S)zReturns the MySQL Shell's temp directory The directory will be created if it does not exist yet Args: *argv: The list of directories to be added to the path Returns: The temp directory path as string ZtempTr)rrrrrrr)rZtemp_dirrrrrget_shell_temp_dirKs rcGsbddlm}ddl}td}z||jddWntk rDYnX|D]}|j||}qJ|S)zReturns the MySQL Shell's plugin directory The directory will be created if it does not exist yet Args: *argv: The list of directories to be added to the path Returns: The plugin directory path as string rrNZpluginsTr)pathlibrZos.pathrrrrr)rrrZ plugins_dirrrrrget_plugins_dirds rFc Cs|zt}|dkr4|dkr4t||dtjdddWStjj|t|d}| }W5QRX|sj| dWSt |d }| |W5QRXWdSWntj jk r}z8|r|jd krtd |d t|WY dSW5d}~XYntj jk rv}zht|j} d | krF|dkrFt} t|||tj| ddWY&Std |d t||rfW5d}~XYnXdS)ajDownloads a file from a given URL Args: url (str): The URL to the text file to download file_path (str): The file to store the downloaded file raise_exceptions (bool): Whether exceptions are raised Returns: The contents of the file decoded to utf-8 if no file is given or True on success or None on failure NZDarwinTz/private/etc/ssl/cert.pem)cafile) file_pathraise_exceptionsctx)Ztimeoutcontextzutf-8wbizCould not download file from z ERROR: ZCERTIFICATE_VERIFY_FAILED)r r download_filesslZcreate_default_contexturllibZrequestZurlopenURL_OPEN_TIMEOUT_SECONDSreaddecodeopenwriteerrorZ HTTPErrorcodeprintstrZURLErrorreasoninstall_ssl_certificates) ZurlrrrrZresponsedataZout_fileer-rrrrr!sF         r!cCstjtjBtjBtjBtjBtjBtjBtjB}t j t d}t dt j t}t dzt |Wntk rYnXt dt ||t dt ||t d|S)Nzcertifi-ca.pemzInstalling SSL certificate...z& -- removing any existing file or linkz2 -- creating symlink to certifi certificate bundlez -- setting permissionsz -- update complete)statS_IRUSRS_IWUSRS_IXUSRS_IRGRPS_IWGRPS_IXGRPS_IROTHS_IXOTHrrrrr+relpathcertifiwhereremoveFileNotFoundErrorsymlinkchmod)Z STAT_0o775Z shell_cafileZrelpath_to_certifi_cafilerrrr.s<   r.)NFN)r;r rZ urllib.errorr#Zurllib.requestr1r"rrVERSIONr$rrrr!r.rrrrs % :