Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/landscape/package/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/landscape/package/changer.pyc


Tc@sddlZddlZddlZddlZddlZddlZddlZddlmZm	Z	ddl
mZddlm
Z
mZmZmZmZmZmZddlmZddlmZddlmZddlmZmZmZmZdd	lm Z dd
l!m"Z"ddl#m$Z$de%fd
YZ&defdYZ'de(fdYZ)defdYZ*dZ+dZ,dS(iN(t
maybeDeferredtsucceed(treactor(tSUCCESS_RESULTtERROR_RESULTtDEPENDENCY_ERROR_RESULTt
POLICY_STRICTtPOLICY_ALLOW_INSTALLStPOLICY_ALLOW_ALL_CHANGEStUNKNOWN_PACKAGE_DATA_TIMEOUT(tcreate_file(tlog_failure(tfind_reporter_command(tPackageTaskHandlertPackageTaskHandlerConfigurationtPackageTaskErrortrun_task_handler(tFAILED(tShutdownProcessProtocol(tREBOOT_REQUIRED_FILENAMEtUnknownPackageDatacBseZdZRS(s(Raised when an ID or a hash isn't known.(t__name__t
__module__t__doc__(((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyRstPackageChangerConfigurationcBseZdZedZRS(s<Specialized configuration for the Landscape package-changer.cCstjj|jdS(s@The path to the directory we store server-generated packages in.tbinaries(tostpathtjointpackage_directory(tself((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyt
binaries_path#s(RRRtpropertyR(((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyR stChangePackagesResultcBseZdZdZRS(sValue object to hold the results of change packages operation.

    @ivar code: The result code of the requested changes.
    @ivar text: The output from Apt.
    @ivar installs: Possible additional packages that need to be installed
        in order to fulfill the request.
    @ivar removals: Possible additional packages that need to be removed
        in order to fulfill the request.
    cCs(d|_d|_g|_g|_dS(N(tNonetcodettexttinstallstremovals(R((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyt__init__4s			(RRRR'(((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyR!)s	tPackageChangercBseZdZeZdZededZ	dZ
dZdZdZ
dZdZdd	Zedddded
ZdZdZd
ZdZdZdZedZdZedZRS(s%Install, remove and upgrade packages.tchangerc	Csitt|j||||||_|dkrSddlm}||_n	||_||_dS(Ni(tLandscapeReactor(	tsuperR(R't_process_factoryR"tlandscape.reactorR*t_landscape_reactortreboot_required_filename(	Rtstoretfacadetremotetconfigtprocess_factorytlandscape_reactorR/R*((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyR'Bs		csujs#tjdtdSj}|jfd|jfd|jfd|S(sV
        Handle our tasks and spawn the reporter if package data has changed.
        s-The package-reporter hasn't run yet, exiting.cs
jS(N(tget_session_id(tx(R(s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyt<lambda>Wscs
jS(N(thandle_tasks(R7(R(s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyR8Xscs
jS(N(trun_package_reporter(R7(R(s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyR8YsN(tupdate_stamp_existstloggingtwarningRR"tuse_hash_id_dbtaddCallback(Rtresult((Rs=/usr/lib/python2.7/dist-packages/landscape/package/changer.pytrunNs

cCs|jdkrdStjdkrZtjtjdjtjtj	dj
nt}|jj
dk	r|d|jj
7}ntj|dS(sX
        Run the L{PackageReporter} if there were successfully completed tasks.
        iNt	landscapes -c %s(thandled_tasks_countRtgetuidtsetgidtgrptgetgrnamtgr_gidtsetuidtpwdtgetpwnamtpw_uidRt_configR3R"tsystem(Rtcommand((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyR:\s	cCs_|j}|ddkr>t|j|}|j|j|S|ddkr[|j|SdS(sl
        @param task: A L{PackageTask} carrying a message of
            type C{"change-packages"}.
        ttypeschange-packagesschange-package-locksN(tdataRthandle_change_packagest
addErrbacktunknown_package_data_errorthandle_change_package_locks(RttasktmessageR@((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pythandle_taskls	cCs|jttjd|jjd|jtjtkridd6|j	dd6t
d6dd6}|jj||j
Std	S(
s}Handle L{UnknownPackageData} data errors.

        If the task is older than L{UNKNOWN_PACKAGE_DATA_TIMEOUT} seconds,
        a message is sent to the server to notify the failure of the associated
        activity and the task will be removed from the queue.

        Otherwise a L{PackageTaskError} is raised and the task will be picked
        up again at the next run.
        s2Package data not yet synchronized with server (%r)ischange-packages-resultRPsoperation-idsresult-codes5Package data has changed. Please retry the operation.sresult-textN(ttrapRR<R=tvaluetargst	timestampttimeR	RQRt_brokertsend_messaget_session_idR(RtfailureRVRW((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyRTxs

	

cCs+tjj|jjp*tjj|jS(sT
        Return a boolean indicating if the update-stamp stamp file exists.
        (RRtexistsRMtupdate_stamp_filenametupdate_notifier_stamp(R((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyR;scCsS|jj}x3tj|D]"}tjtjj||qW|jjdS(s/Remove any binaries and its associated channel.N(	RMRRtlistdirtremoveRRt_facadetclear_channels(RRtexisting_deb_path((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyt_clear_binariess cCs|jj}|j|ri}xJ|D]B\}}}ttjj|d|tj||||<q)W|j	j
||jj||jj
dtn|jjdS(sInitialize the Apt channels as needed.

        @param binaries: A possibly empty list of 3-tuples of the form
            (hash, id, deb), holding the hash, the id and the content of
            additional Debian packages that should be loaded in the channels.
        s%d.debtforce_reload_binariesN(RMRRjR
RRRtbase64tdecodestringt_storetset_hash_idsRgtadd_channel_deb_dirtreload_channelstTruetensure_channels_reloaded(RRRthash_idsthashtidtdeb((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyt
init_channelss
cCs|r|jjn|r,|jjnx|jj|f|jj|f|jj|f|jj|fgD]\}}xr|D]j}	|jj|	}
|
dkrt
|	n|jj|
}|dkrt
|
n||qWqoWdS(sMark packages for upgrade, installation or removal.

        @param upgrade: If C{True} mark all installed packages for upgrade.
        @param install: A list of package ids to be marked for installation.
        @param remove: A list of package ids to be marked for removal.
        @param hold: A list of package ids to be marked for holding.
        @param remove_hold: A list of package ids to be marked to have a hold
                            removed.
        @param reset: If C{True} all existing marks will be reset.
        N(Rgtreset_markstmark_global_upgradetmark_installtmark_removet	mark_holdtmark_remove_holdRntget_id_hashR"Rtget_package_by_hash(RtupgradetinstallRftholdtremove_holdtresett
mark_functiontmark_idstmark_idRutpackage((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyt
mark_packagess"
c
Cs}ddlm}m}t}d}xQ|jdkrx|d7}y|jj|_Wn|k
r}t	|_|j
d|_q(|k
rk}x|jD]z}|jj|}|j
j|}	|	dkrt|n|jj|r|jj|	q|jj|	qW|dkr_|j||r_|jd|jd|jdtqut|_q(Xt|_q(W|S(	stPerform the requested changes.

        @param policy: A value indicating what to do in case additional changes
            beside the ones explicitly requested are needed in order to fulfill
            the request (see L{complement_changes}).
        @return: A L{ChangePackagesResult} holding the details about the
            outcome of the requested changes.
        i(tDependencyErrortTransactionErroriiRRfRN(tlandscape.package.facadeRRR!R#R"Rgtperform_changesR$RR[tpackagestget_package_hashRntget_hash_idRtis_package_installedR&tappendR%tmay_complement_changesRtFalseRR(
RtpolicyRRR@tcountt	exceptionRRuRv((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pytchange_packagess2	
	

cCs:|tkrtS|tkr6|jr6|jr6tSntS(saDecide whether or not we should complement the given changes.

        @param result: A L{PackagesResultObject} holding the details about the
            missing dependencies needed to complement the given changes.
        @param policy: It can be one of the following values:
            - L{POLICY_STRICT}, no additional packages will be marked.
            - L{POLICY_ALLOW_INSTALLS}, if only additional installs are missing
                they will be marked for installation.
        @return: A boolean indicating whether the given policy allows to
            complement the changes and retry.
        (RRrRR%R&R(RR@R((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyRsc
Cs|j|jdd|jd|jdtd|jdd
d|jddd|jddd|jdd|j|jd	t}|j|jd
otjj	|j
}|}|jd||d|}|r|j
|jn|S(s$Handle a C{change-packages} message.RRsupgrade-allRRfRRsremove-holdRsreboot-if-necessarytstop_exchanger(((((N(RxtgetRRRRRjRRRbR/t_send_responseR"R?t
_reboot_later(RRWR@tneeds_rebootRtdeferred((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyRRs 
	
cCs|jjd|jdS(Ni(R.t
call_latert_run_reboot(RR@((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyR:scCszt}d}|j|j|jj|j||jjtddd|dg}|jj	|dd||jS(sU
        Create a C{ShutdownProcessProtocol} and return its result deferred.
        tnowsReboot failed.s/sbin/shutdowns-rs!Landscape is rebooting the systemR[(
Rtset_timeoutR.R@R?t_log_rebootRSRR,tspawnProcess(RtprotocoltminutesR[((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyR=s				cCstjd|dS(sLog the reboot.s/Landscape is rebooting the system in %s minutesN(R<R=(RR@R((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyRLscsidd6|jdd6}|j|d<|jrC|j|d<n|jrbt|j|d<n|jrt|j|d<ntjdjj	|j
t}|rtjd	|jfd
n|S(s?
        Create a response and dispatch to the broker.
        schange-packages-resultRPsoperation-idsresult-codesresult-textsmust-installsmust-removesBQueuing response with change package results to exchange urgently.s*stopping exchanger due to imminent reboot.cs
jjS(N(R^R(t_(R(s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyR8gs(
RR#R$R%tsortedR&R<tinfoR^R_R`RrR?(Rt
reboot_resultRWtpackage_change_resultRtresponseR((Rs=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyRQs

			

cCsKidd6|jdd6td6dd6dd6}|jj||jtS(	scHandle a C{change-package-locks} message.

        Package locks aren't supported anymore.
        soperation-resultRPsoperation-idtstatuss*This client doesn't support package locks.sresult-textisresult-code(RRR^R_R`Rr(RRWR((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyRUjs
cCstS(N(tfind_changer_command(((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pytfind_commandxsN((((((RRRRtconfig_factoryt
queue_nameRR"RR'RAR:RXRTR;RjRxRRrRRRRRRRRRRUtstaticmethodR(((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyR(;s0
									/						cCs8tjjtjjtjd}tjj|dS(Nislandscape-package-changer(RRtdirnametabspathtsystargvR(R((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyR}s%cCs2tjtjkr%tjntt|S(N(RtgetpgrptgetpidtsetsidRR((R[((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pytmains
(-R<RlR]RRRJRFttwisted.internet.deferRRttwisted.internetRtlandscape.constantsRRRRRRR	tlandscape.lib.fsR
tlandscape.lib.logRtlandscape.package.reporterRtlandscape.package.taskhandlerR
RRRtlandscape.manager.managerRt!landscape.manager.shutdownmanagerRt landscape.monitor.rebootrequiredRt	ExceptionRRtobjectR!R(RR(((s=/usr/lib/python2.7/dist-packages/landscape/package/changer.pyt<module>s.4"	C