Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.buildout
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
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
isaak yansane-sisk
slapos.buildout
Commits
66d44d8f
Commit
66d44d8f
authored
May 11, 2011
by
Lucas Carvalho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a python library which implements the feature of networkcache client.
parent
6f10302b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
101 additions
and
0 deletions
+101
-0
src/zc/buildout/libnetworkcache.py
src/zc/buildout/libnetworkcache.py
+101
-0
No files found.
src/zc/buildout/libnetworkcache.py
0 → 100644
View file @
66d44d8f
##############################################################################
#
# Copyright (c) 2010 ViFiB SARL and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import
httplib
import
os
class
NetworkcacheClient
(
object
):
'''
NetworkcacheClient is a wrapper for httplib.
It must implement all the required methods to use the Networkcache HTTP
Server.
- put(key, file)
- get(key)
- delete(key)
'''
def
__init__
(
self
,
networkcache_url
):
# XXX (lucas): Is it required to check if networkcache_url is a valid URL?
self
.
networkcache_url
=
networkcache_url
def
_start
(
self
):
self
.
connection
=
httplib
.
HTTPConnection
(
self
.
networkcache_url
)
def
_close
(
self
):
self
.
connection
.
close
()
def
put
(
self
,
key
,
file_path
):
'''
Upload the file to the server.
It uses http PUT resquest method.
'''
if
not
os
.
path
.
exists
(
file_path
):
raise
ValueError
,
'File does not exists. %s'
%
file_path
f
=
open
(
file_path
,
'rb'
)
try
:
file_content
=
f
.
read
()
except
:
f
.
close
()
path_info
=
'/%s'
%
key
self
.
_start
()
try
:
self
.
connection
.
request
(
'PUT'
,
path_info
,
file_content
)
result
=
self
.
connection
.
getresponse
()
finally
:
self
.
_close
()
return
result
def
get
(
self
,
key
,
file_path
):
'''
Download the file.
It uses http GET request method.
'''
path_info
=
'/%s'
%
key
self
.
_start
()
try
:
self
.
connection
.
request
(
'GET'
,
path_info
)
result
=
self
.
connection
.
getresponse
()
finally
:
self
.
_close
()
# save file
if
os
.
path
.
isdir
(
file_path
):
file_path
=
os
.
path
.
join
(
file_path
,
key
)
f
=
open
(
file_path
,
'w+'
)
try
:
f
.
write
(
result
.
read
())
except
:
f
.
close
()
return
result
,
file_path
def
delete
(
self
,
key
):
'''
Delete the file.
It uses http DELETE request method.
'''
path_info
=
'/%s'
%
key
self
.
_start
()
try
:
self
.
connection
.
request
(
'DELETE'
,
path_info
)
result
=
self
.
connection
.
getresponse
()
finally
:
self
.
_close
()
return
result
.
read
(),
result
.
getheaders
()
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