Source code for pysteg.sql
"""
This package provides an interface to an SQL database to store
image features for steganalysis.
The tables represented by SQLObject classes are visible directly
in the package. The different submodules provide functionality:
:setup: functions to create tables and enter standard feature def's
:imageset: enter images in the db and create test and training sets
:features: establish new feature vectors
:extract: extracting features from images and enter them in the db
:queue: the class and SQL table for the job queue
:stats: statistical analysis of features in the database
:svmodel: managing SVM classifiers using features from the db
:scaling: scaling models for use with learning classifiers
"""
print "[pysteg.sql]"
from sqlobject import sqlhub,connectionForURI,SQLObject
from .tables import *
from .config import config
[docs]def sqlConnect():
"""Connect to the data base, using connection data from the
config object."""
url = config.get( "sql", "url" )
verbosity = config.getint( "sql", "verbosity" )
try:
s = sqlhub.processConnection
if verbosity:
print "Already connected to", s
except:
if verbosity:
print "Connecting to", url
sqlhub.processConnection = connectionForURI( url )
return sqlhub.processConnection
[docs]def getImageSet(name):
"""Look up an image set by its key. The ImageSet table is tried
first, and the TestSet table if that fails. If the argument is
itself an SQLObject, this is returned as is. It should be used
by any function intended to take a polymorphic image set argument.
"""
if isinstance(name,SQLObject):
return name
try:
T = ImageSet.byName(name)
except:
T = TestSet.byName(name)
return T
[docs]class MissingDataException(Exception):
"""This exception is raised when prerequisite data are found
to be missing from the database during calculations.
Catching it allows client processes to proceed to the next
task in the queue."""
pass
[docs]class ConfigError(Exception):
"Error in the configuration file."
pass
[docs]class DataIntegrityException(Exception):
"Integrity error in the database contents."
pass