Commit d006acdc authored by Pavel KORSHUNOV's avatar Pavel KORSHUNOV

Merge branch 'fldb_clients' into 'master'

Added clients option to filelistdb driver, fix #17

Closes #17

See merge request !34
parents 350cd6cf a6747782
Pipeline #17357 passed with stage
in 21 minutes and 2 seconds
...@@ -25,13 +25,35 @@ import sys ...@@ -25,13 +25,35 @@ import sys
from bob.db.base.driver import Interface as BaseInterface from bob.db.base.driver import Interface as BaseInterface
def clients(args):
"""Dumps lists of client IDs based on your criteria"""
from .query import FileListPadDatabase
db = FileListPadDatabase(args.list_directory, 'pad_filelist')
client_ids = db.client_ids(
protocol=args.protocol,
groups = args.group
)
output = sys.stdout
if args.selftest:
from bob.db.base.utils import null
output = null()
for client in client_ids:
output.write('%s\n' % client)
return 0
def dumplist(args): def dumplist(args):
"""Dumps lists of files based on your criteria""" """Dumps lists of files based on your criteria"""
from .query import FileListPadDatabase from .query import FileListPadDatabase
db = FileListPadDatabase(args.list_directory, 'pad_filelist') db = FileListPadDatabase(args.list_directory, 'pad_filelist')
r = db.objects( file_objects = db.objects(
purposes=args.purpose, purposes=args.purpose,
groups=args.group, groups=args.group,
protocol=args.protocol protocol=args.protocol
...@@ -42,8 +64,8 @@ def dumplist(args): ...@@ -42,8 +64,8 @@ def dumplist(args):
from bob.db.base.utils import null from bob.db.base.utils import null
output = null() output = null()
for f in r: for file_obj in file_objects:
output.write('%s\n' % f.make_path(directory=args.directory, extension=args.extension)) output.write('%s\n' % file_obj.make_path(directory=args.directory, extension=args.extension))
return 0 return 0
...@@ -54,16 +76,16 @@ def checkfiles(args): ...@@ -54,16 +76,16 @@ def checkfiles(args):
from .query import FileListPadDatabase from .query import FileListPadDatabase
db = FileListPadDatabase(args.list_directory, 'pad_filelist') db = FileListPadDatabase(args.list_directory, 'pad_filelist')
r = db.objects(protocol=args.protocol) file_objects = db.objects(protocol=args.protocol)
# go through all files, check if they are available on the filesystem # go through all files, check if they are available on the filesystem
good = [] good = []
bad = [] bad = []
for f in r: for file_obj in file_objects:
if os.path.exists(f.make_path(args.directory, args.extension)): if os.path.exists(file_obj.make_path(args.directory, args.extension)):
good.append(f) good.append(file_obj)
else: else:
bad.append(f) bad.append(file_obj)
# report # report
output = sys.stdout output = sys.stdout
...@@ -72,9 +94,9 @@ def checkfiles(args): ...@@ -72,9 +94,9 @@ def checkfiles(args):
output = null() output = null()
if bad: if bad:
for f in bad: for file_obj in bad:
output.write('Cannot find file "%s"\n' % f.make_path(args.directory, args.extension)) output.write('Cannot find file "%s"\n' % file_obj.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)) output.write('%d files (out of %d) were not found at "%s"\n' % (len(bad), len(file_objects), args.directory))
return 0 return 0
...@@ -101,6 +123,19 @@ class Interface(BaseInterface): ...@@ -101,6 +123,19 @@ class Interface(BaseInterface):
import argparse import argparse
# the "clients" action
parser = subparsers.add_parser('clients', help=dumplist.__doc__)
parser.add_argument('-l', '--list-directory', required=True,
help="The directory which contains the file lists.")
parser.add_argument('-g', '--group',
help="if given, this value will limit the output files to those belonging to a "
"particular group.",
choices=('dev', 'eval', 'train', ''))
parser.add_argument('-p', '--protocol', default=None,
help="If set, the protocol is appended to the directory that contains the file lists.")
parser.add_argument('--self-test', dest="selftest", action='store_true', help=argparse.SUPPRESS)
parser.set_defaults(func=clients) # action
# the "dumplist" action # the "dumplist" action
parser = subparsers.add_parser('dumplist', help=dumplist.__doc__) parser = subparsers.add_parser('dumplist', help=dumplist.__doc__)
parser.add_argument('-l', '--list-directory', required=True, parser.add_argument('-l', '--list-directory', required=True,
...@@ -115,7 +150,7 @@ class Interface(BaseInterface): ...@@ -115,7 +150,7 @@ class Interface(BaseInterface):
choices=('real', 'attack', '')) choices=('real', 'attack', ''))
parser.add_argument('-g', '--group', parser.add_argument('-g', '--group',
help="if given, this value will limit the output files to those belonging to a " help="if given, this value will limit the output files to those belonging to a "
"particular protocolar group.", "particular group.",
choices=('dev', 'eval', 'train', '')) choices=('dev', 'eval', 'train', ''))
parser.add_argument('-p', '--protocol', default=None, parser.add_argument('-p', '--protocol', default=None,
help="If set, the protocol is appended to the directory that contains the file lists.") help="If set, the protocol is appended to the directory that contains the file lists.")
......
...@@ -213,7 +213,7 @@ class FileListPadDatabase(PadDatabase, FileListBioDatabase): ...@@ -213,7 +213,7 @@ class FileListPadDatabase(PadDatabase, FileListBioDatabase):
self.groups(protocol), self.groups(protocol),
default_parameters=self.groups(protocol)) default_parameters=self.groups(protocol))
return self.__client_id_list__(groups, 'for_real', protocol) return sorted(self.__client_id_list__(groups, 'for_real', protocol))
def objects(self, groups=None, protocol=None, purposes=None, model_ids=None, **kwargs): def objects(self, groups=None, protocol=None, purposes=None, model_ids=None, **kwargs):
"""Returns a set of :py:class:`PadFile` objects for the specific query by the user. """Returns a set of :py:class:`PadFile` objects for the specific query by the user.
......
...@@ -66,6 +66,7 @@ def test_query_protocol(): ...@@ -66,6 +66,7 @@ def test_query_protocol():
def test_driver_api(): def test_driver_api():
from bob.db.base.script.dbmanage import main from bob.db.base.script.dbmanage import main
assert main(('pad_filelist clients --list-directory=%s --self-test' % example_dir).split()) == 0
assert main(('pad_filelist dumplist --list-directory=%s --self-test' % example_dir).split()) == 0 assert main(('pad_filelist dumplist --list-directory=%s --self-test' % example_dir).split()) == 0
assert main(('pad_filelist dumplist --list-directory=%s --purpose=real --group=dev --self-test' % assert main(('pad_filelist dumplist --list-directory=%s --purpose=real --group=dev --self-test' %
example_dir).split()) == 0 example_dir).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