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


Tc@sdZddlZyddlZWn!ek
rEddlmZnXddlmZddlm	Z	de
fdYZde
fd	YZd
e
fdYZdefd
YZdefdYZde
fdYZde
fdYZdZdZdZdS(sEProvide access to the persistent data used by L{PackageTaskHandler}s.iN(tdbapi2(tbpickle(twith_cursortUnknownHashIDRequestcBseZdZRS(s$Raised for unknown hash id requests.(t__name__t
__module__t__doc__(((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyR
stInvalidHashIdDbcBseZdZRS(sARaised when trying to add an invalid hash=>id lookaside database.(RRR(((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyRstHashIdStorecBseZdZd	ZdZdZedZedZ	edZ
edZedZedZ
RS(
sC{HashIdStore} stores package hash=>id mappings in a file.

    The file is a SQLite database that contains a single table called "hash".
    The table schema is defined in L{ensure_hash_id_schema}.

    @param filename: The file where the mappings are persisted to.
    cCs
||_dS(N(t	_filename(tselftfilename((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyt__init__scCst|jdS(N(tensure_hash_id_schemat_db(R
((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyt_ensure_schema"scCs=x6|jD](\}}|jd|t|fq
WdS(sbSet the ids of a set of hashes.

        @param hash_ids: a C{dict} of hash=>id mappings.
        sREPLACE INTO hash VALUES (?, ?)N(t	iteritemstexecutetbuffer(R
tcursorthash_idsthashtid((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytset_hash_ids%s	cCs7|jdt|f|j}|r3|dSdS(sAReturn the id associated to C{hash}, or C{None} if not available.s SELECT id FROM hash WHERE hash=?iN(RRtfetchonetNone(R
RRtvalue((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytget_hash_id/s
cCsD|jdtg|jD] }t|d|df^qS(s=Return a C{dict} holding all the available hash=>id mappings.sSELECT hash, id FROM hashii(Rtdicttfetchalltstr(R
Rtrow((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytget_hash_ids8s
cCsRt|ttfst|jd|f|j}|rNt|dSdS(sAReturn the hash associated to C{id}, or C{None} if not available.s SELECT hash FROM hash WHERE id=?iN(t
isinstancetinttlongtAssertionErrorRRRR(R
RRR((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytget_id_hash>scCs|jddS(sDelete all hash=>id mappings.sDELETE FROM hashN(R(R
R((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytclear_hash_idsHscCs>y|jddWn#tjk
r9t|jnXdS(sCheck database integrity.

        @raise: L{InvalidHashIdDb} if the filenme passed to the constructor is
            not a SQLite database or does not have a table called "hash" with
            a compatible schema.
        s SELECT id FROM hash WHERE hash=?tN(R'(Rtsqlite3t
DatabaseErrorRR	(R
R((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytcheck_sanityMsN(RRRRRRRRRRR R%R&R*(((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyRs		
	
tPackageStorecBseZdZdZdZdZdZdZdZe	dZ
e	dZe	d	Ze	d
Z
e	dZe	dZe	d
Ze	dZe	dZe	dZe	dZe	dZe	dZe	dZe	dZe	dZe	dZe	dZe	dZe	dZe	dZe	dZe	ddZ RS(sPersist data about system packages and L{PackageTaskHandler}'s tasks.

    This class extends L{HashIdStore} by adding tables to the SQLite database
    backend for storing information about the status of the system packages and
    about the tasks to be performed by L{PackageTaskHandler}s.

    The additional tables and schemas are defined in L{ensure_package_schema}.

    @param filename: The file where data is persisted to.
    cCs#tt|j|g|_dS(N(tsuperR+Rt_hash_id_stores(R
R((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyRgscCs$tt|jt|jdS(N(R,R+Rtensure_package_schemaR(R
((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyRkscCsJt|}y|jWntk
r5}|nX|jj|dS(s 
        Attach an additional "lookaside" hash=>id database.

        This method can be called more than once to attach several
        hash=>id databases, which will be queried *before* the main
        database, in the same the order they were added.

        If C{filename} is not a SQLite database or does not have a
        table called "hash" with a compatible schema, L{InvalidHashIdDb}
        is raised.

        @param filename: a secondary SQLite databases to look for pre-canned
                         hash=>id mappings.
        N(RR*RR-tappend(R
Rt
hash_id_storete((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytadd_hash_id_dbos
cCst|jdkS(s?Return C{True} if one or more lookaside databases are attached.i(tlenR-(R
((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pythas_hash_id_dbscCsRt|tstx*|jD]}|j|}|r|SqWtj||S(s	Return the id associated to C{hash}, or C{None} if not available.

        This method composes the L{HashIdStore.get_hash_id} methods of all
        the attached lookaside databases, falling back to the main one, as
        described in L{add_hash_id_db}.
        (R!t
basestringR$R-RR(R
RtstoreR((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyRscCsCx0|jD]%}|j|}|dk	r
|Sq
Wtj||S(s'Return the hash associated to C{id}, or C{None} if not available.

        This method composes the L{HashIdStore.get_id_hash} methods of all
        the attached lookaside databases, falling back to the main one in
        case the hash associated to C{id} is not found in any of them.
        N(R-R%RR(R
RR6R((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyR%s
cCs(x!|D]}|jd|fqWdS(Ns!REPLACE INTO available VALUES (?)(R(R
RtidsR((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyt
add_availables
cCs.djd|D}|jd|dS(Nt,css!|]}tt|VqdS(N(RR"(t.0R((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pys	<genexpr>ss&DELETE FROM available WHERE id IN (%s)(tjoinR(R
RR7tid_list((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytremove_availablescCs|jddS(NsDELETE FROM available(R(R
R((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytclear_availablescCs.|jdg|jD]}|d^qS(NsSELECT id FROM availablei(RR(R
RR((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyt
get_availables
cCs(x!|D]}|jd|fqWdS(Ns)REPLACE INTO available_upgrade VALUES (?)(R(R
RR7R((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytadd_available_upgradess
cCs.djd|D}|jd|dS(NR9css!|]}tt|VqdS(N(RR"(R:R((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pys	<genexpr>ss.DELETE FROM available_upgrade WHERE id IN (%s)(R;R(R
RR7R<((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytremove_available_upgradess	cCs|jddS(NsDELETE FROM available_upgrade(R(R
R((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytclear_available_upgradesscCs.|jdg|jD]}|d^qS(Ns SELECT id FROM available_upgradei(RR(R
RR((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytget_available_upgradess
cCs(x!|D]}|jd|fqWdS(Ns!REPLACE INTO installed VALUES (?)(R(R
RR7R((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyt
add_installeds
cCs.djd|D}|jd|dS(NR9css!|]}tt|VqdS(N(RR"(R:R((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pys	<genexpr>ss&DELETE FROM installed WHERE id IN (%s)(R;R(R
RR7R<((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytremove_installedscCs|jddS(NsDELETE FROM installed(R(R
R((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytclear_installedscCs.|jdg|jD]}|d^qS(NsSELECT id FROM installedi(RR(R
RR((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyt
get_installeds
cCs.|jdg|jD]}|d^qS(s+Get the package ids of all locked packages.sSELECT id FROM lockedi(RR(R
RR((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyt
get_lockeds
cCs(x!|D]}|jd|fqWdS(s9Add the given package ids to the list of locked packages.sREPLACE INTO locked VALUES (?)N(R(R
RR7R((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyt
add_lockeds
cCs.djd|D}|jd|dS(NR9css!|]}tt|VqdS(N(RR"(R:R((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pys	<genexpr>ss#DELETE FROM locked WHERE id IN (%s)(R;R(R
RR7R<((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyt
remove_lockedscCs|jddS(s/Remove all the package ids in the locked table.sDELETE FROM lockedN(R(R
R((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytclear_lockedscCsJt|}|jdttj|tjft|j|jS(Ns<INSERT INTO hash_id_request (hashes, timestamp) VALUES (?,?)(	tlistRRRtdumpsttimet
HashIDRequestRt	lastrowid(R
Rthashes((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytadd_hash_id_requests	"cCs>|jd|f|js.t|nt|j|S(Ns(SELECT 1 FROM hash_id_request WHERE id=?(RRRROR(R
Rt
request_id((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytget_hash_id_requests
	
cCs:|jdg|jD]}t|j|d^qS(NsSELECT id FROM hash_id_requesti(RRROR(R
RR((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytiter_hash_id_requestss
cCs|jddS(NsDELETE FROM hash_id_request(R(R
R((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytclear_hash_id_requestsscCsGtj|}|jd|tjt|ft|j|jS(Ns8INSERT INTO task (queue, timestamp, data) VALUES (?,?,?)(RRMRRNRtPackageTaskRRP(R
Rtqueuetdata((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytadd_tasks	cCs=|jd|f|j}|r9t|j|dSdS(Ns4SELECT id FROM task WHERE queue=? ORDER BY timestampi(RRRWRR(R
RRXR((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyt
get_next_tasks	
cCs:|jddjg|D]}t|j^qdS(Ns%DELETE FROM task WHERE id NOT IN (%s)R9(RR;RR(R
Rtexcept_tasksttask((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytclear_tasks$s	((!RRRRRR2R4RR%RR8R=R>R?R@RARBRCRDRERFRGRHRIRJRKRRRTRURVRZR[R^(((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyR+[s>
						
	tFakePackageStorecBsSeZdZdZedZedZedZedZRS(sT
    A L{PackageStore} with an additional message table to store sent messages.
    cCs$tt|jt|jdS(N(R,R_Rtensure_fake_package_schemaR(R
((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyR/scCs&|jdttj|fdS(Ns%INSERT INTO message (data) VALUES (?)(RRRRM(R
Rtmessage((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytsave_message3s	cCs*g|jdjD]}|d^qS(NsSELECT id FROM messagei(RR(R
RR((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytget_message_ids8scCs*|jdg|D]}|f^qdS(Ns#INSERT INTO message (id) VALUES (?)(texecutemany(R
Rtmessage_idst
message_id((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytsave_message_ids=scCscdjdgt|}|jd|t|j}g|D]}|d|df^qES(Ns, t?s9SELECT id, data FROM message WHERE id IN (%s) ORDER BY idii(R;R3RttupleR(R
RRetparamstresultR((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytget_messages_by_idsCs
(	RRRRRRbRcRgRl(((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyR_*s	ROcBseZdZeedZedZedZeeeZedZ	edZ
ee	e
ZedZRS(cCs||_||_dS(N(RR(R
tdbR((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyRNs	cCs3|jd|jftjt|jdS(Ns-SELECT hashes FROM hash_id_request WHERE id=?i(RRRtloadsRR(R
R((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyRQRs	
cCs$|jd|jf|jdS(Ns0SELECT timestamp FROM hash_id_request WHERE id=?i(RRR(R
R((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyt_get_timestampYs	
cCs|jd||jfdS(Ns1UPDATE hash_id_request SET timestamp=? WHERE id=?(RR(R
RR((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyt_set_timestamp_s	cCs$|jd|jf|jdS(Ns1SELECT message_id FROM hash_id_request WHERE id=?i(RRR(R
R((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyt_get_message_idfs	
cCs|jd||jfdS(Ns2UPDATE hash_id_request SET message_id=? WHERE id=?(RR(R
RR((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyt_set_message_idls	cCs|jd|jfdS(Ns&DELETE FROM hash_id_request WHERE id=?(RR(R
R((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pytremovess(
RRRtpropertyRRQRoRpt	timestampRqRrRfRs(((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyROLs	RWcBs eZdZedZRS(cCs||_||_|j}z#|jd|f|j}Wd|jX|d|_|d|_tj	t
|d|_dS(Ns2SELECT queue, timestamp, data FROM task WHERE id=?iii(RRRRRtcloseRXRuRRnRRY(R
RmRRR((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyRzs			


cCs|jd|jfdS(NsDELETE FROM task WHERE id=?(RR(R
R((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyRss(RRRRRs(((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyRWxs	cCsi|j}y|jdWn1tjtjfk
rP|j|jnX|j|jdS(seCreate all tables needed by a L{HashIdStore}.

    @param db: A connection to a SQLite database.
    s<CREATE TABLE hash (id INTEGER PRIMARY KEY, hash BLOB UNIQUE)N(RRR(tOperationalErrorR)Rvtrollbacktcommit(RmR((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyR
s

cCs|j}yR|jd|jd|jd|jd|jd|jdWn(tjk
r|j|jnX|j|jdS(sfCreate all tables needed by a L{PackageStore}.

    @param db: A connection to a SQLite database.
    s,CREATE TABLE locked (id INTEGER PRIMARY KEY)s/CREATE TABLE available (id INTEGER PRIMARY KEY)s7CREATE TABLE available_upgrade (id INTEGER PRIMARY KEY)s/CREATE TABLE installed (id INTEGER PRIMARY KEY)skCREATE TABLE hash_id_request (id INTEGER PRIMARY KEY, timestamp TIMESTAMP, message_id INTEGER, hashes BLOB)sVCREATE TABLE task (id INTEGER PRIMARY KEY, queue TEXT, timestamp TIMESTAMP, data BLOB)N(RRR(RwRvRxRy(RmR((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyR.s	






cCsi|j}y|jdWn1tjtjfk
rP|j|jnX|j|jdS(Ns8CREATE TABLE message (id INTEGER PRIMARY KEY, data BLOB)(RRR(RwR)RvRxRy(RmR((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyR`s

(RRNR(tImportErrort	pysqlite2Rt
landscape.libRtlandscape.lib.storeRt	ExceptionRRtobjectRR+R_RORWR
R.R`(((s;/usr/lib/python2.7/dist-packages/landscape/package/store.pyt<module>s"
F",		!