Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.db.base
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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.base
Commits
a2920a09
There was a problem fetching the pipeline summary.
Commit
a2920a09
authored
7 years ago
by
André Anjos
Browse files
Options
Downloads
Plain Diff
Merge branch 'issue_17' into 'master'
Closes #17 Closes #17 See merge request
!29
parents
f328e576
a829dece
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!29
Closes #17
Pipeline
#
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/db/base/driver.py
+42
-25
42 additions, 25 deletions
bob/db/base/driver.py
with
42 additions
and
25 deletions
bob/db/base/driver.py
+
42
−
25
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
,
perm
s
)
if
not
(
200
<=
res
.
status
<
300
):
raise
IOError
(
response
)
else
:
print
(
"
Uploaded %s (status: %d)
"
%
(
target_path
,
res
.
statu
s
)
)
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
...
...
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