Commit 6333338e authored by Manuel Günther's avatar Manuel Günther

Unified driver API; added tests for reverse and path commands.

parents 5f394119 e77cee9a
...@@ -28,7 +28,7 @@ def add_files(session, imagedir, verbose): ...@@ -28,7 +28,7 @@ def add_files(session, imagedir, verbose):
session.add(Client(int(v[0]), v[1], v[2], v[5])) session.add(Client(int(v[0]), v[1], v[2], v[5]))
client_dict[v[0]] = True client_dict[v[0]] = True
session_id = int(v[3].split('s')[1]) session_id = int(v[3].split('s')[1])
base_path = os.path.join(subdir,os.path.basename(filename).split('.')[0]) base_path = os.path.join(subdir, os.path.basename(filename).split('.')[0])
if verbose: print "Adding file '%s'..." %(base_path, ) if verbose: print "Adding file '%s'..." %(base_path, )
session.add(File(int(v[0]), base_path, v[4], v[6], session_id)) session.add(File(int(v[0]), base_path, v[4], v[6], session_id))
......
...@@ -18,10 +18,11 @@ def dumplist(args): ...@@ -18,10 +18,11 @@ def dumplist(args):
r = db.objects( r = db.objects(
protocol=args.protocol, protocol=args.protocol,
purposes=args.purposes, purposes=args.purpose,
model_ids=(args.client,), model_ids=(args.client,),
groups=args.groups, groups=args.group,
languages=args.languages languages=args.language,
classes=args.sclass
) )
output = sys.stdout output = sys.stdout
...@@ -140,21 +141,21 @@ class Interface(BaseInterface): ...@@ -140,21 +141,21 @@ class Interface(BaseInterface):
db = Database() db = Database()
parser = subparsers.add_parser('dumplist', help=dumplist.__doc__) parser = subparsers.add_parser('dumplist', help=dumplist.__doc__)
parser.add_argument('-d', '--directory', dest="directory", default='', help="if given, this path will be prepended to every entry returned.") parser.add_argument('-d', '--directory', default='', help="if given, this path will be prepended to every entry returned.")
parser.add_argument('-e', '--extension', dest="extension", default='', help="if given, this extension will be appended to every entry returned.") parser.add_argument('-e', '--extension', default='', help="if given, this extension will be appended to every entry returned.")
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.", choices=db.protocol_names() if db.is_valid() else ()) parser.add_argument('-p', '--protocol', help="if given, limits the dump to a particular subset of the data that corresponds to the given protocol.", choices=db.protocol_names() if db.is_valid() else ())
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.", choices=db.purposes() if db.is_valid() else ()) parser.add_argument('-u', '--purpose', help="if given, this value will limit the output files to those designed for the given purposes.", choices=db.purposes() if db.is_valid() else ())
parser.add_argument('-C', '--client', dest="client", default=None, type=int, help="if given, limits the dump to a particular client", choices=db.clients() if db.is_valid() else ()) parser.add_argument('-C', '--client', type=int, help="if given, limits the dump to a particular client", choices=db.model_ids() if db.is_valid() else ())
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.", choices=db.groups() if db.is_valid() else ()) parser.add_argument('-g', '--group', help="if given, this value will limit the output files to those belonging to a particular protocolar group.", choices=db.groups() if db.is_valid() else ())
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.", choices=db.languages() if db.is_valid() else ()) parser.add_argument('-l', '--language', help="if given, this value will limit the output files to those belonging to the given languages.", choices=db.languages() if db.is_valid() else ())
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.", choices=('client', 'impostor', '')) parser.add_argument('-c', '--class', dest='sclass', help="if given, this value will limit the output files to those belonging to the given classes.", choices=('client', 'impostor'))
parser.add_argument('--self-test', dest="selftest", action='store_true', help=argparse.SUPPRESS) parser.add_argument('--self-test', dest="selftest", action='store_true', help=argparse.SUPPRESS)
parser.set_defaults(func=dumplist) #action parser.set_defaults(func=dumplist) #action
# the "checkfiles" action # the "checkfiles" action
parser = subparsers.add_parser('checkfiles', help=checkfiles.__doc__) parser = subparsers.add_parser('checkfiles', help=checkfiles.__doc__)
parser.add_argument('-d', '--directory', dest="directory", default='', help="if given, this path will be prepended to every entry returned.") parser.add_argument('-d', '--directory', default='', help="if given, this path will be prepended to every entry returned.")
parser.add_argument('-e', '--extension', dest="extension", default='', help="if given, this extension will be appended to every entry returned.") parser.add_argument('-e', '--extension', default='', help="if given, this extension will be appended to every entry returned.")
parser.add_argument('--self-test', dest="selftest", action='store_true', help=argparse.SUPPRESS) parser.add_argument('--self-test', dest="selftest", action='store_true', help=argparse.SUPPRESS)
parser.set_defaults(func=checkfiles) #action parser.set_defaults(func=checkfiles) #action
...@@ -166,8 +167,8 @@ class Interface(BaseInterface): ...@@ -166,8 +167,8 @@ class Interface(BaseInterface):
# adds the "path" command # adds the "path" command
parser = subparsers.add_parser('path', help=path.__doc__) 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.") parser.add_argument('-d', '--directory', default='', help="if given, this path will be prepended to every entry returned.")
parser.add_argument('-e', '--extension', dest="extension", default='', help="if given, this extension will be appended to every entry returned.") parser.add_argument('-e', '--extension', default='', help="if given, this extension will be appended to every entry returned.")
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('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", action='store_true', help=argparse.SUPPRESS) parser.add_argument('--self-test', dest="selftest", action='store_true', help=argparse.SUPPRESS)
parser.set_defaults(func=path) #action parser.set_defaults(func=path) #action
......
...@@ -69,21 +69,12 @@ class BancaDatabaseTest(unittest.TestCase): ...@@ -69,21 +69,12 @@ class BancaDatabaseTest(unittest.TestCase):
self.assertEqual(len(db.zobjects(groups=group, model_ids=model_id)), 105) self.assertEqual(len(db.zobjects(groups=group, model_ids=model_id)), 105)
def test03_driver_api(self):
def test03_manage_dumplist_1(self):
from bob.db.script.dbmanage import main from bob.db.script.dbmanage import main
self.assertEqual(main('banca dumplist --self-test'.split()), 0) self.assertEqual(main('banca dumplist --self-test'.split()), 0)
self.assertEqual(main('banca dumplist --protocol=P --class=client --group=dev --purpose=enrol --client=1008 --self-test'.split()), 0)
def test04_manage_dumplist_2(self):
from bob.db.script.dbmanage import main
self.assertEqual(main('banca dumplist --protocol=P --classes=client --groups=dev --purposes=enrol --self-test'.split()), 0)
def test05_manage_checkfiles(self):
from bob.db.script.dbmanage import main
self.assertEqual(main('banca checkfiles --self-test'.split()), 0) self.assertEqual(main('banca checkfiles --self-test'.split()), 0)
self.assertEqual(main('banca reverse 05/1021_f_g2_s05_1026_en_3 --self-test'.split()), 0)
self.assertEqual(main('banca path 2327 --self-test'.split()), 0)
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