From e8328e577dd352f70f36480cf07d62a19ac0d491 Mon Sep 17 00:00:00 2001 From: Steve Nyemba Date: Tue, 17 Sep 2019 11:21:42 -0500 Subject: [PATCH] bug fix --- README.md | 24 ++++++++++++++++++------ transport/__init__.py | 17 +++++++++-------- transport/couch.py | 16 ++++++++-------- transport/mongo.py | 2 +- transport/queue.py | 4 ++-- 5 files changed, 38 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 242d21a..1913cfe 100644 --- a/README.md +++ b/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) import transport - - p = {"uri":"https://your-server:5984","dbname":"mydatabase","doc":"doc_id"} - couchdb = transport.Factory.instance(type='CouchdbReader',args=p) + from transport import factory + # + # importing a mongo reader + args = {"host":":","dbname":"","doc":"",["username":"","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":":","dbname":"","doc":"","username":"","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) - info = couchdb.read() \ No newline at end of file + document = dreader.read() + result = couchdb.view(id='',view_name=) + diff --git a/transport/__init__.py b/transport/__init__.py index 9b4f540..71d9570 100644 --- a/transport/__init__.py +++ b/transport/__init__.py @@ -22,7 +22,7 @@ The configuration for the data-store is as follows : username:, password:, dbname:, - uid: + doc: } } RabbitMQ: @@ -36,7 +36,7 @@ The configuration for the data-store is as follows : username:, password:, dbname:, - uid:s + doc:s } } @@ -46,11 +46,11 @@ import numpy as np import json import importlib from common import Reader, Writer #, factory -# import disk -# import queue -# import couch -# import mongo -# import s3 +import disk +import queue +import couch +import mongo +import s3 class factory : @staticmethod def instance(**args): @@ -68,12 +68,13 @@ class factory : # @TODO: Make sure objects are serializable, be smart about them !! # aClassName = ''.join([source,'(**params)']) - + else: stream = json.dumps(params) aClassName = ''.join([source,'(**',stream,')']) + try: anObject = eval( aClassName) #setattr(anObject,'name',source) diff --git a/transport/couch.py b/transport/couch.py index 6368a27..d3189f2 100644 --- a/transport/couch.py +++ b/transport/couch.py @@ -10,17 +10,17 @@ import json from common import Reader,Writer 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 uid user id involved - + @param doc user id involved @param dbname database name (target) """ def __init__(self,**args): url = args['url'] - self.uid = args['uid'] + self.uid = args['doc'] dbname = args['dbname'] 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: self.server = cloudant.CouchDB(args['username'],args['password'],url=url) self.server.connect() @@ -56,10 +56,10 @@ class Couch: def view(self,**args): """ - We are executing a view - :id design document _design/xxxx (provide full name with _design prefix) - :view_name name of the view i.e - :key key to be used to filter the content + The function will execute a view (provivded a user is authenticated) + :id design document _design/xxxx (provide full name with _design prefix) + :view_name name of the view i.e + :key(s) key(s) to be used to filter the content """ document = cloudant.design_document.DesignDocument(self.dbase,args['id']) document.fetch() diff --git a/transport/mongo.py b/transport/mongo.py index 5c11e56..51b6e28 100644 --- a/transport/mongo.py +++ b/transport/mongo.py @@ -23,7 +23,7 @@ class Mongo : else: self.client = MongoClient() - self.uid = args['uid'] #-- document identifier + self.uid = args['doc'] #-- document identifier self.dbname = args['dbname'] self.db = self.client[self.dbname] diff --git a/transport/queue.py b/transport/queue.py index 846f591..64c770a 100644 --- a/transport/queue.py +++ b/transport/queue.py @@ -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) :host - :uid identifier of the exchange + :xid identifier of the exchange :qid identifier of the queue """ def __init__(self,**params): self.host= params['host'] - self.uid = params['uid'] + self.uid = params['xid'] self.qid = params['qid'] def isready(self):