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
3d49a1e6
There was a problem fetching the pipeline summary.
Commit
3d49a1e6
authored
7 years ago
by
André Anjos
Browse files
Options
Downloads
Patches
Plain Diff
Now everything works ;-)
parent
3cec688a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!33
Implemented local file upload, closes #20
Pipeline
#
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/db/base/driver.py
+19
-12
19 additions, 12 deletions
bob/db/base/driver.py
with
19 additions
and
12 deletions
bob/db/base/driver.py
+
19
−
12
View file @
3d49a1e6
...
...
@@ -83,7 +83,7 @@ def upload(arguments):
import
six.moves.http_client
import
shutil
parsed_url
=
six
.
moves
.
urllib
.
parse
.
urlparse
(
arguments
.
destination
)
parsed_url
=
six
.
moves
.
urllib
.
parse
.
urlparse
(
arguments
.
url
)
with
tempfile
.
TemporaryFile
()
as
tmpfile
:
...
...
@@ -98,29 +98,36 @@ def upload(arguments):
f
.
close
()
tmpfile
.
seek
(
0
)
if
parsed_url
.
scheme
in
(
''
,
'
file
'
):
if
parsed_url
.
netloc
:
# relative URL;
target_path
=
parsed_url
.
netloc
+
target_path
# file location?
# print what we are going to do
target_path
=
'
/
'
.
join
((
parsed_url
.
path
,
arguments
.
name
+
"
.tar.bz2
"
))
print
(
"
Uploading protocol files to %s
"
%
target_path
)
if
parsed_url
.
scheme
in
(
''
,
'
file
'
):
#local file upload
try
:
shutil
.
copyfileobj
(
tmpfile
,
open
(
target_path
,
'
w
'
))
print
(
"
Created %s
"
%
target_path
)
shutil
.
copyfileobj
(
tmpfile
,
open
(
target_path
,
'
wb
'
))
return
except
(
shutil
.
Error
,
IOError
)
as
e
:
# maybe no file location? try next steps
print
(
"
Error: %s
"
%
e
)
# print what we are going to do
target_path
=
'
/
'
.
join
((
parsed_url
.
path
,
arguments
.
name
+
"
.tar.bz2
"
))
print
(
"
Uploading protocol files to %s
"
%
target_path
)
# if you get to this point, it is because it is a network transfer
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
)
# copy tmpfile to DAV server
import
base64
import
getpass
from
six.moves
import
input
print
(
"
Authorization requested by server %s
"
%
parsed_url
.
netloc
)
username
=
input
(
'
Username:
'
)
username
=
username
.
encode
(
'
ascii
'
)
password
=
getpass
.
getpass
(
prompt
=
'
Password:
'
)
password
=
password
.
encode
(
'
ascii
'
)
upass
=
base64
.
encodestring
(
b
'
%s:%s
'
%
\
(
username
,
password
)).
decode
(
'
ascii
'
)[:
-
1
]
headers
=
{
'
Authorization
'
:
'
Basic %s
'
%
upass
}
dav_server
.
request
(
'
PUT
'
,
target_path
,
tmpfile
,
headers
=
headers
)
res
=
dav_server
.
getresponse
()
response
=
res
.
read
()
...
...
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