online-desktop r7242 - trunk/pyddm/ddm



Author: otaylor
Date: Fri Feb  8 22:30:19 2008
New Revision: 7242
URL: http://svn.gnome.org/viewvc/online-desktop?rev=7242&view=rev

Log:
Support updates with fetch strings and return objects


Modified:
   trunk/pyddm/ddm/AbstractModel.py
   trunk/pyddm/ddm/DataModel.py

Modified: trunk/pyddm/ddm/AbstractModel.py
==============================================================================
--- trunk/pyddm/ddm/AbstractModel.py	(original)
+++ trunk/pyddm/ddm/AbstractModel.py	Fri Feb  8 22:30:19 2008
@@ -102,6 +102,10 @@
 
         Arguments:
         method -- the method to call. A tuple of (namespace_uri, name)
+        fetch -- the fetch string to use for retrieving data, if the update method has a result (default None)
+        single_result -- if True, the method is expected to return exactly one object, and an
+           error will result if it returns 0 or more than 1 object. If False,
+           the method returns a possibly-empty list of objects. (default False)
 
         Additional keyword arguments are passed to the query
         method. The query will not actually be sent until you call

Modified: trunk/pyddm/ddm/DataModel.py
==============================================================================
--- trunk/pyddm/ddm/DataModel.py	(original)
+++ trunk/pyddm/ddm/DataModel.py	Fri Feb  8 22:30:19 2008
@@ -145,11 +145,11 @@
 
     def query(self, method, fetch=None, single_result=False, **kwargs):
         _logger.debug("doing query: %s fetch=%s, single_result=%s", method, fetch, single_result)
-        return _DBusQuery(self, method, fetch, single_result, kwargs)
+        return _DBusQuery(self, method, fetch, single_result, kwargs, False)
 
-    def update(self, method, **kwargs):
+    def update(self, method, fetch=None, single_result=False, **kwargs):
         _logger.debug("doing update: %s", method)        
-        return _DBusUpdate(self, method, kwargs)
+        return _DBusQuery(self, method, fetch, single_result, kwargs, True)
 
     def __update_property_from_dbus(self, resource, property_struct, notifications):
         property_uri, property_name, update_byte, type_byte, cardinality_byte, value = property_struct
@@ -225,12 +225,15 @@
         notifications.send()
     
 class _DBusQuery(Query):
-    def __init__(self, model, method, fetch, single_result, params):
+    def __init__(self, model, method, fetch, single_result, params, is_update):
         Query.__init__(self, params, single_result)
         self.__model = model
         self.__method = method
+        if fetch == None:
+            fetch = ""
         self.__fetch = fetch
         self.__single_result = single_result
+        self.__is_update = is_update
 
     def __on_query_reply(self, resources):
         result = []
@@ -266,39 +269,9 @@
 
         method_uri = self.__method[0] + "#" + self.__method[1]
         #_logger.debug("executing query method: '%s' fetch: '%s' params: '%s'", method_uri, self.__fetch, self._params)
-        self.__model._get_proxy().Query(self.__model.callback.path, method_uri, self.__fetch, self._params,
-                                        dbus_interface='org.freedesktop.od.Model', reply_handler=self.__on_query_reply, error_handler=self.__on_query_error)
-        
-
-class _DBusUpdate(Query):
-    def __init__(self, model, method, params):
-        Query.__init__(self, params)
-        self.__model = model
-        self.__method = method
-
-    def __on_update_reply(self):
-        self._on_success()
-
-    def __on_update_error(self, err):
-        # FIXME: As of dbus-python-0.80, exception handling is very, very, limited
-        # all we get is the message, so we can't do anything special for the defined
-        # DataModel errors. This is fixed in later versions of dbus-python, where we can
-        # get the exception type and the args
-        #
-        _logger.error('Caught error: %s', err.message)
-        self._on_error(ERROR_FAILED, err.message)
-
-    def __async_no_connection_error(self):
-        self._on_error(ERROR_NO_CONNECTION, "No connection to engine")
-        return False
-
-    def execute(self):
-        if self.__model._proxy == None:
-            gobject.idle_add(self.__async_no_connection_error)
-            return
-
-        method_uri = self.__method[0] + "#" + self.__method[1]
-        _logger.debug("executing update method: '%s' params: '%s'", method_uri, self._params)
-        self.__model._get_proxy().Update(method_uri, self._params,
-                                         dbus_interface='org.freedesktop.od.Model', reply_handler=self.__on_update_reply, error_handler=self.__on_update_error)
-        
+        if self.__is_update:
+            self.__model._get_proxy().Update(self.__model.callback.path, method_uri, self.__fetch, self._params,
+                                             dbus_interface='org.freedesktop.od.Model', reply_handler=self.__on_query_reply, error_handler=self.__on_query_error)
+        else:
+            self.__model._get_proxy().Query(self.__model.callback.path, method_uri, self.__fetch, self._params,
+                                            dbus_interface='org.freedesktop.od.Model', reply_handler=self.__on_query_reply, error_handler=self.__on_query_error)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]