Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.libnetworkcache
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
slapos.libnetworkcache
Commits
af2f5c36
Commit
af2f5c36
authored
Jun 23, 2011
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid playing with url.
HTTPConnection accept port as none, there is no need to play with it.
parent
df7a4fa7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
11 deletions
+8
-11
slapos/libnetworkcache.py
slapos/libnetworkcache.py
+8
-11
No files found.
slapos/libnetworkcache.py
View file @
af2f5c36
...
@@ -36,10 +36,6 @@ class NetworkcacheClient(object):
...
@@ -36,10 +36,6 @@ class NetworkcacheClient(object):
# ShaCache Properties
# ShaCache Properties
if
shacache
is
not
None
:
if
shacache
is
not
None
:
shacache_urlparse
=
urlparse
(
shacache
)
shacache_urlparse
=
urlparse
(
shacache
)
self
.
shacache_host
=
shacache_urlparse
.
hostname
if
shacache_urlparse
.
port
is
not
None
:
self
.
shacache_host
+=
':%s'
%
shacache_urlparse
.
port
self
.
shacache_header_dict
=
{
'Content-Type'
:
'application/json'
}
self
.
shacache_header_dict
=
{
'Content-Type'
:
'application/json'
}
shacache_user
=
shacache_urlparse
.
username
shacache_user
=
shacache_urlparse
.
username
shacache_passwd
=
shacache_urlparse
.
password
shacache_passwd
=
shacache_urlparse
.
password
...
@@ -53,8 +49,7 @@ class NetworkcacheClient(object):
...
@@ -53,8 +49,7 @@ class NetworkcacheClient(object):
self
.
shacache_path
=
shacache_urlparse
.
path
self
.
shacache_path
=
shacache_urlparse
.
path
self
.
shacache_host
=
shacache_urlparse
.
hostname
self
.
shacache_host
=
shacache_urlparse
.
hostname
if
shacache_urlparse
.
port
is
not
None
:
self
.
shacache_port
=
shacache_urlparse
.
port
self
.
shacache_host
+=
':%s'
%
shacache_urlparse
.
port
self
.
shacache_url
=
shacache
self
.
shacache_url
=
shacache
# ShaDir Properties
# ShaDir Properties
...
@@ -73,8 +68,7 @@ class NetworkcacheClient(object):
...
@@ -73,8 +68,7 @@ class NetworkcacheClient(object):
self
.
shadir_path
=
shadir_urlparse
.
path
self
.
shadir_path
=
shadir_urlparse
.
path
self
.
shadir_host
=
shadir_urlparse
.
hostname
self
.
shadir_host
=
shadir_urlparse
.
hostname
if
shadir_urlparse
.
port
is
not
None
:
self
.
shadir_port
=
shadir_urlparse
.
port
self
.
shadir_host
+=
':%s'
%
shadir_urlparse
.
port
def
upload
(
self
,
file_descriptor
,
directory_key
=
None
,
**
kw
):
def
upload
(
self
,
file_descriptor
,
directory_key
=
None
,
**
kw
):
''' Upload the file to the server.
''' Upload the file to the server.
...
@@ -89,7 +83,8 @@ class NetworkcacheClient(object):
...
@@ -89,7 +83,8 @@ class NetworkcacheClient(object):
sha512sum
=
hashlib
.
sha512
(
file_content
).
hexdigest
()
sha512sum
=
hashlib
.
sha512
(
file_content
).
hexdigest
()
path
=
os
.
path
.
join
(
self
.
shacache_path
,
sha512sum
)
path
=
os
.
path
.
join
(
self
.
shacache_path
,
sha512sum
)
shacache_connection
=
httplib
.
HTTPConnection
(
self
.
shacache_host
)
shacache_connection
=
httplib
.
HTTPConnection
(
self
.
shacache_host
,
self
.
shacache_port
)
try
:
try
:
shacache_connection
.
request
(
'POST'
,
path
,
file_content
,
shacache_connection
.
request
(
'POST'
,
path
,
file_content
,
self
.
shacache_header_dict
)
self
.
shacache_header_dict
)
...
@@ -119,7 +114,8 @@ class NetworkcacheClient(object):
...
@@ -119,7 +114,8 @@ class NetworkcacheClient(object):
signature
=
''
signature
=
''
data
=
[
kw
,
signature
]
data
=
[
kw
,
signature
]
shadir_connection
=
httplib
.
HTTPConnection
(
self
.
shadir_host
)
shadir_connection
=
httplib
.
HTTPConnection
(
self
.
shadir_host
,
self
.
shadir_port
)
try
:
try
:
shadir_connection
.
request
(
'POST'
,
path
,
json
.
dumps
(
data
),
shadir_connection
.
request
(
'POST'
,
path
,
json
.
dumps
(
data
),
self
.
shadir_header_dict
)
self
.
shadir_header_dict
)
...
@@ -157,7 +153,8 @@ class NetworkcacheClient(object):
...
@@ -157,7 +153,8 @@ class NetworkcacheClient(object):
if
directory_key
is
not
None
:
if
directory_key
is
not
None
:
path_info
=
os
.
path
.
join
(
self
.
shadir_path
,
directory_key
)
path_info
=
os
.
path
.
join
(
self
.
shadir_path
,
directory_key
)
shadir_connection
=
httplib
.
HTTPConnection
(
self
.
shadir_host
)
shadir_connection
=
httplib
.
HTTPConnection
(
self
.
shadir_host
,
self
.
shadir_port
)
try
:
try
:
shadir_connection
.
request
(
'GET'
,
path_info
,
headers
=
self
.
shadir_header_dict
)
shadir_connection
.
request
(
'GET'
,
path_info
,
headers
=
self
.
shadir_header_dict
)
result
=
shadir_connection
.
getresponse
()
result
=
shadir_connection
.
getresponse
()
...
...
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