bug fix
This commit is contained in:
parent
bc8f24d3cc
commit
e8328e577d
24
README.md
24
README.md
|
@ -13,12 +13,24 @@ This project implements an abstraction of objects that can have access to a vari
|
||||||
The basic usage revolves around a factory class (to be a singleton)
|
The basic usage revolves around a factory class (to be a singleton)
|
||||||
|
|
||||||
import transport
|
import transport
|
||||||
|
from transport import factory
|
||||||
p = {"uri":"https://your-server:5984","dbname":"mydatabase","doc":"doc_id"}
|
#
|
||||||
couchdb = transport.Factory.instance(type='CouchdbReader',args=p)
|
# importing a mongo reader
|
||||||
|
args = {"host":"<host>:<port>","dbname":"<database>","doc":"<doc_id>",["username":"<username>","password":"<password>"]}
|
||||||
|
mreader = factory.instance(type='mongo.MonoReader',args=args)
|
||||||
|
#
|
||||||
|
# reading a document and executing a view
|
||||||
|
#
|
||||||
|
document = mreader.read()
|
||||||
|
result = mreader.view(name)
|
||||||
|
#
|
||||||
|
# importing a couchdb reader
|
||||||
|
args = {"url":"<http://host>:<port>","dbname":"<database>","doc":"<doc_id>","username":"<username>","password":"<password>"}
|
||||||
|
creader = factory.instance(type='couch.CouchReader',args=args)
|
||||||
|
|
||||||
#
|
#
|
||||||
# let's execute a view
|
# Reading a document and executing a view
|
||||||
#
|
#
|
||||||
result = couchdb.view('view_name/function',key=value)
|
document = dreader.read()
|
||||||
info = couchdb.read()
|
result = couchdb.view(id='<design_doc_id>',view_name=<view_name',<key=value|keys=values>)
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ The configuration for the data-store is as follows :
|
||||||
username:<username>,
|
username:<username>,
|
||||||
password:<password>,
|
password:<password>,
|
||||||
dbname:<database>,
|
dbname:<database>,
|
||||||
uid:<document id>
|
doc:<document id>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RabbitMQ:
|
RabbitMQ:
|
||||||
|
@ -36,7 +36,7 @@ The configuration for the data-store is as follows :
|
||||||
username:<username>,
|
username:<username>,
|
||||||
password:<password>,
|
password:<password>,
|
||||||
dbname:<database>,
|
dbname:<database>,
|
||||||
uid:<document id>s
|
doc:<document id>s
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,11 +46,11 @@ import numpy as np
|
||||||
import json
|
import json
|
||||||
import importlib
|
import importlib
|
||||||
from common import Reader, Writer #, factory
|
from common import Reader, Writer #, factory
|
||||||
# import disk
|
import disk
|
||||||
# import queue
|
import queue
|
||||||
# import couch
|
import couch
|
||||||
# import mongo
|
import mongo
|
||||||
# import s3
|
import s3
|
||||||
class factory :
|
class factory :
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def instance(**args):
|
def instance(**args):
|
||||||
|
@ -68,12 +68,13 @@ class factory :
|
||||||
# @TODO: Make sure objects are serializable, be smart about them !!
|
# @TODO: Make sure objects are serializable, be smart about them !!
|
||||||
#
|
#
|
||||||
aClassName = ''.join([source,'(**params)'])
|
aClassName = ''.join([source,'(**params)'])
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
stream = json.dumps(params)
|
stream = json.dumps(params)
|
||||||
aClassName = ''.join([source,'(**',stream,')'])
|
aClassName = ''.join([source,'(**',stream,')'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
anObject = eval( aClassName)
|
anObject = eval( aClassName)
|
||||||
#setattr(anObject,'name',source)
|
#setattr(anObject,'name',source)
|
||||||
|
|
|
@ -10,17 +10,17 @@ import json
|
||||||
from common import Reader,Writer
|
from common import Reader,Writer
|
||||||
class Couch:
|
class Couch:
|
||||||
"""
|
"""
|
||||||
|
This class is a wrapper for read/write against couchdb. The class captures common operations for read/write.
|
||||||
@param url host & port reference
|
@param url host & port reference
|
||||||
@param uid user id involved
|
@param doc user id involved
|
||||||
|
|
||||||
@param dbname database name (target)
|
@param dbname database name (target)
|
||||||
"""
|
"""
|
||||||
def __init__(self,**args):
|
def __init__(self,**args):
|
||||||
url = args['url']
|
url = args['url']
|
||||||
self.uid = args['uid']
|
self.uid = args['doc']
|
||||||
dbname = args['dbname']
|
dbname = args['dbname']
|
||||||
if 'username' not in args and 'password' not in args :
|
if 'username' not in args and 'password' not in args :
|
||||||
self.server = cloudant.CouchDB(url=url)
|
self.server = cloudant.CouchDB(None,None,url=url)
|
||||||
else:
|
else:
|
||||||
self.server = cloudant.CouchDB(args['username'],args['password'],url=url)
|
self.server = cloudant.CouchDB(args['username'],args['password'],url=url)
|
||||||
self.server.connect()
|
self.server.connect()
|
||||||
|
@ -56,10 +56,10 @@ class Couch:
|
||||||
|
|
||||||
def view(self,**args):
|
def view(self,**args):
|
||||||
"""
|
"""
|
||||||
We are executing a view
|
The function will execute a view (provivded a user is authenticated)
|
||||||
:id design document _design/xxxx (provide full name with _design prefix)
|
:id design document _design/xxxx (provide full name with _design prefix)
|
||||||
:view_name name of the view i.e
|
:view_name name of the view i.e
|
||||||
:key key to be used to filter the content
|
:key(s) key(s) to be used to filter the content
|
||||||
"""
|
"""
|
||||||
document = cloudant.design_document.DesignDocument(self.dbase,args['id'])
|
document = cloudant.design_document.DesignDocument(self.dbase,args['id'])
|
||||||
document.fetch()
|
document.fetch()
|
||||||
|
|
|
@ -23,7 +23,7 @@ class Mongo :
|
||||||
else:
|
else:
|
||||||
self.client = MongoClient()
|
self.client = MongoClient()
|
||||||
|
|
||||||
self.uid = args['uid'] #-- document identifier
|
self.uid = args['doc'] #-- document identifier
|
||||||
self.dbname = args['dbname']
|
self.dbname = args['dbname']
|
||||||
self.db = self.client[self.dbname]
|
self.db = self.client[self.dbname]
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,12 @@ class MessageQueue:
|
||||||
"""
|
"""
|
||||||
This class hierarchy is designed to handle interactions with a queue server using pika framework (our tests are based on rabbitmq)
|
This class hierarchy is designed to handle interactions with a queue server using pika framework (our tests are based on rabbitmq)
|
||||||
:host
|
:host
|
||||||
:uid identifier of the exchange
|
:xid identifier of the exchange
|
||||||
:qid identifier of the queue
|
:qid identifier of the queue
|
||||||
"""
|
"""
|
||||||
def __init__(self,**params):
|
def __init__(self,**params):
|
||||||
self.host= params['host']
|
self.host= params['host']
|
||||||
self.uid = params['uid']
|
self.uid = params['xid']
|
||||||
self.qid = params['qid']
|
self.qid = params['qid']
|
||||||
|
|
||||||
def isready(self):
|
def isready(self):
|
||||||
|
|
Loading…
Reference in New Issue