From 49e720babc9a8dce885d03acddd2cc6331b4466b Mon Sep 17 00:00:00 2001 From: Guillaume HEUSCH <guillaume.heusch@idiap.ch> Date: Thu, 22 Dec 2016 16:58:52 +0100 Subject: [PATCH] [all] add files as in bob.db.voxforge --- bob/db/fargo/__init__.py | 21 ++++++-- bob/db/fargo/driver.py | 104 +++++++++++++++++++++++++++++++++++++++ bob/db/fargo/query.py | 17 +++++++ buildout.cfg | 2 +- setup.py | 8 +-- 5 files changed, 144 insertions(+), 8 deletions(-) create mode 100644 bob/db/fargo/driver.py create mode 100644 bob/db/fargo/query.py diff --git a/bob/db/fargo/__init__.py b/bob/db/fargo/__init__.py index 2ab1e28..b217859 100644 --- a/bob/db/fargo/__init__.py +++ b/bob/db/fargo/__init__.py @@ -1,3 +1,18 @@ -# see https://docs.python.org/3/library/pkgutil.html -from pkgutil import extend_path -__path__ = extend_path(__path__, __name__) +#!/usr/bin/env python +# encoding: utf-8 +# Guillaume HEUSCH <guillaume.heusch@idiap.ch> +# Thu 22 Dec 16:16:15 CET 2016 + + +from .query import Database +from bob.db.bio_filelist.models import File, Client + +def get_config(): + """Returns a string containing the configuration information. + """ + import bob.extension + return bob.extension.get_config(__name__) + + +# gets sphinx autodoc done right - don't remove it +__all__ = [_ for _ in dir() if not _.startswith('_')] diff --git a/bob/db/fargo/driver.py b/bob/db/fargo/driver.py new file mode 100644 index 0000000..cab9b99 --- /dev/null +++ b/bob/db/fargo/driver.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python +# encoding: utf-8 +# Guillaume HEUSCH <guillaume.heusch@idiap.ch> +# Thu 22 Dec 16:23:51 CET 2016 + + +"""Commands the FARGO database can respond to. +""" + +import os +import sys +from bob.db.base.driver import Interface as BaseInterface + +def dumplist(args): + """Dumps lists of files based on your criteria""" + + from .query import Database + db = Database() + + r = db.objects( + purposes=args.purpose, + groups=args.group, + ) + + output = sys.stdout + if args.selftest: + from bob.db.base.utils import null + output = null() + + for f in r: + output.write('%s\n' % f.make_path(directory=args.directory,extension=args.extension)) + + return 0 + +def checkfiles(args): + """Checks existence of files based on your criteria""" + + from .query import Database + db = Database() + + r = db.objects() + + # go through all files, check if they are available on the filesystem + 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 + if args.selftest: + from bob.db.base.utils import null + output = null() + + if bad: + 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)) + + return 0 + +class Interface(BaseInterface): + + def name(self): + return 'fargo' + + def version(self): + import pkg_resources # part of setuptools + return pkg_resources.require('bob.db.%s' % self.name())[0].version + + def files(self): + return () + + def type(self): + return 'text' + + def add_commands(self, parser): + + from . import __doc__ as docs + + subparsers = self.setup_parser(parser, + "FARGO database", docs) + + import argparse + + # the "dumplist" action + parser = subparsers.add_parser('dumplist', help=dumplist.__doc__) + parser.add_argument('-d', '--directory', default='', help="if given, this path will be prepended 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('-u', '--purpose', help="if given, this value will limit the output files to those designed for the given purposes.", choices=('enroll', 'probe', '')) + parser.add_argument('-g', '--group', help="if given, this value will limit the output files to those belonging to a particular protocolar group.", choices=('dev', 'eval', 'world', 'optional_world_1', 'optional_world_2', '')) + parser.add_argument('--self-test', dest="selftest", action='store_true', help=argparse.SUPPRESS) + parser.set_defaults(func=dumplist) #action + + # the "checkfiles" action + parser = subparsers.add_parser('checkfiles', help=checkfiles.__doc__) + parser.add_argument('-l', '--list-directory', required=True, help="The directory which contains the file lists.") + parser.add_argument('-d', '--directory', dest="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('--self-test', dest="selftest", action='store_true', help=argparse.SUPPRESS) + + parser.set_defaults(func=checkfiles) #action diff --git a/bob/db/fargo/query.py b/bob/db/fargo/query.py new file mode 100644 index 0000000..dca299b --- /dev/null +++ b/bob/db/fargo/query.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python +# encoding: utf-8 +# Guillaume HEUSCH <guillaume.heusch@idiap.ch> +# Thu 22 Dec 16:20:02 CET 2016 + +import bob.db.bio_filelist + +class Database(bob.db.bio_filelist.Database): + """Wrapper class for the FARGO database for face verification + """ + + def __init__(self, original_directory = None, original_extension = None): + # call base class constructor + from pkg_resources import resource_filename + lists = resource_filename(__name__, 'lists') + bob.db.bio_filelist.Database.__init__(self, lists, original_directory = original_directory, original_extension = original_extension) + diff --git a/buildout.cfg b/buildout.cfg index 6096dcc..c9b9f7e 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -11,4 +11,4 @@ verbose = true [scripts] recipe = bob.buildout:scripts -dependent-scripts = true \ No newline at end of file +dependent-scripts = true diff --git a/setup.py b/setup.py index 875f1da..50f45e1 100644 --- a/setup.py +++ b/setup.py @@ -27,11 +27,11 @@ setup( entry_points = { - #'bob.db': [ - # 'fargo = bob.db.fargo.driver:Interface', - # ], + 'bob.db': [ + 'fargo = bob.db.fargo.driver:Interface', + ], 'console_scripts': [ - 'extract_images.py = bob.db.fargo.scripts.extract_images:main' + 'extract_images.py = bob.db.fargo.scripts.extract_images:main', 'make_file_lists.py = bob.db.fargo.scripts.make_file_lists:main' ], }, -- GitLab