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/reporter.pyc


Tc@slddlZddlZddlZddlZddlZddlZddlZddlmZm	Z	ddl
mZddlm
Z
mZddlmZddlmZddlmZddlmZmZmZdd	lmZmZd
ZdZdefd
YZdefdYZdefdYZ defdYZ!dZ"dZ#dS(iN(tDeferredtsucceed(tsequence_to_ranges(tgather_resultst
spawn_process(tfetch_async(t
touch_file(tbpickle(tPackageTaskHandlerConfigurationtPackageTaskHandlertrun_task_handler(tUnknownHashIDRequesttFakePackageStorei itPackageReporterConfigurationcBseZdZdZRS(s=Specialized configuration for the Landscape package-reporter.cCs8tt|j}|jddtdddd|S(sl
        Specialize L{Configuration.make_parser}, adding options
        reporter-specific options.
        s--force-apt-updatetdefaulttactiont
store_truethelpsForce running apt-update.(tsuperR
tmake_parsert
add_optiontFalse(tselftparser((s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRs
(t__name__t
__module__t__doc__R(((s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR
stPackageReportercBseZdZeZdZdZdZdZe	Z
dZdZdZ
dZd	Zd
ZdZdZd
ZdZdZdZdZdZdZdZdZdZdZRS(stReport information about the system packages.

    @cvar queue_name: Name of the task queue to pick tasks from.
    treporters/usr/lib/landscape/apt-updates/etc/apt/sources.lists/etc/apt/sources.list.dcst_t}|jfd|jfd|jfd|jfd|jfd|jfd|jfd|jfd|jd|S(	Ncs
jS(N(tget_session_id(tx(R(s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyt<lambda><scs
jS(N(trun_apt_update(R(R(s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR>scs
jS(N(tfetch_hash_id_db(R(R(s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRAscs
jS(N(tuse_hash_id_db(R(R(s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRDscs
jS(N(thandle_tasks(R(R(s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRGscs
jS(N(tremove_expired_hash_id_requests(R(R(s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRJscs
jS(N(trequest_unknown_hashes(R(R(s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRMscs
jS(N(tdetect_changes(R(R(s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRPs(Rt	_got_taskRtaddCallbacktcallbacktNone(Rtresult((Rs>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pytrun7s		
cCs|jj||jtS(N(t_brokertsend_messaget_session_idtTrue(Rtmessage((s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR.Us	cs,fd}j}|j||S(s
        Fetch the appropriate pre-canned database of hash=>id mappings
        from the server. If the database is already present, it won't
        be downloaded twice.

        The format of the database filename is <uuid>_<codename>_<arch>,
        and it will be downloaded from the HTTP directory set in
        config.package_hash_id_url, or config.url/hash-id-databases if
        the former is not set.

        Fetch failures are handled gracefully and logged as appropriate.
        csdkrdStjjr&dSj}|sItjddSt|tjjfd}d}t	dj
jd}|j||j
||S(Ns)Can't determine the hash=>id database urlcs;td}|j||jtjddS(Ntws$Downloaded hash=>id database from %s(topentwritetclosetloggingtinfo(tdatat
hash_id_db_fd(turlthash_id_db_filename(s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pytfetch_okzs

cSs$|j}tjdt|dS(Ns'Couldn't download hash=>id database: %s(tvalueR6twarningtstr(tfailuret	exception((s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pytfetch_errors		tcainfotssl_public_key(R*tostpathtexistst_get_hash_id_db_base_urlR6R>R?tbasenameRt_configtgetR(t
addErrback(R;tbase_urlR<RBR+(R(R:R;s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pytfetch_itgs 
		

(t_determine_hash_id_db_filenameR((RRNR+((Rs>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR!Ys%
cCsc|jjd}|sR|jjds.dStj|jjjdd}n|jddS(Ntpackage_hash_id_urlR:t/shash-id-databases(RJRKR*turlparseturljoinR:trstrip(RRM((s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRHscCsddlm}g}tjj|jr>|j|jntjj|jr|jgtj	|jD]}tjj
|j|^qlnx=|D]5}tjtjj|}||j
krtSqWtS(s=Return a boolean indicating if the APT sources were modified.i(tPackageMonitor(t landscape.monitor.packagemonitorRURERFRGtsources_list_filenametappendtsources_list_directorytextendtlistdirtjointtimetgetmtimetrun_intervalR0R(RRUt	filenamestfilenametseconds_since_last_change((s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyt_apt_sources_have_changeds8
cCsrtjj|jr!|j}n+tjj|jjrH|jj}ntStj|j}||t	j	kS(s+Check if the apt-update timeout has passed.(
RERFRGtupdate_notifier_stampRJtupdate_stamp_filenameR0tstattst_mtimeR](Rtintervaltstamptlast_update((s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyt_apt_update_timeout_expiredscszjjs-js-jjjrXtj}fd}|j|Stj	djt
dSdS(sRun apt-update and log a warning in case of non-zero exit code.

        @return: a deferred returning (out, err, code)
        cs
|\d}tjjtjdjfdkrtjdjfx^|D]%}|krud\PququWn.jjsddj	j
fnjjd	j
}|jfd
|S(
Ns8Problem renaming the file /var/cache/apt/srcpkgcache.bins5Problem renaming the file /var/cache/apt/pkgcache.bins/'%s' exited with status %d (out='%s', err='%s')is'%s' exited with status %d (%s)tis0There are no APT sources configured in %s or %s.spackage-reporter-resultcs
fS(N((tignore(tcodeterrtout(s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRs(s8Problem renaming the file /var/cache/apt/srcpkgcache.bins5Problem renaming the file /var/cache/apt/pkgcache.bin(RlRli(RRJReR6tdebugtapt_update_filenameR>t_facadetget_channelsRWRYR-tcall_if_acceptedtsend_resultR((t.0RpRoRntaccepted_apt_errorsR1tdeferred(R(RnRoRps>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR)s.	
	s/'%s' didn't run, update interval has not passedRliN(RlRli(RJtforce_apt_updateRcRktapt_update_intervalRRrR(R6RqR(RR+R)((Rs>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR s"
	cCs(idd6|d6|d6}|j|S(sP
        Report the package reporter result to the server in a message.
        spackage-reporter-resultttypeRnRo(R.(RRnRoR1((s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRvs

cCsV|j}|ddkr/t|_|j|S|ddkrRt|_|jSdS(NR|spackage-idst
resynchronize(R8R0R't_handle_package_idst_handle_resynchronize(RttaskR1((s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pythandle_tasks		
	csg}y|jj|dWntk
r:tdSXi}xJtj|dD]2\}}|dkr|j|qX|||<qXW|jj|t	j
dt|t|f|r|j|}ntd}|j
fd|S(Ns
request-idtidssCReceived %d package hash => id translations, %d hashes are unknown.cs
jS(N(tremove(R(trequest(s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR&s(t_storetget_hash_id_requestRRR*tzipthashesRXtset_hash_idsR6R7tlent_handle_unknown_packagesR((RR1tunknown_hashesthash_idsthashtidR+((Rs>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR~
s$
#	cCsK|jj|jj|jj|jj|jjtdS(N(Rtclear_availabletclear_available_upgradestclear_installedtclear_lockedtclear_hash_id_requestsRR*(R((s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR*s




c	Cs<|jjt|}g}g}x|jjD]}|jj|}||kr5|j||jj|}|ji	|jd6|jd6|j	d6|j
d6|jd6|jd6|j
d6|jd6|jd	6q5q5W|r,tjd
t|idd6|d6}|j||}ntd}|S(
NR|tnametversiontsectiontsummarytdescriptiontsizesinstalled-sizet	relationss@Queuing messages with data for %d packages to exchange urgently.sadd-packagestpackages(Rstensure_channels_reloadedtsettget_packagestget_package_hashRXtget_package_skeletonR|RRRRRRtinstalled_sizeRR6R7Rt"_send_message_with_hash_id_requestRR*(	RRtadded_hashesRtpackageRtskeletonR1R+((s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR3s4








		cstjtfd}g}xe|jjD]T}|jdkr`|jq>|jj|j}|j	|||j
|q>Wt|S(Ncs2|r|_n|jkr.|jndS(N(t	timestampR(t
is_pendingR(tnowttimeout(s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pytupdate_or_removeZs(R]tHASH_ID_REQUEST_TIMEOUTRtiter_hash_id_requestst
message_idR*RR-tis_message_pendingR(RXR(RRtresultsRR+((RRs>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR$Vs

cCs|jjt}x]|jjD]L}|jj|}|jj|dkr&|j|jj|q&q&Wx*|jj	D]}|t|j
8}qW|std}nSt|}|t
 }tjdt|idd6|d6}|j||}|S(sDetect available packages for which we have no hash=>id mappings.

        This method will verify if there are packages that APT knows
        about but for which we don't have an id yet (no hash => id
        translation), and deliver a message (unknown-package-hashes)
        to request them.

        Hashes previously requested won't be requested again, unless they
        have already expired and removed from the database.
        sBQueuing request for package hash => id translation on %d hash(es).sunknown-package-hashesR|RN(RsRRRRRtget_hash_idR*taddRRRtsortedtMAX_UNKNOWN_HASHES_PER_REQUESTR6R7RR(RRRRRR+R1((s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR%ps&
	 
	

		cs\|jj|j|d<|j|}fd}fd}|j||S(s<Create a hash_id_request and send message with "request-id".s
request-idcs
|_dS(N(R(R(R(s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pytset_message_idscsj|S(N(R(R@(R(s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pytsend_message_faileds
(Rtadd_hash_id_requestRR.taddCallbacks(RR1RR+RR((Rs>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRs
cs(fd}j}|j|S(sDetect all changes concerning packages.

        If some changes were detected with respect to our last run, then an
        event of type 'package-data-changed' will be fired in the broker
        reactor.
        cs|rjjdSdS(Nspackage-data-changed(R-t
fire_event(R+(R(s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pytchanges_detecteds(tdetect_packages_changesR((RRRy((Rs>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR&scCs-|js|jr|jStdSdS(s
        Check if any information regarding packages have changed, and if so
        compute the changes and send a signal.
        N(R't_package_state_has_changedt_compute_packages_changesRR*(R((s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRs
cCs|jj}tjj|s"tStjjd}tjj	d}||g}|j
tjd|tj|j
}x0|D](}tj|j
}||krtSqWtS(sE
        Detect changes in the universe of known packages.

        This uses the state of packages in /var/lib/dpkg/state and other files
        and simply checks whether they have changed using their "last changed"
        timestamp on the filesystem.

        @return True if the status changed, False otherwise.
        sdir::state::statussdir::state::listss%s/*Packages(RJtdetect_package_changes_stampRERFRGR0tapt_pkgtconfigt	find_filetfind_dirRZtglobRfRgR(Rt
stamp_filetstatus_filet	lists_dirtfilestlast_checkedtftlast_changed((s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRs

csjjtjj}tjj}tjj}tjj}t}t}t}t}xjjD]}	jj	|	}
jj
|
}|d
k	rjj|	r|j
|jj|	r|j
|qn
|j
|jj|	rA|j
|qAqqWxWjjD]F}	jj	|	}
jj
|
}|d
k	rU|j
|qUqUW||||||||||||||||i}rttt|d<nr?ttt|d<nrdttt|d<nrttt|d<nrttt|d<nrttt|d<nrttt|d<nrttt|d<n|s-ttSd	|d
<j|}
tjdttttttttff	d}|
j||
S(s/Analyse changes in the universe of known packages.

        This method will verify if there are packages that:

        - are now installed, and were not;
        - are now available, and were not;
        - are now locked, and were not;
        - were previously available but are not anymore;
        - were previously installed but are not anymore;
        - were previously locked but are not anymore;

        Additionally it will report package locks that:

        - are now set, and were not;
        - were previously set but are not anymore;

        In all cases, the server is notified of the new situation
        with a "packages" message.

        @return: A deferred resulting in C{True} if package changes were
            detected with respect to the previous run, or C{False} otherwise.
        t	installedt	availablesavailable-upgradestlockeds
not-installeds
not-availablesnot-available-upgradess
not-lockedRR|sQueuing message with changes in known packages: %d installed, %d available, %d available upgrades, %d locked, %d not installed, %d not available, %d not available upgrades, %d not locked.csrjjnr2jjnrKjjnrdjjnr}jjnrjjnrjjnrjjnj	j
}t|tS(N(
Rt
add_installedtremove_installedt
add_availablet
add_lockedtremove_availabletadd_available_upgradestremove_available_upgradest
remove_lockedRJRRR0(R+R(	t
not_lockedt
new_availablet
new_lockedtnew_upgradesRtnot_upgradest
not_availablet
new_installedt
not_installed(s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pytupdate_currently_knownHs&
N(RsRRRt
get_installedt
get_availabletget_available_upgradest
get_lockedRRRR*tis_package_installedRtis_package_availabletis_package_upgradetget_locked_packagestlistRRRRR.R6R7RR((Rt
old_installedt
old_availabletold_upgradest
old_lockedtcurrent_installedtcurrent_availabletcurrent_upgradestcurrent_lockedRRRR1R+R((	RRRRRRRRRs>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRs|
				











	'
(RRRR
tconfig_factoryt
queue_nameRrRWRYRR'R,R.R!RHRcRkR RvRR~RRR$R%RR&RRR(((s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR)s4			7				4	
			 			#		)			
	tFakeGlobalReportercBseZdZeZdZRS(sb
    A standard reporter, which additionally stores messages sent into its
    package store.
    cCs&|jj|tt|j|S(N(Rtsave_messageRRR.(RR1((s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR.ls(RRRRtpackage_store_classR.(((s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRdstFakeReportercBs,eZdZeZdZdZdZRS(se
    A fake reporter which only sends messages previously stored by a
    L{FakeGlobalReporter}.
    cshtd}|jfd|jfd|jfd|jfd|S(Ncs
jS(N(R(R(R(s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR}scs
jS(N(R!(R(R(s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRscs
jjS(N(Rtclear_tasks(R(R(s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRscs
jS(N(tsend_pending_messages(R(R(s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRs(RR*R((RR+((Rs>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR,zscs>jdkr"tjd_ntjjjsAtdStjj	}t
j}t|j	}||}td}t}|r:|j|}g}xs|D]k\}	}
tj
t|
}
|
d|kr|j|
d|j|	|j|
fdqqWjj|n|S(sT
        As the last callback of L{PackageReporter}, sends messages stored.
        tFAKE_PACKAGE_STORER|cs
j|S(N(R.(RR1(R(s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRsN(tglobal_store_filenameR*REtenvironRFRGRRRtget_message_idsRtget_messages_by_idsRtloadsR?RRXR(tsave_message_ids(Rtmessage_senttglobal_storetall_message_idstnot_sentRytgot_typetmessagestsentRR1((Rs>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRs,

	
N(	RRRRRR*RR,R(((s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRqs
	cCsIdtjkrtt|Sdtjkr8tt|Stt|SdS(NtFAKE_GLOBAL_PACKAGE_STORER(RERR
RRR(targs((s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pytmains


cCs8tjjtjjtjd}tjj|dS(Nislandscape-package-reporter(RERFtdirnametabspathtsystargvR\(R	((s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pytfind_reporter_commands%($RRR6R]RRERRttwisted.internet.deferRRtlandscape.lib.sequencerangesRtlandscape.lib.twisted_utilRRtlandscape.lib.fetchRtlandscape.lib.fsRt
landscape.libRtlandscape.package.taskhandlerRR	R
tlandscape.package.storeRRRRR
RRRRR
(((s>/usr/lib/python2.7/dist-packages/landscape/package/reporter.pyt<module>s0=
4