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_DROP = 'DROP TABLE package_cache'
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_DROP = 'DROP TABLE values_cache'
SCHEMA_VALUES_NAME = 'values_cache'
_BaseError = ()
_dbClass = None
_dbconnect(config)

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

_delitem(cpv)

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

_getitem(cpv)

get cpv’s values. override this in derived classess

_initdb_con(config)

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

_insert_cpv(cpv)

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

_sfilter(s)

meta escaping, returns quoted string for use in sql statements

_supports_replace = False
_table_exists(tbl)

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
commit()
complete_eclass_entries = True
get(k, x=None)
get_matches(match_dict)

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.

has_key(cpv)
items()
iteritems()
iterkeys()
keys()

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
sync(rate=0)
validate_entry(entry, ebuild_hash, eclass_db)
validation_chf = 'mtime'