Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.db.fargo
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bob
bob.db.fargo
Commits
a6472586
Commit
a6472586
authored
6 years ago
by
Guillaume HEUSCH
Browse files
Options
Downloads
Patches
Plain Diff
added minimal create.py
parent
53fd5267
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/db/fargo/create.py
+81
-0
81 additions, 0 deletions
bob/db/fargo/create.py
with
81 additions
and
0 deletions
bob/db/fargo/create.py
0 → 100644
+
81
−
0
View file @
a6472586
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
import
os
from
.models
import
*
import
bob.core
logger
=
bob
.
core
.
log
.
setup
(
'
bob.db.fargo
'
)
def
add_clients
(
session
,
imagesdir
,
verbose
=
True
):
"""
Add clients
This function add clients to the database.
Parameters
----------
imagesdir : :py:obj:str
The directory where the images have been extracted
verbose : bool
Print some information
"""
if
verbose
:
logger
.
info
(
"
Adding clients ...
"
)
for
d
in
os
.
listdir
(
imagesdir
):
print
(
d
)
def
create_tables
(
args
):
"""
Creates all necessary tables (only to be used at the first time)
"""
from
bob.db.base.utils
import
create_engine_try_nolock
engine
=
create_engine_try_nolock
(
args
.
type
,
args
.
files
[
0
],
echo
=
(
args
.
verbose
>
2
))
Base
.
metadata
.
create_all
(
engine
)
# Driver API
# ==========
def
create
(
args
):
"""
Creates or re-creates this database
"""
from
bob.db.base.utils
import
session_try_nolock
dbfile
=
args
.
files
[
0
]
if
args
.
recreate
:
if
args
.
verbose
and
os
.
path
.
exists
(
dbfile
):
print
((
'
unlinking %s...
'
%
dbfile
))
if
os
.
path
.
exists
(
dbfile
):
os
.
unlink
(
dbfile
)
if
not
os
.
path
.
exists
(
os
.
path
.
dirname
(
dbfile
)):
os
.
makedirs
(
os
.
path
.
dirname
(
dbfile
))
# the real work...
create_tables
(
args
)
s
=
session_try_nolock
(
args
.
type
,
args
.
files
[
0
],
echo
=
(
args
.
verbose
>=
2
))
add_clients
(
s
,
args
.
imagesdir
,
args
.
verbose
)
s
.
commit
()
s
.
close
()
return
0
def
add_command
(
subparsers
):
"""
Add specific subcommands that the action
"
create
"
can use
"""
parser
=
subparsers
.
add_parser
(
'
create
'
,
help
=
create
.
__doc__
)
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
'
,
default
=
0
,
help
=
"
Do SQL operations in a verbose way
"
)
parser
.
add_argument
(
'
-i
'
,
'
--imagesdir
'
,
action
=
'
store
'
,
default
=
'
/idiap/temp/heusch/bob.project.fargo/images/
'
metavar
=
'
DIR
'
,
help
=
"
Change the path to the extracted images of the FARGO database (defaults to %(default)s)
"
)
parser
.
set_defaults
(
func
=
create
)
# action
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment