Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bob
bob.db.replay
Commits
8cb15b0e
Commit
8cb15b0e
authored
Sep 10, 2014
by
Manuel Günther
Browse files
Fixed warning in Database destructor; added db download for travis tests.
parent
b4e931d7
Changes
3
Hide whitespace changes
Inline
Side-by-side
.travis.yml
View file @
8cb15b0e
...
...
@@ -25,6 +25,7 @@ install:
-
./bin/buildout
script
:
-
./bin/python -c 'from bob.db.replay import get_config; print(get_config())'
-
./bin/bob_dbmanage.py replay download
-
./bin/coverage run --source=bob.db.replay ./bin/nosetests -sv
-
./bin/sphinx-build -b doctest doc sphinx
-
./bin/sphinx-build -b html doc sphinx
...
...
bob/db/replay/create.py
View file @
8cb15b0e
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Andre Anjos <andre.dos.anjos@gmail.com>
# Thu 12 May 08:19:50 2011
# Thu 12 May 08:19:50 2011
"""This script creates the Replay-Attack database in a single pass.
"""
...
...
@@ -13,7 +13,7 @@ from .models import *
def
add_clients
(
session
,
protodir
,
verbose
):
"""Add clients to the replay attack database."""
for
client
in
open
(
os
.
path
.
join
(
protodir
,
'clients.txt'
),
'rt'
):
s
=
client
.
strip
().
split
(
' '
,
2
)
if
not
s
:
continue
#empty line
...
...
@@ -110,7 +110,7 @@ def define_protocols(session, protodir, verbose):
if
verbose
:
print
(
"Not considering protocol %s as attack list '%s' was not found"
%
(
s
[
1
],
attack
))
consider
=
False
# check real file
real
=
os
.
path
.
join
(
protodir
,
'real-%s-allsupports-%s.txt'
%
(
s
[
1
],
grp
))
if
not
os
.
path
.
exists
(
real
):
...
...
@@ -118,7 +118,7 @@ def define_protocols(session, protodir, verbose):
if
not
os
.
path
.
exists
(
alt_real
):
if
verbose
:
print
(
"Not considering protocol %s as real list '%s' or '%s' were not found"
%
(
s
[
1
],
real
,
alt_real
))
consider
=
False
consider
=
False
else
:
real
=
alt_real
...
...
@@ -141,7 +141,7 @@ def define_protocols(session, protodir, verbose):
q
.
protocols
.
append
(
obj
)
counter
+=
1
if
verbose
:
print
(
" -> %5s/%-6s: %d files"
%
(
grp
,
"attack"
,
counter
))
counter
=
0
for
fname
in
open
(
flist
[
1
],
'rt'
):
s
=
os
.
path
.
splitext
(
fname
.
strip
())[
0
]
...
...
@@ -149,7 +149,7 @@ def define_protocols(session, protodir, verbose):
q
.
protocols
.
append
(
obj
)
counter
+=
1
if
verbose
:
print
(
" -> %5s/%-6s: %d files"
%
(
grp
,
"real"
,
counter
))
session
.
add
(
obj
)
def
create_tables
(
args
):
...
...
@@ -173,7 +173,7 @@ def create(args):
dbfile
=
args
.
files
[
0
]
if
args
.
recreate
:
if
args
.
recreate
:
if
args
.
verbose
and
os
.
path
.
exists
(
dbfile
):
print
((
'unlinking %s...'
%
dbfile
))
if
os
.
path
.
exists
(
dbfile
):
os
.
unlink
(
dbfile
)
...
...
@@ -192,7 +192,7 @@ def create(args):
s
.
close
()
return
0
def
add_command
(
subparsers
):
"""Add specific subcommands that the action "create" can use"""
...
...
@@ -200,11 +200,11 @@ def add_command(subparsers):
parser
.
add_argument
(
'-R'
,
'--recreate'
,
action
=
'store_true'
,
default
=
False
,
help
=
"If set, I'll first erase the current database"
)
parser
.
add_argument
(
'-v'
,
'--verbose'
,
action
=
'count'
,
parser
.
add_argument
(
'-v'
,
'--verbose'
,
action
=
'count'
,
default
=
0
,
help
=
"Do SQL operations in a verbose way"
)
parser
.
add_argument
(
'-D'
,
'--protodir'
,
action
=
'store'
,
parser
.
add_argument
(
'-D'
,
'--protodir'
,
action
=
'store'
,
default
=
'/idiap/group/replay/database/protocols/replayattack-database/protocols'
,
metavar
=
'DIR'
,
help
=
"Change the relative path to the directory containing the protocol definitions for replay attacks (defaults to %(default)s)"
)
parser
.
set_defaults
(
func
=
create
)
#action
bob/db/replay/query.py
View file @
8cb15b0e
...
...
@@ -30,7 +30,17 @@ class Database(object):
def
__del__
(
self
):
"""Releases the opened file descriptor"""
if
self
.
session
:
self
.
session
.
bind
.
dispose
()
if
self
.
session
:
try
:
# Since the dispose function re-creates a pool
# which might fail in some conditions, e.g., when this destructor is called during the exit of the python interpreter
self
.
session
.
close
()
self
.
session
.
bind
.
dispose
()
except
TypeError
:
# ... I can just ignore the according exception...
pass
except
AttributeError
:
pass
def
connect
(
self
):
"""Tries connecting or re-connecting to the database"""
...
...
@@ -163,7 +173,7 @@ class Database(object):
q
=
q
.
filter
(
Protocol
.
name
.
in_
(
protocol
))
q
=
q
.
order_by
(
Client
.
id
)
retval
+=
list
(
q
)
return
retval
def
files
(
self
,
directory
=
None
,
extension
=
None
,
**
object_query
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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