Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bob
bob.pad.base
Commits
a6747782
Commit
a6747782
authored
Mar 01, 2018
by
Pavel KORSHUNOV
Browse files
added clients option to filelistdb driver
parent
350cd6cf
Pipeline
#17283
passed with stage
in 18 minutes and 31 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
bob/pad/base/database/filelist/driver.py
View file @
a6747782
...
...
@@ -25,13 +25,35 @@ import sys
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
):
"""Dumps lists of files based on your criteria"""
from
.query
import
FileListPadDatabase
db
=
FileListPadDatabase
(
args
.
list_directory
,
'pad_filelist'
)
r
=
db
.
objects
(
file_objects
=
db
.
objects
(
purposes
=
args
.
purpose
,
groups
=
args
.
group
,
protocol
=
args
.
protocol
...
...
@@ -42,8 +64,8 @@ def dumplist(args):
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
))
for
f
ile_obj
in
file_objects
:
output
.
write
(
'%s
\n
'
%
f
ile_obj
.
make_path
(
directory
=
args
.
directory
,
extension
=
args
.
extension
))
return
0
...
...
@@ -54,16 +76,16 @@ def checkfiles(args):
from
.query
import
FileListPadDatabase
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
good
=
[]
bad
=
[]
for
f
in
r
:
if
os
.
path
.
exists
(
f
.
make_path
(
args
.
directory
,
args
.
extension
)):
good
.
append
(
f
)
for
f
ile_obj
in
file_objects
:
if
os
.
path
.
exists
(
f
ile_obj
.
make_path
(
args
.
directory
,
args
.
extension
)):
good
.
append
(
f
ile_obj
)
else
:
bad
.
append
(
f
)
bad
.
append
(
f
ile_obj
)
# report
output
=
sys
.
stdout
...
...
@@ -72,9 +94,9 @@ def checkfiles(args):
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
))
for
f
ile_obj
in
bad
:
output
.
write
(
'Cannot find file "%s"
\n
'
%
f
ile_obj
.
make_path
(
args
.
directory
,
args
.
extension
))
output
.
write
(
'%d files (out of %d) were not found at "%s"
\n
'
%
(
len
(
bad
),
len
(
file_objects
),
args
.
directory
))
return
0
...
...
@@ -101,6 +123,19 @@ class Interface(BaseInterface):
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
parser
=
subparsers
.
add_parser
(
'dumplist'
,
help
=
dumplist
.
__doc__
)
parser
.
add_argument
(
'-l'
,
'--list-directory'
,
required
=
True
,
...
...
@@ -115,7 +150,7 @@ class Interface(BaseInterface):
choices
=
(
'real'
,
'attack'
,
''
))
parser
.
add_argument
(
'-g'
,
'--group'
,
help
=
"if given, this value will limit the output files to those belonging to a "
"particular
protocolar
group."
,
"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."
)
...
...
bob/pad/base/database/filelist/query.py
View file @
a6747782
...
...
@@ -213,7 +213,7 @@ class FileListPadDatabase(PadDatabase, FileListBioDatabase):
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
):
"""Returns a set of :py:class:`PadFile` objects for the specific query by the user.
...
...
bob/pad/base/test/test_filelist.py
View file @
a6747782
...
...
@@ -66,6 +66,7 @@ def test_query_protocol():
def
test_driver_api
():
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 --purpose=real --group=dev --self-test'
%
example_dir
).
split
())
==
0
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment