portage.cache.sql_template module

class portage.cache.sql_template.SQLDatabase(location, label, auxdbkeys, *args, **config)

Bases: portage.cache.template.database

template class for RDBM based caches

This class is designed such that derivatives don’t have to change much code, mostly constant strings. _BaseError must be an exception class that all Exceptions thrown from the derived RDBMS are derived from.

SCHEMA_INSERT_CPV_INTO_PACKAGE should be modified dependant on the RDBMS, as should SCHEMA_PACKAGE_CREATE- basically you need to deal with creation of a unique pkgid. If the dbapi2 rdbms class has a method of recovering that id, then modify _insert_cpv to remove the extra select.

Creation of a derived class involves supplying _initdb_con, and table_exists. Additionally, the default schemas may have to be modified.

SCHEMA_INSERT_CPV_INTO_PACKAGE = 'INSERT INTO package_cache (label, cpv) VALUES(%s, %s)'
SCHEMA_PACKAGE_CREATE = 'CREATE TABLE package_cache (\t\tpkgid INTEGER PRIMARY KEY, label VARCHAR(255), cpv VARCHAR(255), UNIQUE(label, cpv))'
SCHEMA_PACKAGE_NAME = 'package_cache'
SCHEMA_VALUES_CREATE = 'CREATE TABLE values_cache ( pkgid integer references package_cache (pkgid) on delete cascade, \t\tkey varchar(255), value text, UNIQUE(pkgid, key))'
SCHEMA_VALUES_NAME = 'values_cache'
_BaseError = ()
_dbClass = None

should be overridden if the derived class needs special parameters for initializing the db connection, or cursor


delete a cpv cache entry derived RDBM classes for this must either support cascaded deletes, or override this method


get cpv’s values. override this in derived classess


ensure needed tables are in place. If the derived class needs a different set of table creation commands, overload the approriate SCHEMA_ attributes. If it needs additional execution beyond, override


uses SCHEMA_INSERT_CPV_INTO_PACKAGE, which must be overloaded if the table definition doesn’t support auto-increment columns for pkgid. returns the cpvs new pkgid note this doesn’t commit the transaction. The caller is expected to.

static _internal_eclasses(extern_ec_dict, chf_type, paths)

When serialize_eclasses is False, we have to convert an external eclass dict containing hashed_path objects into an appropriate internal dict containing values of chf_type (and eclass dirs if store_eclass_paths is True).

_setitem(cpv, values)

__setitem__ calls this after readonly checks. override it in derived classes note _eclassees_ key must be handled


meta escaping, returns quoted string for use in sql statements

_supports_replace = False

return true if a table exists derived classes must override this

_validate_entry(chf_type, entry, ebuild_hash, eclass_db)
autocommits = False
cleanse_keys = False
complete_eclass_entries = True
get(k, x=None)

generic function for walking the entire cache db, matching restrictions to filter what cpv’s are returned. Derived classes should override this if they can implement a faster method then pulling each cpv:values, and checking it.

For example, RDBMS derived classes should push the matching logic down to the actual RDBM.


This method should always be overridden. It is provided only for backward compatibility with modules that override iterkeys instead. It will automatically raise a NotImplementedError if iterkeys has not been overridden.

serialize_eclasses = True
store_eclass_paths = True
validate_entry(entry, ebuild_hash, eclass_db)
validation_chf = 'mtime'