ó i'dWc@s dZddlZddlZddlZddlZddlZddlZddlZddlZdZ ej Z dZ dZ dZdZdejfd „ƒYZd efd „ƒYZd efd „ƒYZdejfd„ƒYZdejjfd„ƒYZdejfd„ƒYZdejfd„ƒYZdejfd„ƒYZdejjfd„ƒYZdej fd„ƒYZ!eej j"ƒe!_#dS(s: Code specific for the implementation of the InstallLoggeriÿÿÿÿNs%(progress)s %(msg)ss/var/tmp/install/destidtInstallationLoggertInstallationScriptLoggertInstallManagercBs eZdZdded„ZRS(sÊA sub-class of the logging.Manager that exists for the purpose of allowing applications to pass in a default log rather than using the default log provided by the installLogger class. cCsd}tjƒzî|tjjjkr³tjjj|}t|tjƒrý|}tj|d|d|d|ƒ}||_|tjjj|<|j ||ƒ|j |ƒqýnJtj|d|d|d|ƒ}||_|tjjj|<|j |ƒWdtj ƒX|S(su This getLogger method allows the application to pass in the following input: - name: Required. The name of the logger - log: Optional. If a default log is included, it will be set up as the default log location for the logging process. - level: Optional. This value may be set for a default log file. If it is not set, the logger sets to DEBUG as the default value. The format of the level should follow the format of the logging module. For example, logging.DEBUG, logging.INFO. - exclusive_rw - Optional. Opens the file in a more secure mode. It ensures safe log file creation and gives the file restrictive permissions. If it is not set, it defaults to False. These values are passed to the InstallLogger to set up a custom default log file. The placeholder code is an adjunct to the python logging module. It is used to manage the logging hierarchy. Because this getLogger method interfaces with the logging hierarchy, it is necessary to comply with that structure. t default_logtlevelt exclusive_rwN( tNonetloggingt _acquireLocktLoggertmanagert loggerDictt isinstancet PlaceHoldert _loggerClasst_fixupChildrent _fixupParentst _releaseLock(tselftnametlogRRt logger_nametplaceholder_for_fixup((s logger.pyt getLogger1s,      N(t__name__t __module__t__doc__RtFalseR(((s logger.pyR,st LogInitErrorcBseZdZRS(s7Raised if error occurs during initialization of logging(RRR(((s logger.pyRgst LoggerErrorcBseZdZRS(s,Raised if a fatal error occurs in the logger(RRR(((s logger.pyRlstProgressFiltercBs#eZdZed„Zd„ZRS(s]Filters records to determine if a progress message should be logged to a handler. cCs#||_tjj|ddƒdS(NRt(t _log_progressRtFiltert__init__(Rt log_progress((s logger.pyR"vs cCs7|jr%t|dƒp$t|dƒSt|dƒ SdS(s=Checks to see if a record has a progress attribute or levelnotprogresstlevelnoN(R thasattr(Rtrecord((s logger.pytfilterzs (RRRtTrueR"R((((s logger.pyRqs t HTTPHandlercBseZdZdd„ZRS(snThe HTTPHandler super class doesn't have a preamble, which is required by the installer interface. tGETcCs,||_tjjj|||ddƒdS(NtmethodR+(t _preambleRthandlersR*R"(RthostturltpreambleR,((s logger.pyR"‡s (RRRR"(((s logger.pyR*‚st FileHandlercBs/eZdZddded„Zed„ZRS(sqThe FileHandler super class doesn't check to make sure a directory exists, so the check is done here. taic Cs¿tjjtjj|ƒƒs@tjtjj|ƒddƒn|rOt}ntjj||d|d|d|ƒ|r»tj |j tj tj Btj Bdƒ}tj||ƒ|_ndS(Ntmodeiÿtencodingtdelayi¤(tostpathtexiststdirnametmakedirsR)RR2R"topent baseFilenametO_CREATtO_EXCLtO_RDWRtfdopentstream(RtfilenameR4R5R6Rtfd((s logger.pyR"‘s"   cCs |jr&|jjƒ|jjƒn|rQtjj|ƒs“tj|ƒq“nBtjjtjj|ƒdƒs“tjtjj|ƒdƒn|rÜtjj|tjj |j ƒƒ}t j |j |ƒ||_ n(t j |j |ƒtjj |ƒ|_ d|_|jƒ|_dS(sJ transfer_log() - method to move the log from its original location to the location specified in the destination variable isdir - boolean argument to specify the destination is a directory. The log file will be moved from it's current location to the destination directory iR3N(RBtflushtcloseR7R8R9R;tsplittjointbasenameR=tshutiltcopytabspathR4t_open(Rt destinationtisdirtnewfile((s logger.pyt transfer_log£s"  "    N(RRRRRR"RQ(((s logger.pyR2Œs  tInstallFormattercBseZdZd„ZRS(sISub-class the Formatter class to handle the progress records. cCs€|jtkrQ|jtkr.dd|_n|jƒ|_|j|j}|Sy tjdt j ƒj |ƒSWndSXdS(Ns"PROGRESS REPORT: progress percent:s%(progress)s %(msg)stfmts-Improper logging format. Log message dropped.( R%tMAX_INTt_fmttDEFAULTPROGRESSFORMATt getMessagetmessaget__dict__Rt Formattert InstallLoggertINSTALL_FORMATtformat(Rtrectmessage_string((s logger.pyR]Ís  (RRRR](((s logger.pyRRÈstProgressLogRecordc Bs2eZdZdddedddddd„ ZRS(s;Used to construct the log record for the progress reportingtProgressc CsŒ||_d|_||_tjj||||||||d| ƒtjdkrdt dƒ‚n|dkrˆtjj |ƒ|_ndS(Ntfuncs No engine is defined for loggingi( tmsgRR$R%Rt LogRecordR"R[tENGINERtnormalize_progress( RRcR$RRtpathnametlinenotargstexc_infoRb((s logger.pyR"às    N(RRRRRTR"(((s logger.pyR`Ýs  tProgressHandlercBs)eZdZd„Zd„Zd„ZRS(s‡The ProgressHandler manages records that are sent via the report_progress method of the InstallLogger. It sends progress records to a progress receiver. This can be a remote socket of an on disk file. The ProgressHandler provides its own formatting, which formats the data for the progress receiver. The ProgressHandler is instantiated as a singleton. cCs9tjjj|||ƒ||_||_|jƒdS(N(RR.t SocketHandlerR"R/tportt createSocket(RR/Rm((s logger.pyR"ús  cCsî|js|jƒn|jrêy›t|jdƒrj|jjtjdt|ƒƒ|ƒtjdƒnOd}t|ƒ}x:|dkr¸|jj ||ƒ}||}||}qWWqêt j k ræ|jj ƒd|_qêXndS(s«Send a string to the socket. This is modified slightly from the logging SocketHandler's send method in order to manage the progress records. tsendalls@igš™™™™™©?iN(tsockRnR&RotstructtpacktlenttimetsleeptsendtsocketterrorRFR(Rtdatat sentsofartlefttsent((s logger.pyRvs    &   cCs;y |j|ƒ}|j|ƒWn|j|ƒnXdS(N(R]Rvt handleError(RR'Rc((s logger.pytemits (RRRR"RvR~(((s logger.pyRkñs  R[cBs}eZdZd Zd ZdZd d ed„Ze d„ƒZ e d„ƒZ d„Z d d d„Z ed„Zd„ZRS( s0Sub-Class for logging in the install environments:%(asctime)-25s %(name)-10s %(levelname)-10s %(message)-50scCsd|_tdtƒ|_tdtƒ|_tjdk rSt j j ||ƒdStj ro|ro||_n||_ |dkr¥d|krœt j }q¥t}nt j j ||d|ƒt jtdƒt jdtƒtj r|jrtjj|jƒ}tjj|ƒsytj|ƒWn+tk rV}|jtjkrW‚qWnXtj|ƒ}|jd@dkrtj|dƒqntd|jddd |j ƒt_tjj|ƒtjjtƒƒt j j |tjƒtjj!|jƒndS( NR#t.RRTiÿRCR4R3R("Rtdefault_log_fileRR)t _prog_filterRt_no_prog_filterR[tDEFAULTFILEHANDLERRR R"RtNOTSETtDEFAULTLOGLEVELt addLevelNameRTR7R8R:R9R;tOSErrorterrnotEEXISTtstattst_modetchmodR2tsetLevelt setFormatterRRt addHandlert addFilter(RRRRRtlogdirterrtstatbuf((s logger.pyR",sB        cCs tjjS(s$Returns the name of the default log (R[RƒR=(R((s logger.pyRfscCstjS(s7returns the default FileHandler for the logging process(R[Rƒ(R((s logger.pyt default_fhkscCsŽtjj||ƒt|tƒrX|j|jƒ|jtƒ|j t ddƒƒn2|j|j ƒ|j dkrŠ|j t ƒƒndS(syAdds the requested handler to the InstallLogger Performs special handling if it is a progress handler RSs%(progress)s %(msg)sN(RR RR RkRRRRTRŽRRR‚t formatterR(Rthandler((s logger.pyRps cCsBd|kodkns"t‚t||ƒ}|j|ƒdS(s.Logs progress reports to the progress receiveriidN(tAssertionErrorR`thandle(RRcR$t prog_record((s logger.pytreport_progresss"cCs)tjj|ƒ}tjj||ƒdS(så Requests a transfer of the default log to a requested location, currently just another location on disk. It also adds the log location to a log file list that is available once logging completes. N(R7R8ROR[RƒRQ(RRNtisDir((s logger.pyRQ…s cCs‹g}xttjjjjƒD]]}t|dƒrxE|jD]7}t|tƒr;|j |kr;|j |j ƒq;q;WqqWtj ƒ|S(s3Terminates logging and provides a list of log filesR.( RR R R tvaluesR&R.R R2R=tappendtshutdown(Rtclose_log_listtvalR–((s logger.pyRFs N(RRRRReRƒR\RR"tpropertyRR”RRštDEFAULTDESTINATIONRQRF(((s logger.pyR[#s:  ($RRˆRtlogging.handlersR7RJRwRqRtRVtDEBUGR…R¢RTtINSTALL_LOGGER_NAMEtSCRIPT_LOGGER_NAMEtManagerRt ExceptionRRR!RR.R*R2RZRRRdR`RlRkR R[trootR (((s logger.pyts2         ; <2€