[Opensrf-commits] r1044 - in branches/new-json2: . src/python src/python/osrf

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Jul 17 10:56:28 EDT 2007


Author: erickson
Date: 2007-07-17 10:50:56 -0400 (Tue, 17 Jul 2007)
New Revision: 1044

Modified:
   branches/new-json2/
   branches/new-json2/src/python/osrf/conf.py
   branches/new-json2/src/python/osrf/log.py
   branches/new-json2/src/python/osrf/net_obj.py
   branches/new-json2/src/python/osrf/ses.py
   branches/new-json2/src/python/osrf/system.py
   branches/new-json2/src/python/osrf/utils.py
   branches/new-json2/src/python/srfsh.py
Log:
Merged revisions 1039-1043 via svnmerge from 
svn://svn.open-ils.org/OpenSRF/trunk

........
  r1041 | erickson | 2007-07-17 10:07:43 -0400 (Tue, 17 Jul 2007) | 1 line
  
  added config contexts for config files.  fixed some osrfNetworkObject handling bugs.  did some re-tabbing to change to space-based tabs
........



Property changes on: branches/new-json2
___________________________________________________________________
Name: svnmerge-integrated
   - /trunk:1-1038
   + /trunk:1-1043

Modified: branches/new-json2/src/python/osrf/conf.py
===================================================================
--- branches/new-json2/src/python/osrf/conf.py	2007-07-17 14:50:02 UTC (rev 1043)
+++ branches/new-json2/src/python/osrf/conf.py	2007-07-17 14:50:56 UTC (rev 1044)
@@ -16,33 +16,56 @@
 
 from osrf.utils import *
 from osrf.ex import *
+import re
 
 class osrfConfig(object):
-	"""Loads and parses the bootstrap config file"""
+    """Loads and parses the bootstrap config file"""
 
-	config = None
+    config = None
 
-	def __init__(self, file=None):
-		self.file = file	
-		self.data = {}
+    def __init__(self, file, context=None):
+        self.file = file    
+        self.context = context
+        self.data = {}
 
-	def parseConfig(self,file=None):
-		self.data = osrfXMLFileToObject(file or self.file)
-		osrfConfig.config = self
-	
-	def getValue(self, key, idx=None):
-		val = osrfObjectFindPath(self.data, key, idx)
-		if not val:
-			raise osrfConfigException("Config value not found: " + key)
-		return val
+    #def parseConfig(self,file=None):
+    def parseConfig(self):
+        self.data = osrfXMLFileToObject(self.file)
+        osrfConfig.config = self
+    
+    def getValue(self, key, idx=None):
+        if self.context:
+            if re.search('/', key):
+                key = "%s/%s" % (self.context, key)
+            else:
+                key = "%s.%s" % (self.context, key)
 
+        val = osrfObjectFindPath(self.data, key, idx)
+        if not val:
+            raise osrfConfigException("Config value not found: " + key)
+        return val
 
+
 def osrfConfigValue(key, idx=None):
-	"""Returns a bootstrap config value.
+    """Returns a bootstrap config value.
 
-	key -- A string representing the path to the value in the config object
-		e.g.  "domains.domain", "username"
-	idx -- Optional array index if the searched value is an array member
-	"""
-	return osrfConfig.config.getValue(key, idx)
-				
+    key -- A string representing the path to the value in the config object
+        e.g.  "domains.domain", "username"
+    idx -- Optional array index if the searched value is an array member
+    """
+    return osrfConfig.config.getValue(key, idx)
+                
+
+def osrfConfigValueNoEx(key, idx=None):
+    """ Returns a bootstrap config value without throwing an exception
+        if the item is not found. 
+
+    key -- A string representing the path to the value in the config object
+        e.g.  "domains.domain", "username"
+    idx -- Optional array index if the searched value is an array member
+    """
+    try:
+        return osrfConfig.config.getValue(key, idx)
+    except:
+        return None
+

Modified: branches/new-json2/src/python/osrf/log.py
===================================================================
--- branches/new-json2/src/python/osrf/log.py	2007-07-17 14:50:02 UTC (rev 1043)
+++ branches/new-json2/src/python/osrf/log.py	2007-07-17 14:50:56 UTC (rev 1044)
@@ -22,9 +22,14 @@
     """Initialize the logging subsystem."""
     import syslog
     global loglevel
-    if facility: osrfInitSyslog(facility, level)
+    if facility: 
+        osrfInitSyslog(facility, level)
+        syslog.syslog(syslog.LOG_DEBUG, "syslog initialized")
+    else:
+        if file:
+            sys.stderr.write("\n * file-based logging not implemented yet\n")
+            
     loglevel = level
-    syslog.syslog(LOG_DEBUG, "syslog initialized")
 
 
 # -----------------------------------------------------------------------
@@ -72,6 +77,8 @@
 def osrfInitSyslog(facility, level):
     """Connect to syslog and set the logmask based on the level provided."""
 
+    import syslog
+
     level = int(level)
 
     if facility == 'local0': facility = syslog.LOG_LOCAL0
@@ -82,13 +89,13 @@
     if facility == 'local5': facility = syslog.LOG_LOCAL5
     if facility == 'local6': facility = syslog.LOG_LOCAL6
     # XXX add other facility maps if necessary
-    openlog(sys.argv[0], 0, facility)
+    syslog.openlog(sys.argv[0], 0, facility)
 
     # this is redundant...
-    mask = LOG_UPTO(syslog.LOG_ERR)
-    if level >= 1: mask |= LOG_MASK(syslog.LOG_WARNING)
-    if level >= 2: mask |= LOG_MASK(syslog.LOG_NOTICE)
-    if level >= 3: mask |= LOG_MASK(syslog.LOG_INFO)
-    if level >= 4: mask |= LOG_MASK(syslog.LOG_DEBUG)
+    mask = syslog.LOG_UPTO(syslog.LOG_ERR)
+    if level >= 1: mask |= syslog.LOG_MASK(syslog.LOG_WARNING)
+    if level >= 2: mask |= syslog.LOG_MASK(syslog.LOG_NOTICE)
+    if level >= 3: mask |= syslog.LOG_MASK(syslog.LOG_INFO)
+    if level >= 4: mask |= syslog.LOG_MASK(syslog.LOG_DEBUG)
     syslog.setlogmask(mask)
 

Modified: branches/new-json2/src/python/osrf/net_obj.py
===================================================================
--- branches/new-json2/src/python/osrf/net_obj.py	2007-07-17 14:50:02 UTC (rev 1043)
+++ branches/new-json2/src/python/osrf/net_obj.py	2007-07-17 14:50:56 UTC (rev 1044)
@@ -13,7 +13,6 @@
         return obj
     except AttributeError:
         return osrfNetworkObject.__unknown()
-#newFromHint = staticmethod(newFromHint)
 
 
 ''' Global object registry '''
@@ -76,9 +75,8 @@
         If this is an array, we pull data out of the data array
         (if there is any) and translate that into a hash internally
         '''
-
     self.__data = data
-    if len(data) > 0:
+    if isinstance(data, list) and len(data) > 0:
         reg = self.getRegistry()
         if reg.wireProtocol == 'array':
             self.__data = {}
@@ -134,33 +132,49 @@
 # Define the custom object parsing behavior 
 # -------------------------------------------------------------------
 def parseNetObject(obj):
-    hint = None
-    islist = False
+    
     try:
+
         hint = obj[OSRF_JSON_CLASS_KEY]
-        obj = obj[OSRF_JSON_PAYLOAD_KEY]
-    except: pass
-    if isinstance(obj,list):
-        islist = True
-        for i in range(len(obj)):
-            obj[i] = parseNetObject(obj[i])
-    else: 
-        if isinstance(obj,dict):
-            for k,v in obj.iteritems():
-                obj[k] = parseNetObject(v)
+        subObj = obj[OSRF_JSON_PAYLOAD_KEY]
+        reg = osrfNetworkRegistry.getRegistry(hint)
 
-    if hint: # Now, "bless" the object into an osrfNetworkObject
+        obj = {}
+
+        if reg.wireProtocol == 'array':
+            for i in range(len(reg.keys)):
+                if len(subObj) > i:
+                    obj[reg.keys[i]] = parseNetObject(subObj[i])
+                else:
+                    obj[reg.keys[i]] = None
+        else:
+            for k in reg.keys:
+                obj[k] = parseNetObject(subObj.get(k))
+
         estr = 'obj = osrfNetworkObject.%s(obj)' % hint
         try:
             exec(estr)
-        except AttributeError:
+        except e:
             # this object has not been registered, shove it into the default container
             obj = osrfNetworkObject.__unknown(obj)
 
+        return obj
+
+    except: pass
+
+    # the current object does not have a class hint
+    if isinstance(obj, list):
+        for i in range(len(obj)):
+            obj[i] = parseNetObject(obj[i])
+
+    else:
+        if isinstance(obj, dict):
+            for k,v in obj.iteritems():
+                obj[k] = parseNetObject(v)
+
     return obj;
 
 
-
 def osrfObjectToXML(obj):
     """ Returns the XML representation of an internal object."""
     chars = []

Modified: branches/new-json2/src/python/osrf/ses.py
===================================================================
--- branches/new-json2/src/python/osrf/ses.py	2007-07-17 14:50:02 UTC (rev 1043)
+++ branches/new-json2/src/python/osrf/ses.py	2007-07-17 14:50:56 UTC (rev 1044)
@@ -33,276 +33,276 @@
 
 
 class osrfSession(object):
-	"""Abstract session superclass."""
+    """Abstract session superclass."""
 
-	def __init__(self):
-		# by default, we're connected to no one
-		self.state = OSRF_APP_SESSION_DISCONNECTED
+    def __init__(self):
+        # by default, we're connected to no one
+        self.state = OSRF_APP_SESSION_DISCONNECTED
 
 
-	def wait(self, timeout=120):
-		"""Wait up to <timeout> seconds for data to arrive on the network"""
-		osrfLogInternal("osrfSession.wait(%d)" % timeout)
-		handle = osrfGetNetworkHandle()
-		handle.recv(timeout)
+    def wait(self, timeout=120):
+        """Wait up to <timeout> seconds for data to arrive on the network"""
+        osrfLogInternal("osrfSession.wait(%d)" % timeout)
+        handle = osrfGetNetworkHandle()
+        handle.recv(timeout)
 
-	def send(self, omessage):
-		"""Sends an OpenSRF message"""
-		netMessage = osrfNetworkMessage(
-			to		= self.remoteId,
-			body	= osrfObjectToJSON([omessage]),
-			thread = self.thread )
+    def send(self, omessage):
+        """Sends an OpenSRF message"""
+        netMessage = osrfNetworkMessage(
+            to      = self.remoteId,
+            body    = osrfObjectToJSON([omessage]),
+            thread = self.thread )
 
-		handle = osrfGetNetworkHandle()
-		handle.send(netMessage)
+        handle = osrfGetNetworkHandle()
+        handle.send(netMessage)
 
-	def cleanup(self):
-		"""Removes the session from the global session cache."""
-		del osrfClientSession.sessionCache[self.thread]
+    def cleanup(self):
+        """Removes the session from the global session cache."""
+        del osrfClientSession.sessionCache[self.thread]
 
 class osrfClientSession(osrfSession):
-	"""Client session object.  Use this to make server requests."""
+    """Client session object.  Use this to make server requests."""
 
-	def __init__(self, service):
-		
-		# call superclass constructor
-		osrfSession.__init__(self)
+    def __init__(self, service):
+        
+        # call superclass constructor
+        osrfSession.__init__(self)
 
-		# the remote service we want to make requests of
-		self.service = service
+        # the remote service we want to make requests of
+        self.service = service
 
-		# find the remote service handle <router>@<domain>/<service>
-		domain = osrfConfigValue('domains.domain', 0)
-		router = osrfConfigValue('router_name')
-		self.remoteId = "%s@%s/%s" % (router, domain, service)
-		self.origRemoteId = self.remoteId
+        # find the remote service handle <router>@<domain>/<service>
+        domain = osrfConfigValue('domains.domain', 0)
+        router = osrfConfigValue('router_name')
+        self.remoteId = "%s@%s/%s" % (router, domain, service)
+        self.origRemoteId = self.remoteId
 
-		# generate a random message thread
-		self.thread = "%s%s%s" % (os.getpid(), str(random.randint(100,100000)), str(time.time()))
+        # generate a random message thread
+        self.thread = "%s%s%s" % (os.getpid(), str(random.randint(100,100000)), str(time.time()))
 
-		# how many requests this session has taken part in
-		self.nextId = 0 
+        # how many requests this session has taken part in
+        self.nextId = 0 
 
-		# cache of request objects 
-		self.requests = {}
+        # cache of request objects 
+        self.requests = {}
 
-		# cache this session in the global session cache
-		osrfClientSession.sessionCache[self.thread] = self
+        # cache this session in the global session cache
+        osrfClientSession.sessionCache[self.thread] = self
 
-	def resetRequestTimeout(self, rid):
-		req = self.findRequest(rid)
-		if req:
-			req.resetTimeout = True
-			
+    def resetRequestTimeout(self, rid):
+        req = self.findRequest(rid)
+        if req:
+            req.resetTimeout = True
+            
 
-	def request2(self, method, arr):
-		"""Creates a new request and sends the request to the server using a python array as the params."""
-		return self.__request(method, arr)
+    def request2(self, method, arr):
+        """Creates a new request and sends the request to the server using a python array as the params."""
+        return self.__request(method, arr)
 
-	def request(self, method, *args):
-		"""Creates a new request and sends the request to the server using a variable argument list as params"""
-		arr = list(args)
-		return self.__request(method, arr)
+    def request(self, method, *args):
+        """Creates a new request and sends the request to the server using a variable argument list as params"""
+        arr = list(args)
+        return self.__request(method, arr)
 
-	def __request(self, method, arr):
-		"""Builds the request object and sends it."""
-		if self.state != OSRF_APP_SESSION_CONNECTED:
-			self.resetRemoteId()
+    def __request(self, method, arr):
+        """Builds the request object and sends it."""
+        if self.state != OSRF_APP_SESSION_CONNECTED:
+            self.resetRemoteId()
 
-		osrfLogDebug("Sending request %s -> %s " % (self.service, method))
-		req = osrfRequest(self, self.nextId, method, arr)
-		self.requests[str(self.nextId)] = req
-		self.nextId += 1
-		req.send()
-		return req
+        osrfLogDebug("Sending request %s -> %s " % (self.service, method))
+        req = osrfRequest(self, self.nextId, method, arr)
+        self.requests[str(self.nextId)] = req
+        self.nextId += 1
+        req.send()
+        return req
 
 
-	def connect(self, timeout=10):
-		"""Connects to a remote service"""
+    def connect(self, timeout=10):
+        """Connects to a remote service"""
 
-		if self.state == OSRF_APP_SESSION_CONNECTED:
-			return True
-		self.state == OSRF_APP_SESSION_CONNECTING
+        if self.state == OSRF_APP_SESSION_CONNECTED:
+            return True
+        self.state == OSRF_APP_SESSION_CONNECTING
 
-		# construct and send a CONNECT message
-		self.send(
-			osrfNetworkObject.osrfMessage( 
-				{	'threadTrace' : 0,
-					'type' : OSRF_MESSAGE_TYPE_CONNECT
-				} 
-			)
-		)
+        # construct and send a CONNECT message
+        self.send(
+            osrfNetworkObject.osrfMessage( 
+                {   'threadTrace' : 0,
+                    'type' : OSRF_MESSAGE_TYPE_CONNECT
+                } 
+            )
+        )
 
-		while timeout >= 0 and not self.state == OSRF_APP_SESSION_CONNECTED:
-			start = time.time()
-			self.wait(timeout)
-			timeout -= time.time() - start
-		
-		if self.state != OSRF_APP_SESSION_CONNECTED:
-			raise osrfServiceException("Unable to connect to " + self.service)
-		
-		return True
+        while timeout >= 0 and not self.state == OSRF_APP_SESSION_CONNECTED:
+            start = time.time()
+            self.wait(timeout)
+            timeout -= time.time() - start
+        
+        if self.state != OSRF_APP_SESSION_CONNECTED:
+            raise osrfServiceException("Unable to connect to " + self.service)
+        
+        return True
 
-	def disconnect(self):
-		"""Disconnects from a remote service"""
+    def disconnect(self):
+        """Disconnects from a remote service"""
 
-		if self.state == OSRF_APP_SESSION_DISCONNECTED:
-			return True
+        if self.state == OSRF_APP_SESSION_DISCONNECTED:
+            return True
 
-		self.send(
-			osrfNetworkObject.osrfMessage( 
-				{	'threadTrace' : 0,
-					'type' : OSRF_MESSAGE_TYPE_DISCONNECT
-				} 
-			)
-		)
+        self.send(
+            osrfNetworkObject.osrfMessage( 
+                {   'threadTrace' : 0,
+                    'type' : OSRF_MESSAGE_TYPE_DISCONNECT
+                } 
+            )
+        )
 
-		self.state = OSRF_APP_SESSION_DISCONNECTED
+        self.state = OSRF_APP_SESSION_DISCONNECTED
 
 
-		
-	
-	def setRemoteId(self, remoteid):
-		self.remoteId = remoteid
-		osrfLogInternal("Setting request remote ID to %s" % self.remoteId)
+        
+    
+    def setRemoteId(self, remoteid):
+        self.remoteId = remoteid
+        osrfLogInternal("Setting request remote ID to %s" % self.remoteId)
 
-	def resetRemoteId(self):
-		"""Recovers the original remote id"""
-		self.remoteId = self.origRemoteId
-		osrfLogInternal("Resetting remote ID to %s" % self.remoteId)
+    def resetRemoteId(self):
+        """Recovers the original remote id"""
+        self.remoteId = self.origRemoteId
+        osrfLogInternal("Resetting remote ID to %s" % self.remoteId)
 
-	def pushResponseQueue(self, message):
-		"""Pushes the message payload onto the response queue 
-			for the request associated with the message's ID."""
-		osrfLogDebug("pushing %s" % message.payload())
-		try:
-			self.findRequest(message.threadTrace()).pushResponse(message.payload())
-		except Exception, e: 
-			osrfLogWarn("pushing respond to non-existent request %s : %s" % (message.threadTrace(), e))
+    def pushResponseQueue(self, message):
+        """Pushes the message payload onto the response queue 
+            for the request associated with the message's ID."""
+        osrfLogDebug("pushing %s" % message.payload())
+        try:
+            self.findRequest(message.threadTrace()).pushResponse(message.payload())
+        except Exception, e: 
+            osrfLogWarn("pushing respond to non-existent request %s : %s" % (message.threadTrace(), e))
 
-	def findRequest(self, rid):
-		"""Returns the original request matching this message's threadTrace."""
-		try:
-			return self.requests[str(rid)]
-		except KeyError:
-			osrfLogDebug('findRequest(): non-existent request %s' % str(rid))
-			return None
+    def findRequest(self, rid):
+        """Returns the original request matching this message's threadTrace."""
+        try:
+            return self.requests[str(rid)]
+        except KeyError:
+            osrfLogDebug('findRequest(): non-existent request %s' % str(rid))
+            return None
 
 
 
 osrfSession.sessionCache = {}
 def osrfFindSession(thread):
-	"""Finds a session in the global cache."""
-	try:
-		return osrfClientSession.sessionCache[thread]
-	except: return None
+    """Finds a session in the global cache."""
+    try:
+        return osrfClientSession.sessionCache[thread]
+    except: return None
 
 class osrfRequest(object):
-	"""Represents a single OpenSRF request.
-		A request is made and any resulting respones are 
-		collected for the client."""
+    """Represents a single OpenSRF request.
+        A request is made and any resulting respones are 
+        collected for the client."""
 
-	def __init__(self, session, id, method=None, params=[]):
+    def __init__(self, session, id, method=None, params=[]):
 
-		self.session = session # my session handle
-		self.id		= id # my unique request ID
-		self.method = method # method name
-		self.params = params # my method params
-		self.queue	= [] # response queue
-		self.resetTimeout = False # resets the recv timeout?
-		self.complete = False # has the server told us this request is done?
-		self.sendTime = 0 # local time the request was put on the wire
-		self.completeTime =  0 # time the server told us the request was completed
-		self.firstResponseTime = 0 # time it took for our first reponse to be received
+        self.session = session # my session handle
+        self.id     = id # my unique request ID
+        self.method = method # method name
+        self.params = params # my method params
+        self.queue  = [] # response queue
+        self.resetTimeout = False # resets the recv timeout?
+        self.complete = False # has the server told us this request is done?
+        self.sendTime = 0 # local time the request was put on the wire
+        self.completeTime =  0 # time the server told us the request was completed
+        self.firstResponseTime = 0 # time it took for our first reponse to be received
 
-	def send(self):
-		"""Sends a request message"""
+    def send(self):
+        """Sends a request message"""
 
-		# construct the method object message with params and method name
-		method = osrfNetworkObject.osrfMethod( {
-			'method' : self.method,
-			'params' : self.params
-		} )
+        # construct the method object message with params and method name
+        method = osrfNetworkObject.osrfMethod( {
+            'method' : self.method,
+            'params' : self.params
+        } )
 
-		# construct the osrf message with our method message embedded
-		message = osrfNetworkObject.osrfMessage( {
-			'threadTrace' : self.id,
-			'type' : OSRF_MESSAGE_TYPE_REQUEST,
-			'payload' : method
-		} )
+        # construct the osrf message with our method message embedded
+        message = osrfNetworkObject.osrfMessage( {
+            'threadTrace' : self.id,
+            'type' : OSRF_MESSAGE_TYPE_REQUEST,
+            'payload' : method
+        } )
 
-		self.sendTime = time.time()
-		self.session.send(message)
+        self.sendTime = time.time()
+        self.session.send(message)
 
-	def recv(self, timeout=120):
-		"""Waits up to <timeout> seconds for a response to this request.
-		
-			If a message is received in time, the response message is returned.
-			Returns None otherwise."""
+    def recv(self, timeout=120):
+        """Waits up to <timeout> seconds for a response to this request.
+        
+            If a message is received in time, the response message is returned.
+            Returns None otherwise."""
 
-		self.session.wait(0)
+        self.session.wait(0)
 
-		origTimeout = timeout
-		while not self.complete and timeout >= 0 and len(self.queue) == 0:
-			s = time.time()
-			self.session.wait(timeout)
-			timeout -= time.time() - s
-			if self.resetTimeout:
-				self.resetTimeout = False
-				timeout = origTimeout
+        origTimeout = timeout
+        while not self.complete and timeout >= 0 and len(self.queue) == 0:
+            s = time.time()
+            self.session.wait(timeout)
+            timeout -= time.time() - s
+            if self.resetTimeout:
+                self.resetTimeout = False
+                timeout = origTimeout
 
-		now = time.time()
+        now = time.time()
 
-		# -----------------------------------------------------------------
-		# log some statistics 
-		if len(self.queue) > 0:
-			if not self.firstResponseTime:
-				self.firstResponseTime = now
-				osrfLogDebug("time elapsed before first response: %f" \
-					% (self.firstResponseTime - self.sendTime))
+        # -----------------------------------------------------------------
+        # log some statistics 
+        if len(self.queue) > 0:
+            if not self.firstResponseTime:
+                self.firstResponseTime = now
+                osrfLogDebug("time elapsed before first response: %f" \
+                    % (self.firstResponseTime - self.sendTime))
 
-		if self.complete:
-			if not self.completeTime:
-				self.completeTime = now
-				osrfLogDebug("time elapsed before complete: %f" \
-					% (self.completeTime - self.sendTime))
-		# -----------------------------------------------------------------
+        if self.complete:
+            if not self.completeTime:
+                self.completeTime = now
+                osrfLogDebug("time elapsed before complete: %f" \
+                    % (self.completeTime - self.sendTime))
+        # -----------------------------------------------------------------
 
 
-		if len(self.queue) > 0:
-			# we have a reponse, return it
-			return self.queue.pop(0)
+        if len(self.queue) > 0:
+            # we have a reponse, return it
+            return self.queue.pop(0)
 
-		return None
+        return None
 
-	def pushResponse(self, content):
-		"""Pushes a method response onto this requests response queue."""
-		self.queue.append(content)
+    def pushResponse(self, content):
+        """Pushes a method response onto this requests response queue."""
+        self.queue.append(content)
 
-	def cleanup(self):
-		"""Cleans up request data from the cache. 
+    def cleanup(self):
+        """Cleans up request data from the cache. 
 
-			Do this when you are done with a request to prevent "leaked" cache memory."""
-		del self.session.requests[str(self.id)]
+            Do this when you are done with a request to prevent "leaked" cache memory."""
+        del self.session.requests[str(self.id)]
 
-	def setComplete(self):
-		"""Sets me as complete.  This means the server has sent a 'request complete' message"""
-		self.complete = True
+    def setComplete(self):
+        """Sets me as complete.  This means the server has sent a 'request complete' message"""
+        self.complete = True
 
 
 class osrfServerSession(osrfSession):
-	"""Implements a server-side session"""
-	pass
+    """Implements a server-side session"""
+    pass
 
 
 def osrfAtomicRequest(service, method, *args):
-	ses = osrfClientSession(service)
-	req = ses.request2('open-ils.cstore.direct.actor.user.retrieve', list(args)) # grab user with ID 1
-	resp = req.recv()
-	data = resp.content()
-	req.cleanup()
-	ses.cleanup()
-	return data
+    ses = osrfClientSession(service)
+    req = ses.request2(method, list(args))
+    resp = req.recv()
+    data = resp.content()
+    req.cleanup()
+    ses.cleanup()
+    return data
 
 
 

Modified: branches/new-json2/src/python/osrf/system.py
===================================================================
--- branches/new-json2/src/python/osrf/system.py	2007-07-17 14:50:02 UTC (rev 1043)
+++ branches/new-json2/src/python/osrf/system.py	2007-07-17 14:50:56 UTC (rev 1044)
@@ -13,7 +13,7 @@
 # GNU General Public License for more details.
 # -----------------------------------------------------------------------
 
-from osrf.conf import osrfConfig, osrfConfigValue
+from osrf.conf import osrfConfig, osrfConfigValue, osrfConfigValueNoEx
 from osrf.net import osrfNetwork, osrfSetNetworkHandle
 from osrf.stack import osrfPushStack
 from osrf.log import *
@@ -21,28 +21,31 @@
 import sys
 
 
-def osrfConnect(configFile):
-	""" Connects to the opensrf network """
+def osrfConnect(configFile, configContext):
+    """ Connects to the opensrf network """
 
-	# parse the config file
-	configParser = osrfConfig(configFile)
-	configParser.parseConfig()
-	
-	# set up logging
-	osrfInitLog(osrfConfigValue('loglevel'), osrfConfigValue('syslog'))
+    # parse the config file
+    configParser = osrfConfig(configFile, configContext)
+    configParser.parseConfig()
+    
+    # set up logging
+    osrfInitLog(
+        osrfConfigValue('loglevel'), 
+        osrfConfigValueNoEx('syslog'),
+        osrfConfigValueNoEx('logfile'))
 
-	# connect to the opensrf network
-	network = osrfNetwork(
-		host=osrfConfigValue('domains.domain'),
-		port=osrfConfigValue('port'),
-		username=osrfConfigValue('username'), 
-		password=osrfConfigValue('passwd'))
-	network.setRecvCallback(osrfPushStack)
-	osrfSetNetworkHandle(network)
-	network.connect()
+    # connect to the opensrf network
+    network = osrfNetwork(
+        host=osrfConfigValue('domains.domain'),
+        port=osrfConfigValue('port'),
+        username=osrfConfigValue('username'), 
+        password=osrfConfigValue('passwd'))
+    network.setRecvCallback(osrfPushStack)
+    osrfSetNetworkHandle(network)
+    network.connect()
 
-	# load the domain-wide settings file
-	osrfLoadSettings(osrfConfigValue('domains.domain'))
+    # load the domain-wide settings file
+    osrfLoadSettings(osrfConfigValue('domains.domain'))
 
 
 

Modified: branches/new-json2/src/python/osrf/utils.py
===================================================================
--- branches/new-json2/src/python/osrf/utils.py	2007-07-17 14:50:02 UTC (rev 1043)
+++ branches/new-json2/src/python/osrf/utils.py	2007-07-17 14:50:56 UTC (rev 1044)
@@ -3,14 +3,14 @@
 def osrfXMLFileToObject(filename):
     """Turns the contents of an XML file into a Python object"""
     doc = xml.dom.minidom.parse(filename)
-    obj = osrfXMLNodeToObject(doc.childNodes[0])
+    obj = osrfXMLNodeToObject(doc.documentElement)
     doc.unlink()
     return obj
 
 def osrfXMLStringToObject(string):
     """Turns an XML string into a Python object"""
     doc = xml.dom.minidom.parseString(string)
-    obj = osrfXMLNodeToObject(doc.childNodes[0])
+    obj = osrfXMLNodeToObject(doc.documentElement)
     doc.unlink()
     return obj
 
@@ -72,7 +72,7 @@
 
     parts = []
 
-    if re.compile('/').search(path):
+    if re.search('/', path):
         parts = path.split('/')
     else:
         parts = path.split('.')

Modified: branches/new-json2/src/python/srfsh.py
===================================================================
--- branches/new-json2/src/python/srfsh.py	2007-07-17 14:50:02 UTC (rev 1043)
+++ branches/new-json2/src/python/srfsh.py	2007-07-17 14:50:56 UTC (rev 1044)
@@ -214,9 +214,8 @@
 
 def do_connect():
 	file = os.path.join(get_var('HOME'), ".srfsh.xml")
-
 	print_green("Connecting to opensrf...")
-	osrfConnect(file)
+	osrfConnect(file, 'srfsh')
 	print_red('OK\n')
 
 def load_plugins():



More information about the opensrf-commits mailing list