3
NZ              (   @   sR  d dl mZ 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
mZmZ d dl
mZ d d	lT d d
lmZmZmZmZ d d	lT d dlmZ dZyd dlmZmZ W n ek
r   ejd Y nX dZedddfde dddfejd\d]d^ejejejej ej!ej"d_d`dadbgZ#e	j$d Z%d!Z&dcd#d$Z'd%d& Z(d'd( Z)d)d* Z*G d+d, d,e+Z,e-d-krNyej.e y4ejej/d.d d/d0d1d2d3d4d5d6d7d8d9g
\Z0Z1W nB ej2k
r Z3 z"ej4e3j5 e'  ej6d. W Y ddZ3[3X nX d:Z7ej8d;rd<Z7e9Z:dZ;dZ<xe0D ]\Z=Z>e=ddkr"e'  ne=d?kr6e'd@ ne=dAkrJe'dB ne=dCkrle?edDdE ej6d  ne=dekre>j@ jA Z7ne=dHkrd<Z7nte=dIkrdZ<nde=dfkreBZ:nTe=dgkreCZ:nDe=dhkre9Z:n4e=dQkrejDejEdR ej6d. ne=dSkrdZ;qW ejFe7s e'  e<s.ejG  ejHjIdTZJejDejEdUeJ  ejHjKeJryejLeJ W n$ eMk
r   ejDdVeJ  Y nX ejNeJ e;sejOejP nejOejQ e(  eRjSdWdXZTe,eUeVeTZWeWjXjY  eWjZe:e;\Z[Z\e[se\reWj]  nejDej^dY W n  e_k
r:   ej4dZ Y nX ejD  ejDd[ dS )i    )print_functionz15.1z Dependency/Version Check Utilityzhp-checkzyChecks dependency versions,permissions of HPLIP. (Run as 'python ./check.py' from the HPLIP tarball before installation.)N)PY3to_string_utf8)r   )*)utilstuiqueuessmart_install)cupsF)devicepmlzDevice library is not avail.T namezUsage: %s [OPTIONS]ZsummaryCompile-time check:-c or --compileoptionRun-time check:-r or --run or --runtimeCompile and run-time checks:-b or --both (default)b1. For checking for the proper build environment for the HPLIP supplied tarball (.tar.gz or .run),note%use the --compile or --both switches.c2. For checking for the proper runtime environment for a distro supplied package (.deb, .rpm, etc),use the --runtime switch.z	FUNC#(.*)notextc             C   s4   | dkrt jtt t jt| ttt tjd d S )Nr   r   )	r   	log_title	__title____version__Zformat_textUSAGE__mod__sysexit)typ r%   /usr/share/hplip/check.pyusageL   s    r'   c              C   sr  t jtt tjtjd xtjdD ]} tj|  q(W xtjdD ]} tj|  qFW xtjdD ]} tj|  qdW tj  xtjdD ]} tj|  qW xtjdD ]} tj|  qW xtjdD ]} tj|  qW xtjdD ]} tj|  qW xtjd	D ]} tj|  qW xtjd
D ]} tj|  q"W tj  tjd tjd tjd tjd tj  d S )Nz)Note: hp-check can be run in three modes:z1. Compile-time check mode (-c or --compile): Use this mode before compiling the HPLIP supplied tarball (.tar.gz or .run) to determine if the proper dependencies are installed to successfully compile HPLIP.z2. Run-time check mode (-r or --run): Use this mode to determine if a distro supplied package (.deb, .rpm, etc) or an already built HPLIP supplied tarball has the proper dependencies installed to successfully run.z3. Both compile- and run-time check mode (-b or --both) (Default): This mode will check both of the above cases (both compile- and run-time dependencies).zCheck types:z&a. EXTERNALDEP - External DependencieszMb. GENERALDEP  - General Dependencies (required both at compile and run time)z*c. COMPILEDEP  - Compile time Dependencieszd. [All are run-time checks]z PYEXT
SCANCONF
QUEUES
PERMISSIONzStatus Types:z    OKz?    MISSING       - Missing Dependency or Permission or Plug-inzE    INCOMPAT      - Incompatible dependency-version or Plugin-version)	r   r   r   r   loginfoboldr   Zformat_paragraph)lr%   r%   r&   
show_titleU   s6    



r,   c             C   s4   | dks| dkr,|dks"t ||r&dS dS ndS d S )NTr   -OKZINCOMPATZMISSING)check_version)ZInstalledstsZmin_verZInstalled_verr%   r%   r&   Status_Typey   s
    r0   c             C   s   d}| dks| dkrH|dkrt |d r8t |dr8d}qt |dsd}n| d	krd|dkr^d
}qd}n| dks|| dks|| dkr|dkrd}nf| dkr|dkrd}qd}nJ| dkrtdkr|dkrd}n,| dkr|dkrd}qd}n|dkrd|  }|S )Nr-   pyqtpyqt4r.   z2.3z2.2z/Fax is not supported if version is lessthan 2.3z>Python Programming is not supported if version is lessthan 2.2hpaioz%'hpaio found in /etc/sane.d/dll.conf'zP'hpaio not found in /etc/sane.d/dll.conf. hpaio needs to be added in this file.'ZcupsextZpcardexthpmudextz5'Not Found or Failed to load, Please reinstall HPLIP'r
   z*'CUPS may not be installed or not running'z'CUPS Scheduler is running'Zlibusbyesz"'libusb-1.0 needs to be installed'dbusz*'DBUS may not be installed or not running'z'%s needs to be installed')r/   IS_LIBUSB01_ENABLED)packageZInst_statusinstalled_vercommentr%   r%   r&   get_comment   s8    
r;   c               @   sr   e Zd ZeedfddZdd Zdd Zdd	 Zd
d Z	dd Z
dd Zdd Zdd ZedfddZdd ZdS )DependenciesCheckqt4c             C   sN   d| _ d| _t|||| _|| _g | _g | _g | _i | _d| _	g | _
d| _d S )Nr   r   )
num_errors	num_warnsZCoreInstallcore
ui_toolkitreq_deps_to_be_installedopt_deps_to_be_installedcmds_to_be_runcomm_error_devicesplugin_statussmart_install_devicesuser_grps_cmd)selfmodeZui_moderA   r%   r%   r&   __init__   s    zDependenciesCheck.__init__c             C   s  |dkr| j dkrd S | jdkr@| jdkr@| jdkr@|dkr@d S |dkrV| jdkrVd S |dkrl| jdkrld S |dkr| jdkrd S |dkr| j rd S | jjd	krd
| jkr|d%krd S |d d krd}nHtj|d r|d | jjkr | jj|d   }nd}nt	|d }t
|d  |d |}t|||}g g  }}| jj rx| jj|\}}| r|dkr|j| n.| jj||\}}| r|dkr|j| |d rd}	nd}	|dkr|dkst|drd| _ tjd|  |dkr|d krd| _|d kr8tjd!||d" |	|d |||f  ntjtjd#||d" |	|d |||f  |  jd$7  _x |D ]}
|
rv| jj|
 qvW |	dkrxD|D ]}|r| jj| qW n"x |D ]}|r| jj| qW d S )&Ncups-ddkTZqt5r=   Zqt3r1   r2   r3   Zrhelz5.r6   python-develpython-dbus
pyqt4-dbuslibnetsnmp-develgccmake	reportlab	policykit
sane-devel   r-         r   ZREQUIREDZOPTIONALr
   z1.4z6cups -ddk not required as cups version [%s] is => 1.4 r4   r.   z' %-20s %-60s %-15s %-15s %-15s %-10s %s   z. error: %-13s %-60s %-15s %-15s %-15s %-10s %s   )r6   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rL   )cups_ddk_not_reqrA   scanning_enabledr@   distrodistro_versionVer_Func_PatsearchZversion_funcZget_versionr0   r;   is_auto_installer_supportZget_dependency_dataappendr/   r(   debughpmudext_availr)   Zredr>   rD   rC   rB   )rI   Zsup_dist_versdZ	deps_infor9   ZStatusr:   packages_to_installZcommandsZpackage_typecmdpkgr%   r%   r&   Z__update_deps_info   sl    &


 
&*



z$DependenciesCheck.__update_deps_infoc             C   s   | j S )N)rB   )rI   r%   r%   r&   get_required_deps   s    z#DependenciesCheck.get_required_depsc             C   s   | j S )N)rC   )rI   r%   r%   r&   get_optional_deps  s    z#DependenciesCheck.get_optional_depsc             C   s   | j S )N)rD   )rI   r%   r%   r&   get_cmd_to_run  s    z DependenciesCheck.get_cmd_to_runc             C   s   | j S )N)rE   )rI   r%   r%   r&   get_communication_error_devs  s    z.DependenciesCheck.get_communication_error_devsc             C   s   | j S )N)rH   )rI   r%   r%   r&   get_user_grp_cmd  s    z"DependenciesCheck.get_user_grp_cmdc             C   s   | j S )N)rF   )rI   r%   r%   r&   get_plugin_status  s    z#DependenciesCheck.get_plugin_statusc             C   s   | j S )N)rG   )rI   r%   r%   r&   get_smart_install_devices   s    z+DependenciesCheck.get_smart_install_devicesFc       L   b      sz  d _ d _tjdd _tj }|r2tjtj tjddd} j	j
d} j	j} j	j|krt|r|t|d  }tjtjd j	j j	j j	j|f  tjd	 tjd
\}}tjd\}}	tjd
\}}
tjd||	|
 j	j j	jf  tjdtj   tjd tjdd}|rFtjdd}tjd|  tjd|   j	j rrtjd j	j j	jf  ntjd j	j j	jf  tj  tjtjd ytddj }W nF ttfk
r } z$tjd|j    jd7  _W Y d d }~X nX tj| tj  tjtjd yttj j!ddj }W n8 ttfk
rr } ztjd|j  W Y d d }~X nX tj| tj  tjtjd yttj j!ddj }W nF ttfk
r } z$tjd |j    j"d7  _"W Y d d }~X nX tj| tj#tjdd!d" _$tjd#d   j	j%j& j	j' |t(ksL|t)krt*t+t,t-t.d+}x|D ]x}tj| xf j	j%D ]Z} j	j%| d, || krzt/ fd-d. j	j%| d D rz j0|| j	j%|  qzW qbW  j$r@tjd/ tj1d0r@tjd1\}}|d2kr tjd3 n d4|kr6tjd5 n
tj| t2
r&t3j4rtjd6 t5j6d7g}|rtj7 }d|_x,t8|j9 D ]\}}|j:||d2 f qW |j;  n
tjd: tjd; t<j=d<t<j>}tjd=\}}tj  g }d }xZ|j? D ]N}y0|j@|}|jAd}|jAd>}|jB||f W n tCk
rD   Y nX qW tjD| |
rx|D ]}|\}}|jEd?sd|jEd@rqdy t5jF|\	}}} }!}"}#}$}%}&W n, tGk
r   d\	}}} }!}"}#}$}%}&Y nX tjtj| tjtjdBt|  dC}'|dDkrdE}'n|dFkr&dG}'tjdH|'  tjdI|  tj jHdJ|dK }(tj jI|(rtjdL|(  t<j=dMt<jJ})ytKt|(dNj }W n( tk
r   tjdO|(  dA}*Y n2X y|)j@|jAd}*W n tCk
r   dA}*Y nX tjdP|*  tjdQ| \}}tjdR|jLdSdA  |dDkr\|*r\dT|*kr\  jd7  _tjdU|  nZ|dFkr|*rdT|*kr  jd7  _tjdV|  n"|dkrtjdW   j"d7  _"t2
r|
rd }z.yt5jM|d d d dX}W n$ tGk
r   tjdY wdY nX |jNjdZtO}+|+tPtQfkr|sDd2d[lRmS}, |,jT }-|-jU }||,jVkrztV _W|+|,jPkrntjd\ n
tjd] n|||,jXkrtX _W|+tPkr  jd7  _tjd^ n  j"d7  _"tjd_ n,||,jYkr  j"d7  _"|,jY _Wtjd` | dk	ry|j  W n4 tGk
	r@ } ztj|jZ dA}.W Y d d }~X nX |j[ }.tjD|. |.	s~tjdb | j\|<   jd7  _n
tjdc nj| ddk	ry|j]t^j_\}/}.W n tGk
	r   Y nX |.	stjdb | j\|<   jd7  _n
tjdc W d |d k	
r
|j`  X tj  qdW n
tjde tjdf  jrtj1dg}0|0rtj jH|0dg}0tjdh|0 \}}|rt<j=dit<j>}1tjD| yd2d la}2W n. tbk

r   tjdj   jd7  _Y nX x*|j? D ]}3dX}4|1j@|3}|d k	
r|jc \} }5}6}7}8|2jd| |5\}9}:|9|2jekrftK|:}:d }yt5jM|:d d d dX}W n tGk
rV   
wY nX |jfst
qntjDdk 
qtgjh };d }x"|;D ]}|ji|:kr|jj}P qW tj jHdldmdnd7| |5}<tj jI|<stj jHdldodnd7| |5}<tj jI|<
rtjk|<\
}=}>}?}@}A}B}C}D}E}Ftj1dpdX}G|Grtjdq|G|<f \}}|jldr}HdA}IxZ|HD ]R}Jdp|JkrFdA|Jk	rFds|JkrFt<j=dt}K|Kj@|JrF|Idu |Kj@|JjAd }IqFW tjdvdw|dxdBdBdydz|<|If f  n(tjdvdw|dxdBdBdyd{|<|=d|@ f f  
qW tmjn  _ot jor^tjd}   jd7  _x> joD ]}tjd~|ddf  q&W ntjd   jd7  _|rntj|  j j"fS )NF	configurez
ui-toolkitzlibusb01-buildr   Zversions_listrZ   zZ%s-%s version is not supported. Using %s-%s versions dependencies to verify and install...zSYSTEM INFOzuname -r -v -ozuname -nz1 Kernel: %s Host: %s Proc: %s Distribution: %s %sz Bitness: %s bit
zHPLIP CONFIGURATIONZhplipversiondirshomezHPLIP-Version: HPLIP %szHPLIP-Home: %szMHPLIP-Installation: Auto installation is supported for %s distro  %s version zQHPLIP-Installation: Auto installation is not supported for %s distro  %s version z.Current contents of '/etc/hp/hplip.conf' file:z/etc/hp/hplip.confrz4Could not access file: %s. Check HPLIP installation.z3Current contents of '/var/lib/hp/hplip.state' file:z/var/lib/hp/hplip.statez4Plugins are not installed. Could not access file: %sz/Current contents of '~/.hplip/hplip.conf' file:z~/.hplip/hplip.confzCould not access file: %szscanner-build0z' %-20s %-20s %-10s %-10s %-10s %-10s %s<Package-name> <Package-Desc><Required/Optional><Min-Version><Installed-Version><Status>	<Comment>)zExternal DependencieszGeneral Dependencies
COMPILEDEPzPython ExtentionszScan Configuration   c                s   g | ]} j j| qS r%   )r@   Zselected_options).0x)rI   r%   r&   
<listcomp>n  s    z.DependenciesCheck.validate.<locals>.<listcomp>zDISCOVERED SCANNER DEVICESZ	scanimagezscanimage -Lr   z#Failed to get Scanners information.zNo scanners were identifiedzNo Scanner found.zDISCOVERED USB DEVICESusb
Device URIModelzNo devices found.zINSTALLED CUPS PRINTER QUEUESz(\S*): (.*)z	lpstat -vrY   z
cups-pdf:/zipp://r   r-   ZUnknownhpfaxZFaxhpZPrinterzType: %szDevice URI: %sz/etc/cups/ppdz.ppdzPPD: %sz\*NickName:\s*\"(.*)"rbzFailed to read %s ppd filezPPD Description: %szlpstat -p%szPrinter status: %s
zHP FaxzNIncorrect PPD file for fax queue '%s'. Fax queues must use 'HP-Fax-hplip.ppd'.zXIncorrect PPD file for a print queue '%s'. Print queues must not use 'HP-Fax-hplip.ppd'.z`Printer is not HPLIP installed. Printers must use the hp: or hpfax: CUPS backend for HP-Devices.TzDevice initialization failed.plugin)pluginhandlerz"Required plug-in status: Installedz"Optional plug-in status: Installedz&Required plug-in status: Not installedz&Optional plug-in status: Not installedz plug-in status: Version mismatchparzCommunication status: FailedzCommunication status: GoodZnetzNo queues found.Z
PERMISSIONlsusbz
%s -d03f0:zd^Bus\s([0-9a-fA-F]{3,3})\sDevice\s([0-9a-fA-F]{3,3}):\sID\s([0-9a-fA-F]{4,4}):([0-9a-fA-F]{4,4})(.*)zfNOT FOUND OR FAILED TO LOAD! Please reinstall HPLIP and check for the proper installation of hpmudext.z     Device URI: (Makeuri FAILED)/devbusprocgetfaclz%s %sz
filez.*:(.*) z#%-15s %-30s %-15s %-8s %-8s %-8s %sZUSBZRequiredr.   zNode:'%s' Perm:'%s'zNode:'%s' Mode:'%s'i  z)'CD-ROM'/'Smart Install' Detected Devicesz%-30s %-20s %s ZCD_ROM_EnabledzNeeds to disable Smart InstallzHPLIP not found.)rv   rw   rx   ry   rz   r{   r|   )r   r   )	r   Fr   r   r   r   r   r   rZ   )r   r   )r   r   )pr[   rd   sys_confgetrA   r(   Z	get_where	set_whereLOG_TO_FILEr@   Zget_distro_datar^   lenwarnr*   r]   r   headerr   runr)   Z
getBitnessra   Zdistro_nameopenreadIOErrorOSErrorerrorstrerrorr>   ospath
expanduserr?   Zto_boolr\   ZdependenciesupdateZhplip_dependenciesDEPENDENCY_RUN_AND_COMPILE_TIMEDEPENDENCY_RUN_TIMEZEXTERNALDEPZ
GENERALDEPr}   ZPYEXTZSCANCONFany$_DependenciesCheck__update_deps_infoZwhichdevice_availZpropZ	usb_buildr   ZprobeDevicesZ	Formatterlistitemsaddoutputrecompile
IGNORECASE
splitlinesr`   grouprb   AttributeErrorrc   
startswithZparseDeviceURIErrorjoinexists	MULTILINEr   replaceZDeviceZmqZPLUGIN_NONEZPLUGIN_REQUIREDZPLUGIN_OPTIONALZ	installerr   ZPluginHandleZ	getStatusZPLUGIN_INSTALLEDrF   PLUGIN_NOT_INSTALLEDPLUGIN_VERSION_MISMATCHmsgZgetDeviceIDrE   ZgetPMLr   ZOID_DEVICE_IDcloser4   ImportErrorgroupsZmake_usb_uriZ
HPMUD_R_OKZ	supportedr
   ZgetPrinters
device_urir   statsplitr	   Z get_smartinstall_enabled_devicesrG   )LrI   	time_flagis_quiet_modeZorg_log_locationr7   ZvrsZsupported_distro_vrsZStsZKernel_infoZ	Host_infoZ	Proc_infovrs   r   eZdep_dictZ	dep_checkdepZstatusZdevicesfre   ZddZ
lpstat_patZcups_printersZ
plugin_stspmatchZprinter_namer   Zback_endZis_hpr   ZmodelserialZdev_filehostZzcZportr   ZppdZnickname_patZdescr   r   Z	pluginObjZdeviceidZ
error_coder   Z	lsusb_patr4   ookr   ZvidpidZmfgZresult_codeZ	deviceuriZprintersZdevnodest_modest_inost_devst_nlinkst_uidst_gidst_sizest_atimest_mtimest_ctimer   Zgetfacl_out_listoutgZpatr%   )rI   r&   validate$  s   


 
"
 


>%











 

	






























&.



zDependenciesCheck.validatec             C   s  t jd tjtjd tjtjdtd  t| jdkrLtjd n:x8| jD ].}|dkrttjd||f  qTtjd|  qTW tjd	 tjtjd
 tjtjdtd
  t| jdkrtjd nx| jD ]}tjd|  qW | j	t
ks| j	tkrDtjd	 tjtjd tjtjdtd  tjd | jrtjd	 tjtjd tjtjdtd  x| jD ]}tjd|  qW tj \}}tjtjd|  tjd	 tjd| j  tjd| j  tj  d S )NZSUMMARYzMissing Required Dependenciesr-   r   Noner
   z7'%s' package is missing or '%s' service is not running.z%'%s' package is missing/incompatible r   zMissing Optional DependencieszNone
zPlug-in StatuszPlug-ins need to be installedz$SMART INSTALL/CD_ROM ENABLED DEVICESz%szSmart Install is enabled for these devices. Please disable Smart Install to enable device functionalities.

Refer link '%s' to disable Smart Install.
zTotal Errors: %dzTotal Warnings: %d)r   r   r(   r)   r*   r   rB   r   rC   rF   r   r   rG   r	   Zget_SmartInstall_tool_infor>   r?   )rI   rf   r   ZurlZ	tool_namer%   r%   r&   display_summary  sB    





z!DependenciesCheck.display_summaryN)__name__
__module____qualname__
MODE_CHECKINTERACTIVE_MODErK   r   ri   rj   rk   rl   rm   rn   ro   r   r   r   r%   r%   r%   r&   r<      s   C   9r<   __main__rZ   z
hl:gtcrbsihelpz	help-restzhelp-manz	help-desczlogging=r   Zruntimer   ZbothZfixr)   ZHPLIP_DEBUGrc   -h--helpz--help-restrestz
--help-manZmanz--help-descr   )end-l	--loggingz-gz-t-c	--compile-r	--runtime--run-b--bothz--fixzI

Note:- 'hp-check --fix' is deprecated. Please run 'hp-doctor' command

z-sz./hp-check.logzSaving output in log file: %szFailed to remove %s filerp   z
ui-toolkitzNo errors or warnings.z	User exitzDone.)r   r   r   F)r   r   r   F)r   r   r   F)r   r   r   F)r   r   r   F)r   r   r   F)r   r   r   F)r   )r   r   )r   r   )r   r   )r   r   r   )r   r   )`Z
__future__r   r   r   r!   __doc__r"   r   Zgetoptr   Zbase.sixextr   r   Zbase.gbaser   r   r   r	   Zinstaller.core_installZprntr
   r   r   r   r   r(   rc   ZUSAGE_OPTIONSZUSAGE_LOGGING1ZUSAGE_LOGGING2ZUSAGE_LOGGING3ZUSAGE_LOGGING_PLAINZ
USAGE_HELPZUSAGE_NOTESr    r   r_   r7   r'   r,   r0   r;   objectr<   r   Z
set_moduleargvZoptsargsZGetoptErrorr   r   r   r#   Z	log_levelgetenvr   r   r   Zfmtr   aprintlowerstripZDEPENDENCY_COMPILE_TIMEr   r)   r*   Z	set_levelZno_formattingr   abspathZlog_filer   remover   Zset_logfiler   ZLOG_TO_CONSOLE_AND_FILEr   r   r   rA   r   r   r   r@   Zinitr   r>   r?   r   ZgreenKeyboardInterruptr%   r%   r%   r&   <module>   s   


	$&    p

4

















