conduit r1506 - in trunk: . conduit/modules/GoogleModule test/python-tests



Author: jstowers
Date: Sat Jun  7 01:27:35 2008
New Revision: 1506
URL: http://svn.gnome.org/viewvc/conduit?rev=1506&view=rev

Log:
2008-06-07  John Stowers  <john stowers gmail com>

	* conduit/modules/GoogleModule/GoogleModule.py:
	* conduit/modules/GoogleModule/documents-config.glade: Make 
	into a sink and implement put()

	* test/python-tests/TestDataProviderGoogleDocuments.py: Add make test use
	proper format (common.test_dataprovider)



Modified:
   trunk/ChangeLog
   trunk/conduit/modules/GoogleModule/GoogleModule.py
   trunk/conduit/modules/GoogleModule/documents-config.glade
   trunk/test/python-tests/TestDataProviderGoogleDocuments.py

Modified: trunk/conduit/modules/GoogleModule/GoogleModule.py
==============================================================================
--- trunk/conduit/modules/GoogleModule/GoogleModule.py	(original)
+++ trunk/conduit/modules/GoogleModule/GoogleModule.py	Sat Jun  7 01:27:35 2008
@@ -39,7 +39,7 @@
         "PicasaTwoWay" :         { "type": "dataprovider" },
         "YouTubeSource" :        { "type": "dataprovider" },    
         "ContactsTwoWay" :       { "type": "dataprovider" },
-#        "DocumentsSink" :        { "type": "dataprovider" },
+        "DocumentsSink" :        { "type": "dataprovider" },
     }
     log.info("Module Information: %s" % Utils.get_module_information(gdata, None))
 except (ImportError, AttributeError):
@@ -1014,7 +1014,7 @@
         
     def __str__(self):
         return "%s:%s by %s (modified:%s) (id:%s)" % (self.type,self.title,self.authorName,self.updated,self.docid)
-
+    
 class DocumentsSink(_GoogleBase,  DataProvider.DataSink):
     """
     Contacts GData provider
@@ -1024,7 +1024,7 @@
     _name_ = _("Google Documents")
     _description_ = _("Sync your Google Documents")
     _category_ = conduit.dataproviders.CATEGORY_OFFICE
-    _module_type_ = "twoway"
+    _module_type_ = "sink"
     _out_type_ = "contact"
     _icon_ = "applications-office"
     
@@ -1091,6 +1091,19 @@
 
         return _GoogleDocument(xmldoc)
         
+    def _get_proxyfile(self, LUID):
+        if LUID:
+            gdoc = self._get_document(LUID)
+            if gdoc:
+                f = File.ProxyFile(
+                            URI=gdoc.raw,
+                            name=gdoc.title,
+                            modified=gdoc.updated,
+                            size=None)
+                f.set_UID(LUID)
+                return f
+        return None
+        
     def _download_doc(self, googleDoc):
         docid = googleDoc.docid
     
@@ -1148,33 +1161,38 @@
     def get(self, LUID):
         pass
 
-#    def put(self, doc, overwrite, LUID=None):            
-#        #Check if we have already uploaded the document
-#        if LUID != None:
-#            info = self._get_photo_info(LUID)
-#            #check if a photo exists at that UID
-#            if info != None:
-#                if overwrite == True:
-#                    #replace the photo
-#                    return self._replace_photo(LUID, uploadInfo)
-#                else:
-#                    #Only upload the photo if it is newer than the Remote one
-#                    url = self._get_raw_photo_url(info)
-#                    remoteFile = File.File(url)
-#
-#                    #this is a limited test for equality type comparison
-#                    comp = photo.compare(remoteFile,True)
-#                    log.debug("Compared %s with %s to check if they are the same (size). Result = %s" % 
-#                            (photo.get_filename(),remoteFile.get_filename(),comp))
-#                    if comp != conduit.datatypes.COMPARISON_EQUAL:
-#                        raise Exceptions.SynchronizeConflictError(comp, photo, remoteFile)
-#                    else:
-#                        return conduit.datatypes.Rid(uid=LUID)
-#
-#        log.debug("Uploading Photo URI = %s, Mimetype = %s, Original Name = %s" % (photoURI, mimeType, originalName))
-#
-#        #upload the file
-#        return self._upload_photo (uploadInfo)
+    def put(self, f, overwrite, LUID=None):
+        DataProvider.DataSink.put(self, f, overwrite, LUID)       
+        #Check if we have already uploaded the document
+        if LUID != None:
+            gdoc = self._get_document(LUID)
+            #check if a doc exists at that UID
+            if gdoc != None:
+                if overwrite == True:
+                    #replace the document
+                    return self._replace_document(LUID, f)
+                else:
+                    #Only upload the doc if it is newer than the Remote one
+                    remoteFile = self._get_proxyfile(LUID)
+
+                    #compare based on mtime
+                    comp = f.compare(remoteFile)
+                    log.debug("Compared %s with %s to check if they are the same (mtime). Result = %s" % 
+                            (f.get_filename(),remoteFile.get_filename(),comp))
+                    if comp != conduit.datatypes.COMPARISON_EQUAL:
+                        raise Exceptions.SynchronizeConflictError(comp, photo, remoteFile)
+                    else:
+                        return conduit.datatypes.Rid(uid=LUID)
+
+        log.debug("Uploading Document")
+
+        #upload the file
+        pf = self._get_proxyfile(
+                        self._upload_document(f))
+        if pf:
+            return pf.get_rid()
+            
+        raise Exceptions.SynchronizeError("Error Uploading")
 
     def delete(self, LUID):
         DataProvider.DataSink.delete(self, LUID)
@@ -1194,6 +1212,10 @@
 
         def make_combo(widget, docType, val, values):
             cb = widget.get_widget("%sCombo" % docType)
+            
+            #FIXME: Make these unsensitive when download works better
+            cb.set_property("sensitive", False)
+            
             store = gtk.ListStore(str)
             cell = gtk.CellRendererText()
             

Modified: trunk/conduit/modules/GoogleModule/documents-config.glade
==============================================================================
--- trunk/conduit/modules/GoogleModule/documents-config.glade	(original)
+++ trunk/conduit/modules/GoogleModule/documents-config.glade	Sat Jun  7 01:27:35 2008
@@ -86,7 +86,7 @@
         <child>
           <widget class="GtkLabel" id="label1">
             <property name="visible">True</property>
-            <property name="label" translatable="yes">&lt;b&gt;Document Format&lt;/b&gt;</property>
+            <property name="label" translatable="yes">&lt;b&gt;Downloaded Document Format&lt;/b&gt;</property>
             <property name="use_markup">True</property>
           </widget>
           <packing>

Modified: trunk/test/python-tests/TestDataProviderGoogleDocuments.py
==============================================================================
--- trunk/test/python-tests/TestDataProviderGoogleDocuments.py	(original)
+++ trunk/test/python-tests/TestDataProviderGoogleDocuments.py	Sat Jun  7 01:27:35 2008
@@ -2,6 +2,11 @@
 from common import *
 import conduit.datatypes.File as File
 
+if not is_online():
+    skip()
+
+SAFE_DOCID = "http://docs.google.com/feeds/documents/private/full/document%3Adf32bhnd_2dv44zrfc";
+
 test = SimpleTest(sinkName="DocumentsSink")
 config = {
     "username":     os.environ.get("TEST_USERNAME","conduitproject gmail com"),
@@ -21,19 +26,31 @@
 num = len(docs)
 ok("Got %s documents" % num, num > 0)
 
-doc = google._get_document(docs[-1])
+doc = google._get_document(SAFE_DOCID)
 ok("Got safe document", doc != None)
 
+f = File.File(URI=get_external_resources("file")["doc"])
+test.do_dataprovider_tests(
+        supportsGet=False,
+        supportsDelete=False,
+        safeLUID=SAFE_DOCID,
+        data=f,
+        name="file"
+        )
 
 
-#finished()
+finished()
+
+print files
+
+finished()
 
 
 
 #path = google._download_doc(info['link'])
 #print "DL: %s" % path
 
-f = File.File(URI="/home/john/Desktop/test.ppt")
+
 LUID = google._upload_document(f)
 doc = google._get_document(LUID)
 



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