Steve Nyemba 5 years ago
parent
commit
e8328e577d
5 changed files with 38 additions and 25 deletions
  1. 18 6
      README.md
  2. 9 8
      transport/__init__.py
  3. 8 8
      transport/couch.py
  4. 1 1
      transport/mongo.py
  5. 2 2
      transport/queue.py

+ 18 - 6
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":"<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)
-    info   = couchdb.read()
+    document    = dreader.read()    
+    result      = couchdb.view(id='<design_doc_id>',view_name=<view_name',<key=value|keys=values>)
+    

+ 9 - 8
transport/__init__.py

@@ -22,7 +22,7 @@ The configuration for the data-store is as follows :
 				username:<username>,
 				password:<password>,
 				dbname:<database>,
-				uid:<document id>
+				doc:<document id>
 			}
 		}
 	RabbitMQ:
@@ -36,7 +36,7 @@ The configuration for the data-store is as follows :
 			username:<username>,
 			password:<password>,
 			dbname:<database>,
-			uid:<document id>s
+			doc:<document id>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)

+ 8 - 8
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()

+ 1 - 1
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]
         

+ 2 - 2
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):