3
NZH              O   @   sb  d dl T d dlmZ d dlmZ ddlZddlZyddlZdZ	W n e
k
r\   dZ	dZY nX ejdejZdZd Zd Zd	Zd
ZdZdZdZeZdZdddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUgGZej  dVdWdWdWdXdXdWdWdWdWdWdWdWdWdWdWdWdWdYdYdYdWdWdWdWdWdZdZd[d\dWdWd[dWdWdWdYdYdWdWdWdWdWdWdWdWdWdWdWdWdWdWdWdWd]dWdWdWdWdWdWdWdWdWdWd^AZdZd Zd	Zeeeeeeeeeeeeeeeeed_Zd`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdtdudvdwdxdydzd{d|gZej  d}d~dddZ dd Z!dd Z"G dd dZ#dS )   )*)utils)
to_unicode    NTFz(\d+)                  Z	UndefinedZUnsupported
PostscriptDJGenericVIPLJMonoLJColorLJFastRaster
LJJetReadyDJ350DJ540DJ600DJ6xx
DJ6xxPhotoDJ630DJ8xxDJ8x5DJ850DJ890DJ9xxDJ9xxVIPDJ3600DJ3320DJ4100AP2xxxAP21xxAP2560PSP100PSP470	LJZjsMono
LJZjsColorLJm1005QuickConnectDJ55xx	OJProKx50LJP1XXXStablerViperPlusVIPViperMinusVIPViperPlusTrimViperMinusTrimCorbettPythonOJ7000ZPyramid	Pyramid15Python10MimasMimas15Mimas17
StingrayOJ
CopperheadCopperheadXLPCopperhead12CopperheadIPHCopperheadIPH15PyramidRefresh15CopperheadIPH17AmpereZPython11ZSaipanZPyramidPlusHbpl1KapanMimasTDR	Saipan15BGemstoneSPDOfficejetProAsizeCLECLE17SPDOfficejetProBsizePyramidRefresh17pspcl3pclxllidilzjszxsjpeghbpl1)Ar   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r6   r7   r8   r9   r:   r5   r;   r<   r=   r>   r?   r@   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rA   rL   )rN   Zpcl5Zpcl6Zpcl5eZpclrO   rM   rP   rQ   ZzjstreamrR   ZzxstreamrS   ZjpgZjetreadyZjrrT   ZLargeFormatSuperBZLargeFormatA3Z
CoverMediaZ	FullBleedZDuplexZNormalZ
Apollo2000Z
Apollo2200Z
Apollo2500ZNoPhotoModeZNoPhotoBestHiresModesZNo1200dpiNoSensorZNoFullBleedZ4x6FullBleedZ
300dpiOnlyZGrayscaleOnlyZ
NoAutoTrayZNoEvenDuplexZNoAutoDuplexZNoCDDVDZNoMaxDPIZSmallMarginsZTrimZ4800x1200dpiZAdvancedZMonoZColorZ
AutoDuplexZK10ZLaserJetZPSCZHPZMFP)ZlaserjetZpschpZmfpc             C   s   | j  j }d|kr"|jdd}n,|jdrB|dd  jdd}n|jdd}g }x<|j D ]0}tj|rv|j| q\|jtj	||j
  q\W d|krdj|S ddj| S d S )NZapollo_ rU   r   zHP )lowerstripreplace
startswithsplitpat_prod_numsearchappendMODEL_UI_REPLACEMENTSget
capitalizejoin)modelZmlzyx rh   /usr/share/hplip/base/models.pynormalizeModelUIName  s    


rj   c             C   sp   t | tsDy| jd} W n* tk
rB   tjd| t| f  Y nX tj| j	ddj	ddj	ddj	dddS )	Nzutf-8z%Failed to encode model = %s  type=%s rW   rV   __~ /)

isinstancestrencodeUnicodeEncodeErrorlogerrortyper   ZxstriprZ   )rd   rh   rh   ri   normalizeModelName(  s    
rv   c               @   sT   e Zd ZdddZdddZddd	Zd
d Zdd Zdd Zdd Z	dddZ
dS )	ModelDataNc          '   C   s  |d krt j| _n|| _i | _| j  tjd| _tjdtj| _	tjd| _
tjd| _tjd| _tjj| jdtjj| jddftjjtj d	d
dtjjtj d	d
ddfg}x:|D ]\| _| _tjj| jrP qW d!\| _| _tjd tttttttttttttttttttttttttttttttttttttd%| _tttttttttttttttttttttttttttttd| _tjdtjttjdtjttjdtjttjdtjttjdtjttjdtjttjdtjttjdtjttjdtjttjdtjttjdtjttjdtjttjdtjttjdtjttjdtjttjdtjttjdtjttjdtjttjd tjti| _i | _ d S )"Nz	^\[(.*)\]z^\%include (.*)z	^\%(.*)\%z^([^=]+)=(.*)z^(\d{1,2})/(\d{1,2})/(\d{4,4})z
models.dat
unreleasedzunreleased.datdataZmodelsz Unable to locate models.dat file)%z
align-typez
clean-typezcolor-cal-typez	copy-typezembedded-server-typezfax-typezfw-downloadZiconzio-mfp-modezio-modez
io-supportzjob-storagezmonitor-typezlinefeed-cal-typezpanel-check-typez
pcard-typeZpluginzplugin-reasonzpower-settingszpq-diag-typezr-typez	scan-typezscan-srczstatus-battery-checkzstatus-dynamic-counterszstatus-typezsupport-subtypezsupport-releasedzsupport-typezsupport-verz
tech-classztech-subclassz	tech-typezusb-pidzusb-vidzwifi-configzppd-name)zdev-filezfax-urizscan-urizis-hphostzstatus-desczcups-printersserialzerror-statezdevice-stateZpanelz
device-urizpanel-line1zpanel-line2zback-endZportZdeviceidzcups-urizstatus-codeZrsZrrZrgrZduplexerzsupply-doorZrevisionz
media-pathztop-doorz
photo-trayz^r(\d+)-agent(\d+)-kindz^r(\d+)-agent(\d+)-typez^r(\d+)-agent(\d+)-skuz^agent(\d+)-descz^agent(\d+)-virginz^agent(\d+)-dvcz^agent(\d+)-kindz^agent(\d+)-typez^agent(\d+)-idz^agent(\d+)-hp-inkz^agent(\d+)-health-descz^agent(\d+)-health$z^agent(\d+)-knownz^agent(\d+)-levelz^agent(\d+)-ackz^agent(\d+)-skuz^in-tray(\d+)z^out-tray(\d+)z^model(\d+))NN)!ZpropZ
models_dir	root_path_ModelData__cachereset_includesrecompilesecIincinc_lineeqdateospathrc   getcwdreleased_datunreleased_datexistsrs   rt   TYPE_INT	TYPE_BOOLTYPE_STRTYPE_BITFIELDTYPE_HEX	TYPE_LISTFIELD_TYPESFIELD_TYPES_DYN
IGNORECASERE_FIELD_TYPES
TYPE_CACHE)selfr}   filesrh   rh   ri   __init__3  s    



zModelData.__init__Tc             C   sD   t jj| jr>| j| j | jd k	r>t jj| jr>| j| j | jS )N)r   r   r   r   read_sectionr   r~   )r   rx   rh   rh   ri   read_all_files  s
    zModelData.read_all_filesFc             C   st  d\}}|d k	rB|j  }|r0tjd||f  ntjd||f  |rN| j}n| j}yt|}W n4 tk
r } ztjd||jf  dS d }~X nX x|j	 }	|	sP |	d dkrq|	d dkr8|r|d k	rP | j
j|	}
|
d k	rd	}|
jd
j  }|d k	r||k }}|r|d k	r.tjd||f  i ||< q|	d dkr | jj|	}
|
d k	r|
jd
}tjd|  | jjtjjtjj|| q|r | jj|	}
|
d k	r |
jd
}tjd|  y| j|  W nH tk
r   x0| jD ]}| j||d	rP qW tjd|  Y nX |r| jj|	}
|
d k	r|
jd
}|
jd}| j||}||| |< qW |j  |S )NFz%Searching for include [%s] in file %sz%Searching for section [%s] in file %szI/O Error: %s (%s)r   #;[Tr   zFound section [%s] in file %s%z*Found include file directive: %%include %szFound include directive %%%s%%zInclude %%%s%% not found.r   )FF)r   r   )rX   rs   debug_ModelData__includesr~   openIOErrorrt   strerrorreadliner   r^   groupr   match_ModelData__include_filesr_   r   r   rc   dirnamer   KeyErrorr   r   convert_dataclose)r   filenameZsectionZ
is_includefoundZ
in_sectioncachefdeliner   r   Zinc_fileZinc_sectr   keyvaluerh   rh   ri   r     s|    







zModelData.read_sectionc             C   s   g | _ i | _d S )N)r   r   )r   rh   rh   ri   r     s    zModelData.reset_includesc          	   C   s   |j  }y
| j| S    tjd|  tjd| j  | j| j|rP| j| S | jd k	rtjj	| jrtjd| j  | j| j|r| j| S i S d S )NzCache miss: %szReading file: %s)
rX   r~   rs   r   r   r   r   r   r   r   )r   rd   rh   rh   ri   __getitem__  s    


zModelData.__getitem__c             C   s   | j S )N)r~   )r   rh   rh   ri   
all_models3  s    zModelData.all_modelsc             C   s   y
| j | S  tk
r   y
| j| S  tk
r   y
| j| S  tk
r   x:t| jj D ](\}}|j|}|d k	r^|| j|< |S q^W Y nX Y nX Y nX tj	d|  d S )Nz4get_data_type(): Field type lookup failed for key %s)
r   r   r   r   listr   itemsr   rs   rt   )r   r   Zpattypr   rh   rh   ri   get_data_type7  s     




zModelData.get_data_typec             C   s6  |d kr| j |}|ttfkr\yt|}W n. ttfk
rX   tjd||f  d}Y nX n|tkrpt	j
|}n|tkrdd |jdD }n|tkrtr| jj|}|d k	rt|jd}t|jd}t|jd}tj|||}nJ|tkr2yt|d	}W n0 ttfk
r0   tjd
||f  d}Y nX |S )Nz!Invalid value in .dat file: %s=%sr   c             S   s   g | ]}|r|qS rh   rh   ).0rg   rh   rh   ri   
<listcomp>Z  s    z*ModelData.convert_data.<locals>.<listcomp>,r   r   r      z%Invalid hex value in .dat file: %s=%s)r   r   r   int
ValueError	TypeErrorrs   rt   r   r   Zto_boolr   r\   	TYPE_DATEdatetime_availr   r^   r   datetimer   )r   r   r   r   r   ZmonthZdayZyearrh   rh   ri   r   K  s6    


zModelData.convert_data)N)T)NF)N)__name__
__module____qualname__r   r   r   r   r   r   r   r   rh   rh   rh   ri   rw   2  s   



\rw   )$grm   r   Zsixextr   os.pathr   r   r   r   ImportErrorr   r   r]   ZTYPE_UNKNOWNZTYPE_STRINGr   r   r   r   r   r   ZTYPE_URIr   ZTECH_CLASSESsortZTECH_CLASS_PDLSZPDL_TYPE_PCLZPDL_TYPE_PSZPDL_TYPE_HOSTZ	PDL_TYPESZTECH_SUBCLASSESr`   rj   rv   rw   rh   rh   rh   ri   <module>   s  

