3
NZ2              0   @   s|  d Z dZdZdZddlZddlZddlZddlZddlT ddl	T y(ddl
mZmZmZmZmZmZmZ W nN ek
r Z z2dejd kred nejd	 ejd
 W Y ddZ[X nX ddlT ddlmZ ed	ddfde d	ddfejejdUejejejej ej!ej"gZ#e$Z%dZ&dZ'dZ(da)dZ*dZ+dZ,dVddZ-dd Z.dd Z/dd Z0dd Z1g g g fdd Z2dWd!d"Z3ej4e yVej5eee ee#e$e6fe7e8e9fdZ:e:j;d#d$d%d&d'd(d)d*d+d,d-g
dd.\Z<Z=Z>Z?Z@ZAW n8 ejBk
r Z zejCejD e-  W Y ddZ[X nX ejEd/r"ejFd- d-Z(xe<D ]\ZGZHeGd0krTeIZ%dZ'ejJd1 e-  neGd2krdeHZ&neGdXkrejJd5 e-  ndeGd6krejJd7 e-  nHeGdYkreHjK jL Z(ejFe(se-  neGd:krdZ+neGd;kr(dZ,q(W ybejM dkrejCd<eeNeOf  ejd
 e:jPd	 de:_Qe:jR  ejSjTd=eUjV ZWejSjXeWrzyejYeW W n eZk
rx   Y nX ej[eW ej\ej] ej^d>ej_eW  ej^d	 e'rejM dkrejCd? e3d
 e`jad@dAZ@eebe$e@Zcecjdje  ejfej_dB e1ecjd ejfej_dC ejgdDdZhehrZe.ehZhejiehZjejdkrdejCdE n
ejCdF ejfej_dG e,recjkeld\ZmZnnecjkeld\ZmZnemsenrecjo secjp secjq re2ecjo ecjp ecjq  e/ecjd ecjdjre$ecjo ecjp ecjq  ejfej_dH ejfej_dI ejsecjdjte%e@de& ejfej_dJ e0ec eju Zvevrejfej_dK ejw \ZxZyxevD ]ZzejCdLez  qW ejfej_dMex  ecj{ Z|e|r ejfej_dN x0e|D ](ZzejCdOez  ejfej_dPe  qW e*rejfej_dQ ejfej_dR ejfd	 ejfd	 ejfdS e3d W n( e}k
rv   ejCdT e3d
 Y nX dS )Zz1.0z(Self Diagnse Utility and Healing Utilityz	hp-doctorzqTool checks for the deprecated, plug-in, dependencies, queues, permission issues and provides self diagnose steps    N)*)utilstuimodulequeuesos_utilsservicessmart_installZcupsext    )DependenciesChecknameTzUsage: %s [OPTIONS]ZsummaryRun in interactive mode:-i or --interactive (Default)optionFtextc             C   s2   | dkrt jtt t jt| ttt td d S )Nr      )r   Z	log_title	__title____version__Zformat_textUSAGE__mod__
clean_exit)typ r   /usr/share/hplip/doctor.pyusageM   s    r   c             C   sJ   t tkr| d7 } nt tkr"| d7 } tr.| d7 } tr>| dt 7 } | d7 } | S )Nz -i z -u z -n z -l%sz -s )MODEINTERACTIVE_MODEGUI_MODEPERFORM_IN_NON_INTERACTIVE_MODE	LOG_LEVEL)cmdr   r   r   append_optionsU   s    
r"   c             C   s^   t j  r@tdkr@| jj dkr,tjd n
tjd | j andatsZtj	d t
d tS )NFZsudozENTER SUDO PASSWORDzENTER ROOT/SUPERUSER PASSWORDTzV3 incorrect attempts. (or) Insufficient permissions(i.e. try with sudo user).
Exiting.   )r   Zrunning_as_rootVALID_AUTHENTICATIONpasswordObjZgetAuthTyper   titleZcheck_passwordlogerrorr   )corer   r   r   authenticatef   s    


r*   c             C   s   | j  }|tkr(tjdddgd\}}nd|tkrHtjdddgd\}}nD|tkrhtjdddgd\}}n$|tkr~tjd dS tjd dS |r|dkrd	}t	|}t
j|}|d
krdS tjtjd dS )NzPFound Plugin version mismatch. Press 'y' to re-install the plugin(y=yes*, n=no):ynzDPlugins corrupted. Press 'y' to re-install the plugin(y=yes*, n=no):zDPlugin's are missing. Press 'y' to install the plugin(y=yes*, n=no):zPlugin's already installedTz#No plug-in printers are configured.z	hp-pluginr   zSFailed to install Plugin. Please run 'hp-plugin' command to install plugin manuallyF)Zget_plugin_statusZPLUGIN_VERSION_MISMATCHr   enter_choiceZPLUGIN_FILES_CORRUPTEDZPLUGIN_NOT_INSTALLEDZPLUGIN_INSTALLEDr'   infor"   r   executebold)r)   Z
plugin_stsok
user_inputr!   stsr   r   r   install_plugin}   s(    


r4   c             C   sj   | j  rtjd tjd nHtjd| j| jf  tjtj	dddgd\}}| s^|dkrft
d d S )NzThis distro is supported.zNo Deprecated items are foundzCThis distro (i.e %s  %s) is either deprecated or not yet supported.zZThe diagnosis is limited on unsupported platforms. Do you want to continue?(y=yes*, n=no):r+   r,   r   )Zvalidate_distro_versionr'   debugr.   r(   Zdistro_nameZdistro_versionr   r-   Zredr   )r)   r1   r2   r   r   r   deprecated_check   s    
r6   c             C   s  t | rhtjtjd tjtjdt d  x6| D ].}d|krVtjd|df  q6tjd|  q6W t |rtjtjd tjtjdt d  x|D ]}tjd|  qW t |rtjtjd tjtjdt d  x|D ]}tjd|  qW d S )	NzMissing Required Dependencies-Zcupsz7'%s' package is missing or '%s' service is not running.z%'%s' package is missing/incompatible zMissing Optional DependencieszMissing Commandsz'%s' is missing)lenr'   r.   r0   r(   )Zrequired_dependenciesZoptional_dependenciesZmissing_cmdZpackages_to_installr!   r   r   r   display_missing_dependencies   s"    



r9   c             C   sD   t j  tr6tjd y
xqW W n tk
r4   Y nX tj|  d S )Nz'

Please close this terminal manually. )modZunlockInstanceDONOT_CLOSE_TERMINALr'   r.   KeyboardInterruptsysexit)Z	exit_coder   r   r   r      s    
r   zhl:gnid:f:wzsummary-onlyhelpz	help-restzhelp-manz	help-descinteractiveZguizlang=zlogging=r5   )Zhandle_device_printerZHPLIP_DEBUGz-nz*NON_INTERACTIVE mode is not yet supported.z-d-u--guizGUI is not yet supported.z-fz%Option from file is not yet supported-l	--loggingz-wz--summary-onlyz%s %sz%s/hp-doctor.logzUpgrade log saved in: %sz0Non Interactive mode should be run in root mode.Z	configurez
ui-toolkitz#

Checking for Deprecated items....z 

Checking for HPLIP updates....z
hp-upgradez^Failed to upgrade latest HPLIP. Is hp-upgrade already running (i.e. foreground or background)?z#Failed to locate hp-upgrade utilityz

Checking for Dependencies....z

Checking Permissions....z$

Checking for Configured Queues....z*

Checking for HP Properitery Plugin's....z<

Checking for 'CD-ROM'/'Smart Install' Detected Devices....zDSmart Install is Enabled in '%s' Printer. This needs to be disabled.z4
Refer link '%s' to disable Smart Install manually.
z!

Checking for Printer Status....z<'%s' Printer is either Powered-OFF or Failed to communicate.zTurn On Printer and re-run %sz9
Please reboot the system before performing any function.z
Diagnose completed...
zxMore information on Troubleshooting,How-To's and Support is available on http://hplipopensource.com/hplip-web/index.htmlz	User exit)r   r   r   F)r   )r   )rA   rB   )rC   rD   )~r   r   r   __doc__Zgetoptosr=   ZgetpassZbase.gZbase.stringsbaser   r   r   r   r   r   r	   ImportErroreargsZcheck_extension_module_envr'   Z	exceptionr>   Zinstaller.core_installZcheckr   ZUSAGE_SPACEZ
USAGE_MODEZUSAGE_OPTIONSZ
USAGE_HELPZUSAGE_LOGGING1ZUSAGE_LOGGING2ZUSAGE_LOGGING3r   r   r   Z
DEVICE_URIr   r    r$   ZIS_RESTART_REQr;   ZSUMMARY_ONLYr   r"   r*   r4   r6   r9   r   Z
set_moduleZModuler   ZUI_TOOLKIT_QT3ZUI_TOOLKIT_QT4ZUI_TOOLKIT_QT5r:   ZparseStdOptsZoptsZ
device_uriZprinter_namemodeZ
ui_toolkitlocZGetoptErrorr(   msggetenvZ	set_leveloaZNON_INTERACTIVE_MODEwarnlowerstripgeteuidZqueryStringZERROR_RUNNING_AS_ROOTZlockInstancequietZ	showTitlepathnormpathZpropZuser_dirZlog_fileexistsremoveOSErrorZset_logfileZ	set_whereZLOG_TO_CONSOLE_AND_FILEr5   r0   Zsys_confgetZ
MODE_CHECKZdepr)   Zinitr.   ZwhichZupgrade_cmdr/   r3   ZvalidateZDEPENDENCY_RUN_AND_COMPILE_TIMEZ
num_errorsZ	num_warnsZget_required_depsZget_optional_depsZget_cmd_to_runZinstall_missing_dependenciesZmain_functionr%   Z get_smartinstall_enabled_devicesZsmart_ins_dev_listZget_SmartInstall_tool_infoZurlZ	tool_nameZprinterZget_communication_error_devsZcomm_err_devr<   r   r   r   r   <module>   s&  (


































