3 �Xj��@sRddlZddlZddlmZddlmZddlZddlmZddl m Z y ddl Z Wne k rrddl jZ YnXddlZejddd�Zeed �s�eje_ejZdd lmZdd lmZdd lmZdd lmZddlmZedddded�d�edded�d�edded�d�edded�d�edded�d�gZGdd �d e�Zd!d"�ZdS)#�N)�Option)� OptionParser)�rpclib)�sstrzrhn-client-toolsT)Zfallback�ugettext)�config)� up2dateAuth)� up2dateErrors)� up2dateLog)� up2dateUtilsz-vz --verbose�countzShow additional output)�action�default�helpz--proxyZstorezSpecify an http proxy to use)r rz --proxyUserz:Specify a username to use with an authenticated http proxyz--proxyPasswordz:Specify a password to use with an authenticated http proxyz--debug� store_truez&Enable debug output (network requests)c@sdeZdZdd�Zdd�Zdd�Zdd�Zd d �Zd d �Zd d�Z dd�Z e dd��Z e dd��Z dS)�RhnClicCs"tttj�d�|_d|_d|_dS)N)Z option_list�version)r� _optionsTabler�_RhnCli__versionString� optparser�options�args)�self�r�/usr/lib/python3.6/rhncli.py�__init__MszRhnCli.__init__cCsBtt_y |j�tj|j�pd�W�ntk rZtjjt t d���tjd�Y�n�t j j k r�}zDtjjt t d�tj�d��tjjt t d���tjd�WYdd}~X�n�tk r�tjjt t d�tj�d��tjd�Y�nBtjk �rhtj�d}|dk�s6tt|��dk�rLtjjt t d���ntjjt t d�|��Yn�tk �r�tjjt t d �tj�d��tjd�Yn�tk �r��Yn�tjk �r�tjjt t d �tj�d��tjd�YnBtjk �r<tjjt d ttj�d���tjd �YnXdS) Nrz Aborted. �zThere was an SSL error: %s zqA common cause of this error is the system time being incorrect. Verify that the time on this system is correct. z$An unexpected OS error occurred: %s z1A connection was attempted with a malformed URI. z5A connection was attempted with a malformed URI: %s. z%There was some sort of I/O error: %s z&There was an authentication error: %s zXMLRPC ProtocolError: %s �)�exceptionHandler�sys� excepthook� initialize�exit�main�KeyboardInterrupt�stderr�writer�_�requests� exceptionsZSSLError�exc_info�OSErrorrZMalformedURIError�len�str�IOError� SystemExitr ZAuthenticationError� xmlrpclibZ ProtocolError)r�errr�runTs<      z RhnCli.runcCsn|jj�\|_|_tj|jj�tj�dkrRt d�t j d}|j |�t j d�|jjrb|j�|j�dS)NrzYou must be root to run %sr)r� parse_argsrrr�_RhnCli__setDebugLevel�verbose�os�geteuidr'r�argv�_warning_dialogr"�debug�_initialize_debug_network_logs�_RhnCli__updateProxyConfig)rZrootWarningMsgrrrr!xs   zRhnCli.initializecCst�dS)N)�NotImplementedError)rrrrr#�sz RhnCli.mainc Csxddl}yddlm}Wn tk r8ddlm}YnXd|_|j�|j�j|j �|jd�}|j|j �d|_ dS)zF Enables logging of all all https requests to console rN)�HTTPConnectionrzrequests.packages.urllib3T) �loggingZ http.clientr>� ImportErrorZhttplibZ debuglevelZ basicConfigZ getLoggerZsetLevel�DEBUGZ propagate)rr?r>Z requests_logrrrr;�s  z%RhnCli._initialize_debug_network_logscCs t|�dS)N)�print)r�messagerrrr9�szRhnCli._warning_dialogcCsxtj�}|jjr,|jd|jj�|jdd�|jjrP|jd|jj�|jdd�|jjrt|jd|jj�|jdd�dS)z�Update potential proxy configuration. Note: this will _not_ save the info to up2date's configuration file A separate call to config.initUp2dateConfig.save() is needed. Z httpProxyZ enableProxyr� proxyUserZenableProxyAuth� proxyPasswordN)r�initUp2dateConfigr�proxy�setrDrE)r�cfgrrrZ__updateProxyConfig�s  zRhnCli.__updateProxyConfigcCstj�}|j�dS)zM Saves the current up2date configuration being used to disk. N)rrFZsave)rrIrrr� saveConfig�szRhnCli.saveConfigcCstd�tj�}|S)Nzp%%prog (Spacewalk Client Tools) %s Copyright (C) 1999--2014 Red Hat, Inc. Licensed under the terms of the GPLv2.)r'r r)Z versionStringrrrZ__versionString�s zRhnCli.__versionStringcCstj�}|d||d<dS)Nr:)rrF)�levelrIrrrZ__setDebugLevel�szRhnCli.__setDebugLevelN)�__name__� __module__� __qualname__rr2r!r#r;r9r<rJ� staticmethodrr4rrrrrKs$ rcCs�tj�}tjjttd�d��t|d�rPtjjt|j�d�|j |||�n&tjjtt |�d��|j |||�tjjttd�d��dS)NzAn error has occurred:� �errmsgz)See /var/log/up2date for more information) r ZinitLogrr%r&rr'�hasattrrQZ log_exceptionr-)�type�value�tb�logrrrr�s r)rr6ZoptparserrZrequests.exceptionsr(ZrhnrZrhn.i18nrr0r@Z xmlrpc.clientZclient�gettextZ translation�trRrr'Zup2date_clientrrr r r r�objectrrrrrr�"s@                z