conduit r1233 - in trunk: . conduit/dataproviders conduit/modules conduit/modules/BoxDotNetModule conduit/modules/GConfModule test/python-tests
- From: jstowers svn gnome org
- To: svn-commits-list gnome org
- Subject: conduit r1233 - in trunk: . conduit/dataproviders conduit/modules conduit/modules/BoxDotNetModule conduit/modules/GConfModule test/python-tests
- Date: Wed, 16 Jan 2008 12:50:06 +0000 (GMT)
Author: jstowers
Date: Wed Jan 16 12:50:06 2008
New Revision: 1233
URL: http://svn.gnome.org/viewvc/conduit?rev=1233&view=rev
Log:
2008-01-17 John Stowers <john stowers gmail com>
* conduit/dataproviders/File.py:
* conduit/modules/BoxDotNetModule/BoxDotNetModule.py:
* conduit/modules/GConfModule/GConfModule.py:
* conduit/modules/TomboyModule.py: Fix bug in twoway GConf to folder sync
where Rids() get confused if data is converted. The general solution to
this is to always return a new datatype.get_rid() from put() if you are
a twoway sync. I repeat, if you are a DataProviderTwoWay, and unless you
are smart or have special requirements (such as conserving bandwidth) the
final line in put() should look like return self.get(LUID).get_rid()
* test/python-tests/common.py: split out dp_image_dataprovider_tests into
do_dataprovider_tests and put get() put() delete() tests in there
* test/python-tests/TestDataProviderBoxDotNet.py: Use do_dataprovider_tests
Modified:
trunk/ChangeLog
trunk/conduit/dataproviders/File.py
trunk/conduit/modules/BoxDotNetModule/BoxDotNetModule.py
trunk/conduit/modules/GConfModule/GConfModule.py
trunk/conduit/modules/TomboyModule.py
trunk/test/python-tests/TestDataProviderBoxDotNet.py
trunk/test/python-tests/common.py
Modified: trunk/conduit/dataproviders/File.py
==============================================================================
--- trunk/conduit/dataproviders/File.py (original)
+++ trunk/conduit/dataproviders/File.py Wed Jan 16 12:50:06 2008
@@ -229,12 +229,8 @@
)
if overwrite or comp == DataType.COMPARISON_NEWER:
vfsFile.transfer(newURI, True)
- vfsFile.set_UID(newURI)
- #FIXME: I think we can return vfsFile.get_rid() because after transfer
- #the file info (size,mtime) is reloaded, so we are not permuting anything in place
- #also, we have set_UID to reflect the files destination ID
- return vfsFile.get_rid()
+ return self.get(newURI).get_rid()
def delete(self, LUID):
f = File.File(URI=LUID)
Modified: trunk/conduit/modules/BoxDotNetModule/BoxDotNetModule.py
==============================================================================
--- trunk/conduit/modules/BoxDotNetModule/BoxDotNetModule.py (original)
+++ trunk/conduit/modules/BoxDotNetModule/BoxDotNetModule.py Wed Jan 16 12:50:06 2008
@@ -91,7 +91,8 @@
#------------------------------------------
def _upload_file (self, file_path, filename):
"""
- Upload the file to url
+ Upload the file to box.net
+ @returns: uid of the file
"""
rsp = self.boxapi.upload(file_path,
auth_token=self.token,
@@ -101,12 +102,13 @@
)
uid = rsp.files[0].file[0].attrib['id']
- return Rid(uid=uid)
+ return uid
def _replace_file (self, fileID, url, name):
"""
Box.net automatically replaces files with same name, so we can
use the plain upload method
+ @returns: uid of the file
"""
return self._upload_file(url, name)
@@ -237,17 +239,18 @@
#Gets the local URI (/foo/bar). If this is a remote file then
#it is first transferred to the local filesystem
fileURI = file.get_local_uri()
-
mimeType = file.get_mimetype()
-
- #Check if we have already uploaded the file
- if LUID != None:
- id = self._get_file_info(LUID)
+
+ if LUID == None:
+ log.debug("Uploading file URI = %s, Mimetype = %s, Original Name = %s" % (fileURI, mimeType, originalName))
+ LUID = self._upload_file (fileURI, originalName)
+ else:
#check if a file exists at that UID
- if id:
+ id = self._get_file_info(LUID)
+ if id != None:
if overwrite == True:
- #replace the file
- return self._replace_file(LUID, fileURI, originalName)
+ log.debug("Replacing file URI = %s, Mimetype = %s, Original Name = %s" % (fileURI, mimeType, originalName))
+ LUID = self._replace_file(LUID, fileURI, originalName)
else:
#Only upload the file if it is newer than the Remote one
url = self._get_raw_file_url(id)
@@ -255,17 +258,11 @@
#this is a limited test for equality type comparison
comp = file.compare(remoteFile,True)
- log.debug("Compared %s with %s to check if they are the same (size). Result = %s" %
- (file.get_filename(),remoteFile.get_filename(),comp))
+ log.debug("Compared %s with %s to check if they are the same (size). Result = %s" % (file.get_filename(),remoteFile.get_filename(),comp))
if comp != conduit.datatypes.COMPARISON_EQUAL:
raise Exceptions.SynchronizeConflictError(comp, file, remoteFile)
- else:
- return Rid(uid=LUID)
-
- log.debug("Uploading file URI = %s, Mimetype = %s, Original Name = %s" % (fileURI, mimeType, originalName))
-
- #upload the file
- return self._upload_file (fileURI, originalName)
+
+ return self.get(LUID).get_rid()
def delete(self, LUID):
"""
@@ -276,7 +273,6 @@
target='file',
target_id=LUID)
-
def configure(self, window):
"""
Configures the BoxDotNet sink
Modified: trunk/conduit/modules/GConfModule/GConfModule.py
==============================================================================
--- trunk/conduit/modules/GConfModule/GConfModule.py (original)
+++ trunk/conduit/modules/GConfModule/GConfModule.py Wed Jan 16 12:50:06 2008
@@ -145,7 +145,6 @@
if not node:
log.debug("Could not find uid %s" % uid)
return None
-
s = Setting.Setting(
key=uid,
value=self._from_gconf(node)
@@ -161,9 +160,11 @@
log.debug("%s" % self.whitelist)
def put(self, setting, overwrite, uid=None):
- log.debug("%s: %s" % (setting.key, setting.value))
+ log.debug("Saving value in Gconf: %s=%s" % (setting.key, setting.value))
self._to_gconf(setting.key, setting.value)
- return setting.get_rid()
+ if uid == None:
+ uid = setting.key
+ return self.get(uid).get_rid()
def delete(self, uid):
self.gconf.unset(uid)
Modified: trunk/conduit/modules/TomboyModule.py
==============================================================================
--- trunk/conduit/modules/TomboyModule.py (original)
+++ trunk/conduit/modules/TomboyModule.py Wed Jan 16 12:50:06 2008
@@ -95,16 +95,11 @@
return False
def _update_note(self, uid, note):
- """
- @returns: A Rid for the note
- """
log.debug("Updating note uid: %s" % uid)
xmlContent = '<note-content version="0.1">%s\n%s</note-content>' % (note.get_title(), note.get_contents())
ok = self.remoteTomboy.SetNoteContentsXml(uid, xmlContent)
if not ok:
raise Exceptions.SyncronizeError("Error setting Tomboy note content (uri: %s)" % uid)
- n = self._get_note(uid)
- return n.get_rid()
def _get_note_mtime(self, uid):
try:
@@ -131,13 +126,10 @@
return n
def _create_note(self, note):
- """
- @returns: A Rid for the created note
- """
uid = self.remoteTomboy.CreateNamedNote(note.get_title())
- #fill out the note content
- rid = self._update_note(str(uid), note)
- return rid
+ uid = str(uid)
+ self._update_note(uid, note)
+ return uid
def initialize(self):
"""
@@ -185,17 +177,16 @@
log.debug("Comparing new %s with existing %s" % (note.get_title(),existingNote.get_title()))
if comp == conduit.datatypes.COMPARISON_EQUAL:
log.info("Notes are equal")
- rid = existingNote.get_rid()
elif overwrite == True or comp == conduit.datatypes.COMPARISON_NEWER:
log.info("Updating note")
- rid = self._update_note(LUID, note)
+ self._update_note(LUID, note)
else:
raise Exceptions.SynchronizeConflictError(comp, existingNote, note)
else:
log.info("Saving new Note")
- rid = self._create_note(note)
+ LUID = self._create_note(note)
- return rid
+ return self.get(LUID).get_rid()
def delete(self, LUID):
if self.remoteTomboy.NoteExists(LUID):
Modified: trunk/test/python-tests/TestDataProviderBoxDotNet.py
==============================================================================
--- trunk/test/python-tests/TestDataProviderBoxDotNet.py (original)
+++ trunk/test/python-tests/TestDataProviderBoxDotNet.py Wed Jan 16 12:50:06 2008
@@ -1,6 +1,8 @@
#common sets up the conduit environment
from common import *
+import traceback
+
import conduit.Utils as Utils
import conduit.datatypes.File as File
@@ -8,48 +10,37 @@
skip()
#A Reliable file that will note be deleted
-SAFE_FILENAME="conduit-icon.png"
-SAFE_FILEID=u'75007045'
+SAFE_FILENAME="conduit.png"
+SAFE_FILEID=u'124531811'
SAFE_FOLDER="Test"
#setup the test
-test = SimpleTest(sourceName="BoxDotNetTwoWay")
-
+test = SimpleTest(sinkName="BoxDotNetTwoWay")
boxconfig = {
"foldername":"Test"
}
-test.configure(source=boxconfig)
+test.configure(sink=boxconfig)
#get the module directly so we can call some special functions on it
-boxdotnet = test.get_source().module
+boxdotnet = test.get_sink().module
-#login
-boxdotnet._login()
-ok("Login OK", boxdotnet.token != None)
+#Log in
+try:
+ boxdotnet.refresh()
+ ok("Logged in", boxdotnet.token != None)
+except Exception, err:
+ ok("Logged in (%s)" % err, False)
#get the safe folder
folders = boxdotnet._get_folders()
ok("Got expected folder %s" % SAFE_FOLDER, SAFE_FOLDER in folders)
-#get the safe file
-files = boxdotnet.refresh()
-files = boxdotnet.get_all()
-ok("Got expected file %s" % SAFE_FILENAME, SAFE_FILEID in files)
-
-#transfer the file to the local disk
-tmpdir = Utils.new_tempdir()
-f = boxdotnet.get(SAFE_FILEID)
-f.transfer(tmpdir)
-ok("Transferred file to %s" % tmpdir, f.exists())
-ok("Filename retained in transfer", f.get_filename() == SAFE_FILENAME)
-
-#Send a remote file
-f = File.File("http://files.conduit-project.org/screenshot.png")
-try:
- uid = boxdotnet.put(f, True)
- ok("Upload a file (UID:%s) " % uid, True)
-except Exception, err:
- ok("Upload a file (%s)" % err, False)
+#Perform basic tests
+test.do_dataprovider_tests(
+ supportsGet=True,
+ supportsDelete=True,
+ safeLUID=SAFE_FILEID
+ )
finished()
Modified: trunk/test/python-tests/common.py
==============================================================================
--- trunk/test/python-tests/common.py (original)
+++ trunk/test/python-tests/common.py Wed Jan 16 12:50:06 2008
@@ -329,43 +329,37 @@
def print_mapping_db(self):
print conduit.GLOBALS.mappingDB.debug()
-
- def do_image_dataprovider_tests(self, supportsGet, supportsDelete, safePhotoLUID, ext="png"):
+
+ def do_dataprovider_tests(self, supportsGet, supportsDelete, safeLUID, ext="png", name="file"):
"""
- Tests get(), put(), delete() and Image dataprovider specific
- functions
+ Tests get(), put(), delete()
"""
- #Test get() and image specific friends
+ #Test get()
if supportsGet:
try:
- info = self.sink.module._get_photo_info(safePhotoLUID)
- ok("Got photo info", info != None)
- url = self.sink.module._get_raw_photo_url(info)
- ok("Got photo url (%s)" % url, url != None)
- ok("Photo url is correct", Vfs.uri_exists(url))
- f = self.sink.module.get(safePhotoLUID)
- ok ("Got photo %s" % url, f.exists())
+ f = self.sink.module.get(safeLUID)
+ ok("Got %s %s" % (name,safeLUID), f.exists())
except Exception, err:
traceback.print_exc()
- ok("Got photo (%s)" % err, False)
+ ok("Got %s (%s)" % (name,err), False)
#Test put()
f = File.File("http://files.conduit-project.org/screenshot.%s" % ext)
try:
rid = self.sink.module.put(f, True)
uid = rid.get_UID()
- ok("Upload a photo (%s) " % rid, True)
+ ok("Upload a %s (%s) " % (name,rid), True)
except Exception, err:
traceback.print_exc()
- ok("Upload a photo (%s)" % err, False)
+ ok("Upload a %s (%s)" % (name,err), False)
- #Test put() to replace a photo
+ #Test put() to replace
try:
rid = self.sink.module.put(f, True, uid)
- ok("Update a photo (%s)" % rid, True)
+ ok("Update a %s (%s)" % (name,rid), True)
except Exception, err:
traceback.print_exc()
- ok("Update a photo (%s)" % err, False)
+ ok("Update a %s (%s)" % (name,err), False)
#Test delete()
if supportsDelete:
@@ -373,10 +367,34 @@
self.sink.module.refresh()
self.sink.module.delete(uid)
self.sink.module.refresh()
- ok("Delete a photo (%s)" % rid, uid not in self.sink.module.get_all())
+ ok("Delete a %s (%s)" % (name,rid), uid not in self.sink.module.get_all())
except Exception, err:
traceback.print_exc()
- ok("Delete a photo (%s)" % err, False)
+ ok("Delete a %s (%s)" % (name,err), False)
+
+ def do_image_dataprovider_tests(self, supportsGet, supportsDelete, safePhotoLUID, ext="png"):
+ """
+ Tests get(), put(), delete() and Image dataprovider specific
+ functions
+ """
+ #Test get() and image specific friends
+ if supportsGet:
+ try:
+ info = self.sink.module._get_photo_info(safePhotoLUID)
+ ok("Got photo info", info != None)
+ url = self.sink.module._get_raw_photo_url(info)
+ ok("Got photo url (%s)" % url, url != None and Vfs.uri_exists(url))
+ except Exception, err:
+ traceback.print_exc()
+ ok("Got photo info/url (%s)" % err, False)
+
+ self.do_dataprovider_tests(
+ supportsGet,
+ supportsDelete,
+ safePhotoLUID,
+ ext,
+ "photo"
+ )
class SimpleSyncTest(SimpleTest):
"""
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]