Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
bob.db.base
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bob
bob.db.base
Commits
a2920a09
Commit
a2920a09
authored
Jun 09, 2017
by
André Anjos
💬
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'issue_17' into 'master'
Closes #17 Closes #17 See merge request
!29
parents
f328e576
a829dece
Pipeline
#10494
passed with stages
in 11 minutes and 18 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
25 deletions
+42
-25
bob/db/base/driver.py
bob/db/base/driver.py
+42
-25
No files found.
bob/db/base/driver.py
View file @
a2920a09
...
...
@@ -70,47 +70,64 @@ def upload(arguments):
assert
basedir
,
"Database and package names do not match. Your declared "
\
"database name should be <name>, if your package is called bob.db.<name>"
target_file
=
os
.
path
.
join
(
arguments
.
destination
,
arguments
.
name
+
".tar.bz2"
)
# check all files exist
for
p
in
arguments
.
files
:
if
not
os
.
path
.
exists
(
p
):
raise
IOError
(
"Metadata file `
%
s' is not available. Did you run "
"`create' before attempting to upload?"
%
(
p
,))
# if destination exists, try to erase it before
if
os
.
path
.
exists
(
target_file
):
try
:
os
.
unlink
(
target_file
)
except
Exception
as
e
:
print
(
"Cannot erase existing file `
%
s':
%
s"
%
(
target_file
,
e
))
# if you get here, all files are there, ready to package
print
(
"Compressing metadata files to `
%
s'"
%
(
target_file
,))
# compress
import
tarfile
import
tempfile
import
base64
import
six.moves.urllib
import
six.moves.http_client
import
getpass
parsed_url
=
six
.
moves
.
urllib
.
parse
.
urlparse
(
arguments
.
destination
)
target_path
=
'/'
.
join
((
parsed_url
.
path
,
arguments
.
name
+
".tar.bz2"
))
# encode user/pass to DAV server before we start
password
=
getpass
.
getpass
(
prompt
=
'Password for Bob
\'
s "uploader": '
)
password
=
password
.
encode
(
'ascii'
)
upass
=
base64
.
encodestring
(
b
'uploader:
%
s'
%
password
)
.
decode
(
'ascii'
)[:
-
1
]
headers
=
{
'Authorization'
:
'Basic
%
s'
%
upass
}
with
tempfile
.
TemporaryFile
()
as
tmpfile
:
# if you get here, all files are there, ready to package
print
(
"Compressing metadata files to temporary file..."
)
f
=
tarfile
.
open
(
fileobj
=
tmpfile
,
mode
=
'w:bz2'
)
for
k
,
p
in
enumerate
(
arguments
.
files
):
n
=
os
.
path
.
relpath
(
p
,
basedir
)
print
(
"+ [
%
d/
%
d]
%
s"
%
(
k
+
1
,
len
(
arguments
.
files
),
n
))
f
.
add
(
p
,
n
)
f
.
close
()
if
parsed_url
.
scheme
==
'https'
:
dav_server
=
six
.
moves
.
http_client
.
HTTPSConnection
(
parsed_url
.
netloc
)
else
:
dav_server
=
six
.
moves
.
http_client
.
HTTPConnection
(
parsed_url
.
netloc
)
f
=
tarfile
.
open
(
target_file
,
'w:bz2'
)
for
k
,
p
in
enumerate
(
arguments
.
files
):
n
=
os
.
path
.
relpath
(
p
,
basedir
)
print
(
"+ [
%
d/
%
d]
%
s"
%
(
k
+
1
,
len
(
arguments
.
files
),
n
)
)
f
.
add
(
p
,
n
)
f
.
close
()
# copy tmpfile to DAV server
tmpfile
.
seek
(
0
)
dav_server
.
request
(
'PUT'
,
target_path
,
tmpfile
,
headers
=
headers
)
res
=
dav_server
.
getresponse
(
)
response
=
res
.
read
(
)
dav_server
.
close
()
# set permissions for sane Idiap storage
import
stat
perms
=
stat
.
S_IRUSR
|
stat
.
S_IWUSR
|
stat
.
S_IRGRP
|
stat
.
S_IWGRP
|
stat
.
S_IROTH
os
.
chmod
(
target_file
,
perms
)
if
not
(
200
<=
res
.
status
<
300
):
raise
IOError
(
response
)
else
:
print
(
"Uploaded
%
s (status:
%
d)"
%
(
target_path
,
res
.
status
)
)
def
upload_command
(
subparsers
):
"""Adds a new 'upload' subcommand to your parser"""
parser
=
subparsers
.
add_parser
(
'upload'
,
help
=
upload
.
__doc__
)
parser
.
add_argument
(
"--destination"
,
default
=
"/idiap/group/torch5spro/databases/latest"
)
parser
.
add_argument
(
"--destination"
,
default
=
"https://www.idiap.ch/software/bob/public-upload/databases/latest"
)
parser
.
set_defaults
(
func
=
upload
)
return
parser
...
...
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