dumplist.py 2.79 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Laurent El Shafey <laurent.el-shafey@idiap.ch>

"""Dumps lists of files.
"""

import os
import sys

# Driver API
# ==========

def dumplist(args):
  """Dumps lists of files based on your criteria"""

  from .query import Database
  db = Database()

Laurent EL SHAFEY's avatar
Cleanup    
Laurent EL SHAFEY committed
20
  r = db.objects(
21
22
      protocol=args.protocol,
      purposes=args.purposes,
23
      model_ids=(args.client,),
24
25
26
27
28
29
30
31
32
      groups=args.groups,
      languages=args.languages
      )

  output = sys.stdout
  if args.selftest:
    from bob.db.utils import null
    output = null()

Laurent EL SHAFEY's avatar
Cleanup    
Laurent EL SHAFEY committed
33
34
  for f in r:
    output.write('%s\n' % (f.make_path(args.directory, args.extension),))
35
36
37
38
39
40
41
42
43
44

  return 0

def add_command(subparsers):
  """Add specific subcommands that the action "dumplist" can use"""

  from argparse import SUPPRESS

  parser = subparsers.add_parser('dumplist', help=dumplist.__doc__)

Laurent EL SHAFEY's avatar
Cleanup    
Laurent EL SHAFEY committed
45
46
47
48
  from .query import Database

  db = Database()

49
50
51
52
53
  if not db.is_valid():
    clients = tuple()
  else:
    clients = [client.id for client in db.clients()]

54
55
  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')")
Laurent EL SHAFEY's avatar
Cleanup    
Laurent EL SHAFEY committed
56
57
  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())
58
  parser.add_argument('-C', '--client', dest="client", default=None, type=int, help="if given, limits the dump to a particular client (defaults to '%(default)s')", choices=clients)
Laurent EL SHAFEY's avatar
Cleanup    
Laurent EL SHAFEY committed
59
60
  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())
61
62
63
64
65
  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)

  parser.set_defaults(func=dumplist) #action