Commit 0d5ff04c authored by Laurent EL SHAFEY's avatar Laurent EL SHAFEY

Cleanup

parent a624ee4a
......@@ -17,7 +17,7 @@ def checkfiles(args):
from .query import Database
db = Database()
r = db.files(
r = db.objects(
directory=args.directory,
extension=args.extension,
protocol=args.protocol,
......@@ -28,11 +28,13 @@ def checkfiles(args):
)
# go through all files, check if they are available on the filesystem
good = {}
bad = {}
for id, f in r.items():
if os.path.exists(f): good[id] = f
else: bad[id] = f
good = []
bad = []
for f in r:
if os.path.exists(f.make_path(args.directory, args.extension)):
good.append(f)
else:
bad.append(f)
# report
output = sys.stdout
......@@ -41,10 +43,10 @@ def checkfiles(args):
output = null()
if bad:
for id, f in bad.items():
output.write('Cannot find file "%s"\n' % (f,))
for f in bad:
output.write('Cannot find file "%s"\n' % (f.make_path(args.directory, args.extension),))
output.write('%d files (out of %d) were not found at "%s"\n' % \
(len(bad), len(r), args.directory))
(len(bad), len(r), args.directory))
return 0
......@@ -55,13 +57,17 @@ def add_command(subparsers):
parser = subparsers.add_parser('checkfiles', help=checkfiles.__doc__)
from .query import Database
db = Database()
parser.add_argument('-d', '--directory', dest="directory", default='', help="if given, this path will be prepended to every entry returned (defaults to '%(default)s')")
parser.add_argument('-e', '--extension', dest="extension", default='', help="if given, this extension will be appended to every entry returned (defaults to '%(default)s')")
parser.add_argument('-p', '--protocol', dest="protocol", default='', help="if given, limits the check to a particular subset of the data that corresponds to the given protocol (defaults to '%(default)s')", choices=('P', 'G', 'Mc', 'Md', 'Ma', 'Ud', 'Ua', ''))
parser.add_argument('-u', '--purposes', dest="purposes", default='', help="if given, this value will limit the output files to those designed for the given purposes. (defaults to '%(default)s')", choices=('enrol', 'probe', ''))
parser.add_argument('-p', '--protocol', dest="protocol", default='', help="if given, limits the check to a particular subset of the data that corresponds to the given protocol (defaults to '%(default)s')", choices=db.protocol_names())
parser.add_argument('-u', '--purposes', dest="purposes", default='', help="if given, this value will limit the output files to those designed for the given purposes. (defaults to '%(default)s')", choices=db.purposes())
# TODO: model_ids
parser.add_argument('-g', '--groups', dest="groups", default='', help="if given, this value will limit the output files to those belonging to a particular protocolar group. (defaults to '%(default)s')", choices=('g1', 'g2', 'world', ''))
parser.add_argument('-l', '--languages', dest="languages", default='', help="if given, this value will limit the output files to those belonging to the given languages. (defaults to '%(default)s')", choices=('en', ''))
parser.add_argument('-g', '--groups', dest="groups", default='', help="if given, this value will limit the output files to those belonging to a particular protocolar group. (defaults to '%(default)s')", choices=db.groups())
parser.add_argument('-l', '--languages', dest="languages", default='', help="if given, this value will limit the output files to those belonging to the given languages. (defaults to '%(default)s')", choices=db.languages())
parser.add_argument('-c', '--classes', dest="classes", default='', help="if given, this value will limit the output files to those belonging to the given classes. (defaults to '%(default)s')", choices=('client', 'impostor', ''))
parser.add_argument('--self-test', dest="selftest", default=False,
action='store_true', help=SUPPRESS)
......
......@@ -51,18 +51,6 @@ def add_subworlds(session, verbose):
if verbose: print "Adding client '%d' to subworld '%s'..." %(c_id, snames[k])
su.clients.append(session.query(Client).filter(Client.id == c_id).first())
"""
def add_sessions(session, verbose):
""Adds relations between sessions and scenarios""
for i in range(1,5):
session.add(Session(i,'controlled'))
for i in range(5,9):
session.add(Session(i,'degraded'))
for i in range(9,13):
session.add(Session(i,'adverse'))
"""
def add_protocols(session, verbose):
"""Adds protocols"""
......@@ -205,7 +193,6 @@ def create(args):
s = session_try_nolock(args.type, args.files[0], echo=(args.verbose >= 2))
add_files(s, args.imagedir, args.verbose)
add_subworlds(s, args.verbose)
#add_sessions(s, args.verbose)
add_protocols(s, args.verbose)
s.commit()
s.close()
......
......@@ -2,13 +2,77 @@
# vim: set fileencoding=utf-8 :
# Laurent El Shafey <laurent.el-shafey@idiap.ch>
"""Commands the BANCA database can respond to.
"""Bob Database Driver entry-point for the BANCA
"""
import os
import sys
from bob.db.driver import Interface as BaseInterface
def reverse(args):
"""Returns a list of file database identifiers given the path stems"""
from .query import Database
db = Database()
output = sys.stdout
if args.selftest:
from bob.db.utils import null
output = null()
r = db.reverse(args.path)
for id in r: output.write('%d\n' % id)
if not r: return 1
return 0
def reverse_command(subparsers):
"""Adds the specific options for the reverse command"""
from argparse import SUPPRESS
parser = subparsers.add_parser('reverse', help=reverse.__doc__)
parser.add_argument('path', nargs='+', type=str, help="one or more path stems to look up. If you provide more than one, files which cannot be reversed will be omitted from the output.")
parser.add_argument('--self-test', dest="selftest", default=False,
action='store_true', help=SUPPRESS)
parser.set_defaults(func=reverse) #action
def path(args):
"""Returns a list of fully formed paths or stems given some file id"""
from .query import Database
db = Database()
output = sys.stdout
if args.selftest:
from bob.db.utils import null
output = null()
r = db.paths(args.id, prefix=args.directory, suffix=args.extension)
for path in r: output.write('%s\n' % path)
if not r: return 1
return 0
def path_command(subparsers):
"""Adds the specific options for the path command"""
from argparse import SUPPRESS
parser = subparsers.add_parser('path', help=path.__doc__)
parser.add_argument('-d', '--directory', dest="directory", default='', help="if given, this path will be prepended to every entry returned (defaults to '%(default)s')")
parser.add_argument('-e', '--extension', dest="extension", default='', help="if given, this extension will be appended to every entry returned (defaults to '%(default)s')")
parser.add_argument('id', nargs='+', type=int, help="one or more file ids to look up. If you provide more than one, files which cannot be found will be omitted from the output. If you provide a single id to lookup, an error message will be printed if the id does not exist in the database. The exit status will be non-zero in such case.")
parser.add_argument('--self-test', dest="selftest", default=False,
action='store_true', help=SUPPRESS)
parser.set_defaults(func=path) #action
class Interface(BaseInterface):
def name(self):
......@@ -46,3 +110,8 @@ class Interface(BaseInterface):
from .checkfiles import add_command as checkfiles_command
checkfiles_command(subparsers)
# adds the "reverse" command
reverse_command(subparsers)
# adds the "path" command
path_command(subparsers)
......@@ -17,7 +17,7 @@ def dumplist(args):
from .query import Database
db = Database()
r = db.files(
r = db.objects(
directory=args.directory,
extension=args.extension,
protocol=args.protocol,
......@@ -32,8 +32,8 @@ def dumplist(args):
from bob.db.utils import null
output = null()
for id, f in r.items():
output.write('%s\n' % (f,))
for f in r:
output.write('%s\n' % (f.make_path(args.directory, args.extension),))
return 0
......@@ -44,13 +44,17 @@ def add_command(subparsers):
parser = subparsers.add_parser('dumplist', help=dumplist.__doc__)
from .query import Database
db = Database()
parser.add_argument('-d', '--directory', dest="directory", default='', help="if given, this path will be prepended to every entry returned (defaults to '%(default)s')")
parser.add_argument('-e', '--extension', dest="extension", default='', help="if given, this extension will be appended to every entry returned (defaults to '%(default)s')")
parser.add_argument('-p', '--protocol', dest="protocol", default='', help="if given, limits the dump to a particular subset of the data that corresponds to the given protocol (defaults to '%(default)s')", choices=('P', 'G', 'Mc', 'Md', 'Ma', 'Ud', 'Ua', ''))
parser.add_argument('-u', '--purposes', dest="purposes", default='', help="if given, this value will limit the output files to those designed for the given purposes. (defaults to '%(default)s')", choices=('enrol', 'probe', ''))
parser.add_argument('-p', '--protocol', dest="protocol", default='', help="if given, limits the dump to a particular subset of the data that corresponds to the given protocol (defaults to '%(default)s')", choices=db.protocol_names())
parser.add_argument('-u', '--purposes', dest="purposes", default='', help="if given, this value will limit the output files to those designed for the given purposes. (defaults to '%(default)s')", choices=db.purposes())
# TODO: model_ids
parser.add_argument('-g', '--groups', dest="groups", default='', help="if given, this value will limit the output files to those belonging to a particular protocolar group. (defaults to '%(default)s')", choices=('g1', 'g2', 'world', ''))
parser.add_argument('-l', '--languages', dest="languages", default='', help="if given, this value will limit the output files to those belonging to the given languages. (defaults to '%(default)s')", choices=('en', ''))
parser.add_argument('-g', '--groups', dest="groups", default='', help="if given, this value will limit the output files to those belonging to a particular protocolar group. (defaults to '%(default)s')", choices=db.groups())
parser.add_argument('-l', '--languages', dest="languages", default='', help="if given, this value will limit the output files to those belonging to the given languages. (defaults to '%(default)s')", choices=db.languages())
parser.add_argument('-c', '--classes', dest="classes", default='', help="if given, this value will limit the output files to those belonging to the given classes. (defaults to '%(default)s')", choices=('client', 'impostor', ''))
parser.add_argument('--self-test', dest="selftest", default=False,
action='store_true', help=SUPPRESS)
......
......@@ -36,7 +36,7 @@ class BancaDatabaseTest(unittest.TestCase):
from bob.db.script.dbmanage import main
self.assertEqual(main('banca dumplist --protocol=P --classes=client --groups=g1 --purposes=enrol --self-test'.split()), 0)
self.assertEqual(main('banca dumplist --protocol=P --classes=client --groups=dev --purposes=enrol --self-test'.split()), 0)
def test03_manage_checkfiles(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment