pypicloud.cache.sql module

Store package data in a SQL database

class pypicloud.cache.sql.JSONEncodedDict(*args, **kwargs)[source]

Bases: sqlalchemy.sql.type_api.TypeDecorator

Represents an immutable structure as a json-encoded string.

impl[source]

alias of sqlalchemy.sql.sqltypes.TEXT

process_bind_param(value, dialect)[source]

Receive a bound parameter value to be converted.

Subclasses override this method to return the value that should be passed along to the underlying TypeEngine object, and from there to the DBAPI execute() method.

The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.

This operation should be designed with the reverse operation in mind, which would be the process_result_value method of this class.

Parameters:
  • value – Data to operate upon, of any type expected by this method in the subclass. Can be None.
  • dialect – the Dialect in use.
process_result_value(value, dialect)[source]

Receive a result-row column value to be converted.

Subclasses should implement this method to operate on data fetched from the database.

Subclasses override this method to return the value that should be passed back to the application, given a value that is already processed by the underlying TypeEngine object, originally from the DBAPI cursor method fetchone() or similar.

The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.

Parameters:
  • value – Data to operate upon, of any type expected by this method in the subclass. Can be None.
  • dialect – the Dialect in use.

This operation should be designed to be reversible by the “process_bind_param” method of this class.

class pypicloud.cache.sql.MutableDict[source]

Bases: sqlalchemy.ext.mutable.Mutable, dict

SQLAlchemy dict field that tracks changes

classmethod coerce(key, value)[source]

Convert plain dictionaries to MutableDict.

class pypicloud.cache.sql.SQLCache(request=None, dbmaker=None, graceful_reload=False, **kwargs)[source]

Bases: pypicloud.cache.base.ICache

Caching database that uses SQLAlchemy

all(name)[source]

Search for all versions of a package

Parameters:
name : str

The name of the package

Returns:
packages : list

List of all Package s with the given name

check_health()[source]

Check the health of the cache backend

Returns:
(healthy, status) : (bool, str)

Tuple that describes the health status and provides an optional status message

clear(package)[source]

Remove this package from the caching database

Parameters:
package : Package
clear_all()[source]

Clear all cached packages from the database

classmethod configure(settings)[source]

Configure the cache method with app settings

distinct()[source]

Get all distinct package names

Returns:
names : list

List of package names

fetch(filename)[source]

Get matching package if it exists

Parameters:
filename : str

Name of the package file

Returns:
package : Package
new_package(*args, **kwargs)[source]
classmethod postfork(**kwargs)[source]

This method will be called after uWSGI forks

reload_from_storage(clear=True)[source]

Make sure local database is populated with packages

reload_if_needed()[source]

Reload packages from storage backend if cache is empty

This will be called when the server first starts

save(package)[source]

Save this package to the database

Parameters:
package : Package
search(criteria, query_type)[source]

Perform a search.

Queries are performed as follows:

For the AND query_type, queries within a column will utilize the AND operator, but will not conflict with queries in another column.

(column1 LIKE ‘%a%’ AND column1 LIKE ‘%b%’) OR (column2 LIKE ‘%c%’ AND column2 LIKE ‘%d%’)

For the OR query_type, all queries will utilize the OR operator:

(column1 LIKE ‘%a%’ OR column1 LIKE ‘%b%’) OR (column2 LIKE ‘%c%’ OR column2 LIKE ‘%d%’)
summary()[source]

Summarize package metadata

Returns:
packages : list

List of package dicts, each of which contains ‘name’, ‘summary’, and ‘last_modified’.

class pypicloud.cache.sql.SQLPackage(name, version, filename, last_modified=None, summary=None, **kwargs)[source]

Bases: pypicloud.models.Package, sqlalchemy.orm.decl_api.Base

Python package stored in SQLAlchemy

data[source]
filename[source]
last_modified[source]
name[source]
summary[source]
version[source]
class pypicloud.cache.sql.TZAwareDateTime(*args, **kwargs)[source]

Bases: sqlalchemy.sql.type_api.TypeDecorator

cache_ok = True[source]
impl[source]

alias of sqlalchemy.sql.sqltypes.DateTime

process_bind_param(value, dialect)[source]

Receive a bound parameter value to be converted.

Subclasses override this method to return the value that should be passed along to the underlying TypeEngine object, and from there to the DBAPI execute() method.

The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.

This operation should be designed with the reverse operation in mind, which would be the process_result_value method of this class.

Parameters:
  • value – Data to operate upon, of any type expected by this method in the subclass. Can be None.
  • dialect – the Dialect in use.
process_result_value(value, dialect)[source]

Receive a result-row column value to be converted.

Subclasses should implement this method to operate on data fetched from the database.

Subclasses override this method to return the value that should be passed back to the application, given a value that is already processed by the underlying TypeEngine object, originally from the DBAPI cursor method fetchone() or similar.

The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.

Parameters:
  • value – Data to operate upon, of any type expected by this method in the subclass. Can be None.
  • dialect – the Dialect in use.

This operation should be designed to be reversible by the “process_bind_param” method of this class.

pypicloud.cache.sql.create_schema(engine)[source]

Create the database schema if needed

Parameters:
engine : sqlalchemy.Engine

Notes

The method should only be called after importing all modules containing models which extend the Base object.

pypicloud.cache.sql.drop_schema(engine)[source]

Drop the database schema

Parameters:
engine : sqlalchemy.Engine

Notes

The method should only be called after importing all modules containing models which extend the Base object.