JVc@sKddlZddlZddlZddlZddlZddlZddlZddlTddlm Z m Z m Z ddl m Z dZyejdZdZedk rejdrejd\ZZed 7ZneejddZ?dZ@d-ZAd.ZBd/ZCd/ZDdZEd ZFdZGd ZHdZIdZJd-ZKd.ZLd0ZMd1ZNd2ZOd3ZPd4ZQd5ZRd6ZSd7ZTd8ZUd9ZVd:ZWd;ZXd<ZYd=ZZd>Z[d?Z\d@Z]dAZ^dBZ_dCZ`dDZadEZbdFZcdGZddHZedIZfdJZgdKZhdLZidMZjdNZkdOZldPZmdQZndRZodSZpdTZqdUZrejsdVejtZuejsdWejvZwejsdXejvZxddYZydZZzd[Z{d\Z|d]Z}ejsd^ej~Zd_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqgZxCee jjD],ZdreZeekr8ejeq8q8WeZejdsdtdugdvZdwZdxZdyZdzZd{Zd|dd}Zd~ZdZdZdZdZdZdZdZdZdZdZdZdZdZdddZddZdZdZdZddZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdS(iN(t*(tutilstmodelstos_utils(tPY3s!~`!@#$%^&*()=+[]{}()\/,.<>?'";:| tLANGtCt.s.UTF-8t HPLIP_BUILDs=CUPSEXT could not be loaded. Please check HPLIP installation.iiiiiiidieifigihiiijikilimiiii@i@i@i@i@i@i@i@i @i @i @i @i @i@iiiiiiiiiiiiii i i i i iiiiiiiiiiiiiiiiiiii i iis\*NickName:\s*\"(.*)"s/^loglevel\s?(debug|debug2|warn|info|error|none)s.*hp-(.*?)(-.*)*\.ppd.*cCsk|dkrg}ntjjd|}x9|D]1}tjj|d}tjj|r2|Sq2WdS(s Returns the CUPS ppd path (not the foomatic one under /usr/share/ppd). Usually this is /usr/share/cups/model. t;s cups/modelN(tNonetproptppd_search_pathtsplittostpathtjointexists(taddtional_pathst search_pathsRtppd_path((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyt getPPDPaths   c CsZg}g}g}tjjdr4|jdntjjdrV|jdnx$|D]}|jtj|q]Wx|D]}t|d}x|D]z}|jd rt|dkry|j \}}} } Wnt k rqnX|dkr|j|qqqWqW|jd |jd |jd |jd |S(sk Scan all /etc/cups/*.convs and /usr/share/cups/mime files for allowable file formats. s /etc/cupss/etc/cups/*.convss/usr/share/cups/mimes/usr/share/cups/mime/*.convstrt#isapplication/octet-streamsapplication/vnd.cups-postscripts image/x-bmpstext/cppsapplication/x-pythonsapplication/hplip-fax(sapplication/octet-streamsapplication/vnd.cups-postscript( RRRtappendtextendtglobtopent startswithtlenR t ValueError( tpathstallowable_mime_typestfilesRtft conv_filetlinetsourcetdesttcosttprog((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pytgetAllowableMIMETypess0   "      cCs|jdr-tj|djd}nt|djd}y%tj|jdjd}Wnt k rd}nX|S(Ns.gzRisutf-8it( tendswithtgziptGzipFiletreadRt nickname_pattsearchtdecodetgrouptAttributeError(R"tnicknametdesc((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pytgetPPDDescriptions%  c Cst\}}}i}|dkr|dkrtjdd}tjd|xPtj|dddtD]`}t|}d |kpd |j kpd |kso|||shp s.gzs.ppdsdrv:s-pcls-pcl3s -jetreadys-zxss-zjss-pss -postscripts-jrs-lidls-lidils-ldls-hpijss-%ss-seriess seriest_seriescCs3|j}x tD]}|j|d}qW|S(NR*(RGtSTRIP_STRINGS2treplace(tmodeltx((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyt stripModel2gs  cCs3|j}x tD]}|j|d}qW|S(NR*(RGt STRIP_STRINGSRd(ReRf((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyt stripModelps  cCs.tjdi}i}tj}tjd|xz|D]r}ttjj|}t||||<||dkrtjd|||fnt |||}q:Wtjd|xh|D]`}|||krxG|D].}tjj|tjj|krPqqW||||| dkr>| ^q>fqlqoqfqfWtj|t|} | dkr tjd |ttt||j} tj| t| } | rx| D]\}} tj|}|dk rtjd|y|j dj d}Wnt k r]g}nXt j rsd|kst jrd|kst j rd|ksd |kr|j|g|D]} | r| dkr| ^qfqqqWntj|t|} n| dkr1tjd t|dS| dkr\tjd |ddd fStjd| xtjtjtjgD]m} xd|D]\\}}xM|D]E}tjj|tj| krtjd||f|d fSqWqWqWtjd| xRddgD]D} x;|D]3\}}| |kr"tjd||d fSq"WqWtjd|ddd fS(Nsppd-nameis!Matching PPD list to model %s...isFound match: %sit-thpijstpssFNo PPD found for model %s using new algorithm. Trying old algorithm...s.No PPD found for model %s using old algorithm.sOne match found.R*s?%d matches found. Searching based on PDL: Host > PS > PCL/OthersSelecting '-%s' PPD: %ss<%d matches found. Searching based on Filters: HPCUPS > HPIJSthpcupssSelecting PPD: %ss<No specific PDL located. Defaulting to first found PPD file.(RtnormalizeModelNameRBRgRCRDtppd_patRjR R2R R3R t hpcups_buildt hpijs_buildRRRSR|Rititemsterrort PDL_TYPE_HOSTt PDL_TYPE_PSt PDL_TYPE_PCLt PDL_TYPES(tmqReRMtppd_nameRpRvR"Rjtpdlstpt num_matchestmatches2t num_matches2tdtpdl_listRf((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyt getPPDFile2s~       * E   !     * E       cCs9z(t}d}d}tjd|tjftjr|jdttkr_d}d}nr|jdttkp|jdtt krd}d}n3|jdtt krd }d }n d}d}n|jdttkrd }d }n|jdttkp(|jdtt kr:d }d}n|jdtt krad}d}n d}d}g}x<t j t jdddddtD]}|j|qWtjd|xa|D]H}|j|dkot||kr|}tjd|PnqWtjd|Wd|||fSX(Ns HP Fax hpcupss HP-Fax-hpcupss4Searching for fax PPD for model %s hpcups_build =%dsfax-typesHP-Fax3-hpcupssHP Fax3 hpcupssHP-Fax2-hpcupssHP Fax2 hpcupssHP-Fax4-hpcupssHP Fax4 hpcupss HP-Fax3-hpijss HP Fax3 hpijss HP-Fax2-hpijss HP Fax2 hpijss HP-Fax4-hpijss HP Fax4 hpijss HP-Fax-hpijss HP Fax hpijsR7R8R9s HP-Fax*.ppd*R:sppds=%sisFound fax PPD: %ss8Unable to locate the HPLIP Fax PPD file: %s.ppd.gz file.(R RCRDR RRBt FAX_TYPE_NONEtFAX_TYPE_MARVELLt FAX_TYPE_SOAPtFAX_TYPE_LEDMSOAPt FAX_TYPE_LEDMRRERARFRtfindR6R(RRetfax_ppdtnicktexpected_fax_ppd_nameRMR"((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyt getFaxPPDFile*sN  0    0  . 'cCsd}yt|d}WnCtk r=tjd|nxtk r^tjd|nWXxS|D]K}tj|}|dk rf|jdj }tj d||SqfWtj ddS( Ns/etc/cups/cupsd.confRs %s not found.s%s: I/O error.isCUPS error_log LogLevel: %ss CUPS error_log LogLevel: unknowntunknown( RtOSErrorRCRtIOErrortpat_cups_error_logRjR R2RGRD(t cups_confR"tlRYtlevel((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pytgetErrorLogLevel^s     ic CsEg}d|}d}yt|d}Wn)ttfk rTtjd|dSX|t|djkr4tj}t}xt r0|j } || krt }x#t |r|j |j qW|j | jt ||kr-Pq-q|r|j| jt ||kr-Pq-qqWndj|SdS(Ns[Job %d]s/var/log/cups/error_logRs*Could not open the CUPS error_log file: %sR*s (RRRRCRR.RtQueuetFalseRFtreadlineRRRBtstriptputR( tjob_idt max_linest cont_intervaltrettsRR"tqueuet job_foundR$((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pytgetPrintJobErrorLogrs2     cCs,tj}|dkr(tjdn|S(Ns$The CUPS default printer is not set.(RHtgetDefaultPrinterR RCRD(R((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyRs  cCstdtj|S(NsOYou do not have permission to set the default printer. You need authentication.(tsetPasswordPromptRHtsetDefaultPrinter(t printer_name((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyRs cCstdt|tS(NsVYou do not have permission to accept jobs on a printer queue. You need authentication.(RtcontrolPrintertCUPS_ACCEPT_JOBS(R((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pytaccepts cCstdt|tS(NsVYou do not have permission to reject jobs on a printer queue. You need authentication.(RRtCUPS_REJECT_JOBS(R((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pytrejects cCstdt|tS(NsMYou do not have permission to start a printer queue. You need authentication.(RRtIPP_RESUME_PRINTER(R((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pytstarts cCstdt|tS(NsLYou do not have permission to stop a printer queue. You need authentication.(RRtIPP_PAUSE_PRINTER(R((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pytstops cCstdt|tS(NsBYou do not have permission to purge jobs. You need authentication.(RRtIPP_PURGE_JOBS(R((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pytpurges cCs/|tttttfkr+tj||SdS(Ni(RRRRRRHR(Rtcups_op((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyRscCs|s dStj|S(N(RHtopenPPD(tprinter((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyRscCs tjS(N(RHtclosePPD(((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyRscCs|s dStj|S(N(RHtgetPPD(R((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyRscCs tj|S(N(RHt getPPDOption(toption((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyRscCs tjS(N(RHtgetPPDPageSize(((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyRscCs tjS(N(RHt getPrinters(((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyRs cCstj||S(N(RHtgetJobs(tmy_jobt completed((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyRscCs tj|dtj|dS(Nii(RHR(R((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyt getAllJobsscCs tjS(N(RHt getVersion(((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyRscCs tjS(N(RHR@(((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyR@scCs tjS(N(RHt getServer(((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyRscCsotd|dk r&tj||Stjdd}x0|D](}|j|kr?tj|j|Sq?WtS(NsDYou do not have permission to cancel a job. You need authentication.i(RR RHt cancelJobRtidR&R(tjobidR&tjobsR]((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyRs   cCs tjS(N(RHt resetOptions(((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyRscCs tj|S(N(RHt addOption(R((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyRscCs tjS(N(RHt getOptions(((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyR scCs tj|S(N(RHtduplicateSection(tsection((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyR scCsctjj|r[tsH|jd}|jd}|jd}ntj|||SdSdS(Nsutf-8i(RRRRtencodeRHtprintFileWithOptions(Rtfilenamettitle((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyt printFilescCswtdtjd||||||f|r[tjj| r[tjd|dStj||||||S(NsEYou do not have permission to add a printer. You need authentication.s.addPrinter('%s', '%s', '%s', '%s', '%s', '%s')sPPD file '%s' not found.isPPD file not found(isPPD file not found( RRCRDRRRRRHt addPrinter(Rt device_uritlocationtppd_fileRetinfo((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyRs  cCstdtj|S(NsHYou do not have permission to delete a printer. You need authentication.(RRHt delPrinter(R((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyR's cCs9tdtjdt}d||f}tj|S(NsHYou do not have permission to enable a printer. You need authentication.t cupsenables%s %s(RRtwhichRFRtexecute(Rt cmd_full_pathtcmd((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyt enablePrinter+s cCs tjS(N(RHt getGroupList(((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyR1scCs tj|S(N(RHtgetGroup(R2((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyR4scCs tj|S(N(RHt getOptionList(R2((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyR7scCstj||S(N(RHt getOption(R2R((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyR:scCstj||S(N(RHt getChoiceList(R2R((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyR=scCstj|||S(N(RHt getChoice(R2Rtchoice((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyR@scCs tjS(N(RHt setOptions(((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyRCscCs tj|S(N(RHt removeOption(R((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyRFscCs tj|S(N(RHtsetPasswordCallback(tfunc((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyRIscCs tj|S(N(RHR(tprompt((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyRLscCstj||S(N(RHtfindPPDAttribute(tnametspec((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyROscCs tjS(N(RHtreleaseCupsInstance(((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pyRRsc Gsd}x|dkr|d7}||\}}|tkrAPq t|dkr |tkrptjdq|dkr|jdqddlm}|j|dq q W||fS( NiiisSCould not connect to CUPS Server due to insufficient privileges.Try with valid usertqt3s]Could not connect to CUPS Server due to insufficient privileges.

Try with valid useri(tui_utils(t IPP_FORBIDDENRtINTERACTIVE_MODERCRt FailureUItui4R( toperation_functmodet ui_toolkittui_objt cups_op_argstcnttresultt status_strR((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pytcups_operationVs     (Rtos.pathR,trettimettempfileRtbase.gtbaseRRRt base.sixextRtINVALID_PRINTER_NAME_CHARStgetenvtcurrent_languagetnewlangR tcountR tencodingtenvironRHt ImportErrorRCtwarnRktexittIPP_PRINTER_STATE_IDLEtIPP_PRINTER_STATE_PROCESSINGtIPP_PRINTER_STATE_STOPPEDtPPD_UI_BOOLEANtPPD_UI_PICKONEtPPD_UI_PICKMANYt UI_SPINNERtUI_UNITS_SPINNERtUI_BANNER_JOB_SHEETSt UI_PAGE_RANGEtUI_JOB_STORAGE_MODEtUI_JOB_STORAGE_PINtUI_JOB_STORAGE_USERNAMEtUI_JOB_STORAGE_IDtUI_JOB_STORAGE_ID_EXISTStUI_INFORRRtCUPS_GET_DEFAULTtCUPS_GET_PRINTERStCUPS_ADD_MODIFY_PRINTERtCUPS_DELETE_PRINTERtCUPS_GET_CLASSEStCUPS_ADD_MODIFY_CLASStCUPS_DELETE_CLASSRRtCUPS_SET_DEFAULTtCUPS_GET_DEVICESt CUPS_GET_PPDSt CUPS_MOVE_JOBtCUPS_AUTHENTICATE_JOBtIPP_JOB_PENDINGt IPP_JOB_HELDtIPP_JOB_PROCESSINGtIPP_JOB_STOPPEDtIPP_JOB_CANCELLEDtIPP_JOB_ABORTEDtIPP_JOB_COMPLETEDtIPP_OKt IPP_OK_SUBSTtIPP_OK_CONFLICTtIPP_OK_IGNORED_SUBSCRIPTIONStIPP_OK_IGNORED_NOTIFICATIONStIPP_OK_TOO_MANY_EVENTStIPP_OK_BUT_CANCEL_SUBSCRIPTIONtIPP_OK_EVENTS_COMPLETEtIPP_REDIRECTION_OTHER_SITEtIPP_BAD_REQUESTRtIPP_NOT_AUTHENTICATEDtIPP_NOT_AUTHORIZEDtIPP_NOT_POSSIBLEt IPP_TIMEOUTt IPP_NOT_FOUNDtIPP_GONEtIPP_REQUEST_ENTITYtIPP_REQUEST_VALUEtIPP_DOCUMENT_FORMATtIPP_ATTRIBUTEStIPP_URI_SCHEMEt IPP_CHARSETt IPP_CONFLICTtIPP_COMPRESSION_NOT_SUPPORTEDtIPP_COMPRESSION_ERRORtIPP_DOCUMENT_FORMAT_ERRORtIPP_DOCUMENT_ACCESS_ERRORtIPP_ATTRIBUTES_NOT_SETTABLEtIPP_IGNORED_ALL_SUBSCRIPTIONStIPP_TOO_MANY_SUBSCRIPTIONStIPP_IGNORED_ALL_NOTIFICATIONSt IPP_PRINT_SUPPORT_FILE_NOT_FOUNDtIPP_INTERNAL_ERRORtIPP_OPERATION_NOT_SUPPORTEDtIPP_SERVICE_UNAVAILABLEtIPP_VERSION_NOT_SUPPORTEDtIPP_DEVICE_ERRORtIPP_TEMPORARY_ERRORtIPP_NOT_ACCEPTINGtIPP_PRINTER_BUSYtIPP_ERROR_JOB_CANCELLEDtIPP_MULTIPLE_JOBS_NOT_SUPPORTEDtIPP_PRINTER_IS_DEACTIVATEDtCUPS_ERROR_BAD_NAMEtCUPS_ERROR_BAD_PARAMETERStcompilet MULTILINER/tIRRRR)R6RRRat IGNORECASERnRcRStTECH_CLASS_PDLStvaluesRtppRRhRRgRiR|RRRRRRRRRRRRRRRRRRRRRR@RRRRRRRRRRRRRRRRRRRRRRR (((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/prnt/cups.pytsb                %  H      M d 4 /