Commit 1c2a25bb authored by Lucas Carvalho's avatar Lucas Carvalho
parents
0.1 (unreleased)
================
* Initial version.
include CHANGES.txt
Introduction
==============
The goal of libnetworkcache python library is to abstract the HTTP calls.
It works as wrapper of python httplib to use the Networkcache HTTP Server.
The Networkcache HTTP Server are sub-divided into two Web services:
- SHACACHE
- SHADIR
SHACACHE
===========
It is a simple HTTP Server used to cache files.
SHADIR
=======
It is a simple HTTP Server used to cache information, working like a directory.
API
======
So, it must provide 2 methods:
post(file)
''' Upload the file to Networkcache HTTP Server using POST as HTTP method.'''
get_file(key)
''' Download the file from SHACACHE server using GET as HTTP method.'''
get_information(directory, urlmd5=None)
''' Retrieve the information from SHADIR server using GET as HTTP method. '''
from setuptools import setup, find_packages
import os
name = "slapos.libnetworkcache"
version = 'O.1'
def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
long_description = (
read('README.txt')
+ '\n' +
read('CHANGES.txt')
)
setup(
name=name,
version=version,
description="libnetworkcache - Client for ShaCache and ShaDir HTTP Server",
long_description=long_description,
license="GPLv3",
keywords="vifib slapos networkcache shadir shacache",
classifiers=[
],
packages=find_packages(),
include_package_data=True,
namespace_packages=['slapos', 'slapos.libnetworkcache'],
install_requires=[
],
zip_safe=False,
entry_points=""" """,
)
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
##############################################################################
#
# 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(file)
- get(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, path, file_content):
'''
Upload the file to the server.
It uses http PUT resquest method.
'''
if file_content is None:
raise ValueError('File content should not be None.')
self._start()
try:
self.connection.request('PUT', path, file_content)
result = self.connection.getresponse()
finally:
self._close()
return result
def get(self, key):
'''
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()
return result
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment