Skip to content
Snippets Groups Projects
Commit 300b392e authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

Conforms to the new abstract scheme for database drivers

parent d61739b6
Branches
Tags
No related merge requests found
...@@ -3,47 +3,23 @@ ...@@ -3,47 +3,23 @@
# Andre Anjos <andre.dos.anjos@gmail.com> # Andre Anjos <andre.dos.anjos@gmail.com>
# Wed 18 May 09:28:44 2011 # Wed 18 May 09:28:44 2011
"""The Idiap Replay attack database consists of Photo and Video attacks to """The Replay-Attack Database for face spoofing consists of 1300 video clips of
different identities under different illumination conditions. photo and video attack attempts to 50 clients, under different lighting
conditions. This Database was produced at the Idiap Research Institute, in
Switzerland.
If you use this database in your publication, please cite the following paper
on your references:
@INPROCEEDINGS{Chingovska_BIOSIG-2012,
author = {Chingovska, Ivana and Anjos, Andr{\'{e}} and Marcel, S{\'{e}}bastien},
keywords = {biometric, Counter-Measures, Local Binary Patterns, Spoofing Attacks},
month = september,
title = {On the Effectiveness of Local Binary Patterns in Face Anti-spoofing},
journal = {IEEE BIOSIG 2012},
year = {2012},
}
""" """
import os
def dbname():
'''Returns the database name'''
return 'replay'
def version():
'''Returns the current version number defined in setup.py (DRY)'''
import pkg_resources # part of setuptools
return pkg_resources.require('bob.db.%s' % dbname())[0].version
def location():
'''Returns the directory that contains the data'''
return os.path.dirname(os.path.realpath(__file__))
def files():
'''Returns a python iterable with all auxiliary files needed'''
return ('db.sql3',)
def type():
'''Returns the type of auxiliary files you have for this database
If you return 'sqlite', then we append special actions such as 'dbshell'
on 'bob_dbmanage.py' automatically for you. Otherwise, we don't.
If you use auxiliary text files, just return 'text'. We may provide
special services for those types in the future.
'''
return 'sqlite'
# these are required for the dbmanage.py driver
from .query import Database from .query import Database
from .commands import add_commands __all__ = dir()
__all__ = ['Database',]
#!/usr/bin/env python #!/usr/bin/env python
# vim: set fileencoding=utf-8 : # vim: set fileencoding=utf-8 :
# Andre Anjos <andre.anjos@idiap.ch> # Andre Anjos <andre.dos.anjos@gmail.com>
# Tue 28 Jun 2011 15:20:09 CEST # Wed 15 Aug 11:26:11 2012
"""Commands this database can respond to. """Bob Database Driver entry-point for the Replay Attack Database
""" """
import os import os
import sys import sys
from bob.db.driver import Interface as BaseInterface
def reverse(args): def reverse(args):
"""Returns a list of file database identifiers given the path stems""" """Returns a list of file database identifiers given the path stems"""
...@@ -73,53 +74,45 @@ def path_command(subparsers): ...@@ -73,53 +74,45 @@ def path_command(subparsers):
parser.set_defaults(func=path) #action parser.set_defaults(func=path) #action
def add_commands(parser): class Interface(BaseInterface):
"""Adds my subset of options and arguments to the top-level parser. For
details on syntax, please consult:
http://docs.python.org/dev/library/argparse.html def name(self):
return 'replay'
The strategy assumed here is that each command will have its own set of def version(self):
options that are relevant to that command. So, we just scan such commands and import pkg_resources # part of setuptools
attach the options from those. return pkg_resources.require('bob.db.%s' % self.name())[0].version
"""
from . import dbname, location, version, type, files def location(self):
from bob.db.utils import standard_commands return os.path.dirname(os.path.realpath(__file__))
from . import __doc__ as dbdoc
from argparse import RawDescriptionHelpFormatter
# creates a top-level parser for this database def files(self):
myname = dbname() return ('db.sql3',)
top_level = parser.add_parser(myname,
formatter_class=RawDescriptionHelpFormatter,
help="Photo/Video Replay attack database", description=dbdoc)
top_level.set_defaults(dbname=myname)
top_level.set_defaults(location=location())
top_level.set_defaults(version=version())
top_level.set_defaults(type=type())
top_level.set_defaults(files=files())
# declare it has subparsers for each of the supported commands def type(self):
subparsers = top_level.add_subparsers(title="subcommands") return 'sqlite'
# attach standard commands def add_commands(self, parser):
standard_commands(subparsers, type(), files())
# get the "create" action from a submodule from . import __doc__ as docs
from .create import add_command as create_command
create_command(subparsers) subparsers = self.setup_parser(parser,
"Photo/Video Replay attack database", docs)
# get the "dumplist" action from a submodule # get the "create" action from a submodule
from .dumplist import add_command as dumplist_command from .create import add_command as create_command
dumplist_command(subparsers) create_command(subparsers)
# get the "checkfiles" action from a submodule # get the "dumplist" action from a submodule
from .checkfiles import add_command as checkfiles_command from .dumplist import add_command as dumplist_command
checkfiles_command(subparsers) dumplist_command(subparsers)
# adds the "reverse" command # get the "checkfiles" action from a submodule
reverse_command(subparsers) from .checkfiles import add_command as checkfiles_command
checkfiles_command(subparsers)
# adds the "path" command # adds the "reverse" command
path_command(subparsers) reverse_command(subparsers)
# adds the "path" command
path_command(subparsers)
...@@ -11,9 +11,11 @@ import os ...@@ -11,9 +11,11 @@ import os
import logging import logging
from bob.db import utils from bob.db import utils
from .models import * from .models import *
from . import dbname, type, location, files from .driver import Interface
SQLITE_FILE = os.path.join(location(), files()[0]) INFO = Interface()
SQLITE_FILE = os.path.join(INFO.location(), INFO.files()[0])
class Database(object): class Database(object):
"""The dataset class opens and maintains a connection opened to the Database. """The dataset class opens and maintains a connection opened to the Database.
...@@ -32,7 +34,7 @@ class Database(object): ...@@ -32,7 +34,7 @@ class Database(object):
self.session = None self.session = None
else: else:
self.session = utils.session(type(), location(), files()[0]) self.session = utils.session(type(), INFO.location(), files()[0])
def is_valid(self): def is_valid(self):
"""Returns if a valid session has been opened for reading the database""" """Returns if a valid session has been opened for reading the database"""
...@@ -87,7 +89,7 @@ class Database(object): ...@@ -87,7 +89,7 @@ class Database(object):
""" """
if not self.is_valid(): if not self.is_valid():
raise RuntimeError, "Database '%s' cannot be found at expected location '%s'. Create it and then try re-connecting using Database.connect()" % (dbname(), SQLITE_FILE) raise RuntimeError, "Database '%s' cannot be found at expected location '%s'. Create it and then try re-connecting using Database.connect()" % (INFO.name(), SQLITE_FILE)
def check_validity(l, obj, valid, default): def check_validity(l, obj, valid, default):
"""Checks validity of user input data against a set of valid values""" """Checks validity of user input data against a set of valid values"""
...@@ -157,7 +159,7 @@ class Database(object): ...@@ -157,7 +159,7 @@ class Database(object):
"""Returns the names of all registered protocols""" """Returns the names of all registered protocols"""
if not self.is_valid(): if not self.is_valid():
raise RuntimeError, "Database '%s' cannot be found at expected location '%s'. Create it and then try re-connecting using Database.connect()" % (dbname(), SQLITE_FILE) raise RuntimeError, "Database '%s' cannot be found at expected location '%s'. Create it and then try re-connecting using Database.connect()" % (INFO.name(), SQLITE_FILE)
return tuple([k.name for k in self.session.query(Protocol)]) return tuple([k.name for k in self.session.query(Protocol)])
...@@ -165,7 +167,7 @@ class Database(object): ...@@ -165,7 +167,7 @@ class Database(object):
"""Tells if a certain protocol is available""" """Tells if a certain protocol is available"""
if not self.is_valid(): if not self.is_valid():
raise RuntimeError, "Database '%s' cannot be found at expected location '%s'. Create it and then try re-connecting using Database.connect()" % (dbname(), SQLITE_FILE) raise RuntimeError, "Database '%s' cannot be found at expected location '%s'. Create it and then try re-connecting using Database.connect()" % (INFO.name(), SQLITE_FILE)
return self.session.query(Protocol).filter(Protocol.name==name).count() != 0 return self.session.query(Protocol).filter(Protocol.name==name).count() != 0
...@@ -174,7 +176,7 @@ class Database(object): ...@@ -174,7 +176,7 @@ class Database(object):
an error if that does not exist.""" an error if that does not exist."""
if not self.is_valid(): if not self.is_valid():
raise RuntimeError, "Database '%s' cannot be found at expected location '%s'. Create it and then try re-connecting using Database.connect()" % (dbname(), SQLITE_FILE) raise RuntimeError, "Database '%s' cannot be found at expected location '%s'. Create it and then try re-connecting using Database.connect()" % (INFO.name(), SQLITE_FILE)
return self.session.query(Protocol).filter(Protocol.name==name).one() return self.session.query(Protocol).filter(Protocol.name==name).one()
...@@ -224,7 +226,7 @@ class Database(object): ...@@ -224,7 +226,7 @@ class Database(object):
""" """
if not self.is_valid(): if not self.is_valid():
raise RuntimeError, "Database '%s' cannot be found at expected location '%s'. Create it and then try re-connecting using Database.connect()" % (dbname(), SQLITE_FILE) raise RuntimeError, "Database '%s' cannot be found at expected location '%s'. Create it and then try re-connecting using Database.connect()" % (INFO.name(), SQLITE_FILE)
fobj = self.session.query(File).filter(File.id.in_(ids)) fobj = self.session.query(File).filter(File.id.in_(ids))
retval = [] retval = []
...@@ -246,7 +248,7 @@ class Database(object): ...@@ -246,7 +248,7 @@ class Database(object):
""" """
if not self.is_valid(): if not self.is_valid():
raise RuntimeError, "Database '%s' cannot be found at expected location '%s'. Create it and then try re-connecting using Database.connect()" % (dbname(), SQLITE_FILE) raise RuntimeError, "Database '%s' cannot be found at expected location '%s'. Create it and then try re-connecting using Database.connect()" % (INFO.name(), SQLITE_FILE)
fobj = self.session.query(File).filter(File.path.in_(paths)) fobj = self.session.query(File).filter(File.path.in_(paths))
retval = [] retval = []
...@@ -278,7 +280,7 @@ class Database(object): ...@@ -278,7 +280,7 @@ class Database(object):
""" """
if not self.is_valid(): if not self.is_valid():
raise RuntimeError, "Database '%s' cannot be found at expected location '%s'. Create it and then try re-connecting using Database.connect()" % (dbname(), SQLITE_FILE) raise RuntimeError, "Database '%s' cannot be found at expected location '%s'. Create it and then try re-connecting using Database.connect()" % (INFO.name(), SQLITE_FILE)
from bob.io import save from bob.io import save
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment