conduit r1185 - in trunk: . conduit/modules/N800Module test/python-tests



Author: jstowers
Date: Thu Jan 10 22:29:14 2008
New Revision: 1185
URL: http://svn.gnome.org/viewvc/conduit?rev=1185&view=rev

Log:
N800 improvements and fix iPod tests

Added:
   trunk/conduit/modules/N800Module/__init__.py
   trunk/test/python-tests/TestDataProviderN800.py
Modified:
   trunk/ChangeLog
   trunk/conduit/modules/N800Module/N800Module.py
   trunk/test/python-tests/TestDataProvideriPod.py
   trunk/test/python-tests/common.py

Modified: trunk/conduit/modules/N800Module/N800Module.py
==============================================================================
--- trunk/conduit/modules/N800Module/N800Module.py	(original)
+++ trunk/conduit/modules/N800Module/N800Module.py	Thu Jan 10 22:29:14 2008
@@ -1,24 +1,22 @@
 """
 Provides a number of dataproviders which are associated with
-a N800 device.
+a N800 device. Allow the transcoding of music, photos and video before 
+transferring them to the n800
 
 Copyright 2007: Jaime Frutos Morales, John Stowers
 License: GPLv2
 """
-import os
 import os.path
 import logging
 log = logging.getLogger("modules.N800")
 
 import conduit
-import conduit.dataproviders.DataProvider as DataProvider
 import conduit.datatypes.Video as Video
 import conduit.datatypes.Audio as Audio
 import conduit.datatypes.Photo as Photo
 import conduit.dataproviders.VolumeFactory as VolumeFactory
 import conduit.dataproviders.DataProviderCategory as DataProviderCategory
 import conduit.dataproviders.File as FileDataProvider
-import conduit.Utils as Utils
 import conduit.Exceptions as Exceptions
 
 from gettext import gettext as _
@@ -51,19 +49,28 @@
     """
     TwoWay dataprovider for synchronizing a folder on a N800
     """
-    DEFAULT_GROUP = "N800"
-    DEFAULT_HIDDEN = False
-    DEFAULT_COMPARE_IGNORE_MTIME = False
+    
+    #Translators: Translate this in derived classes.
+    DEFAULT_FOLDER = _("Conduit")
+    #Translators: Format string used to describe the acceptable formats the 
+    #device accepts. The first arg is replaced with DEFAULT_FOLDER and the second
+    #arg is a comma seperated list of encodings
+    FORMAT_CONVERSION_STRING = _("%s Format (%s,unchanged)")
+
     def __init__(self, mount, udi, folder):
         FileDataProvider.FolderTwoWay.__init__(self,
                             folder,
-                            N800Base.DEFAULT_GROUP,
-                            N800Base.DEFAULT_HIDDEN,
-                            N800Base.DEFAULT_COMPARE_IGNORE_MTIME
+                            "N800",
+                            False,
+                            False
                             )
         self.need_configuration(False)
+        self.mount = mount
+        self.udi = udi
+        self.encodings =  {}
+        self.encoding = ""
 
-    def _simple_configure(self, window, encodings):
+    def configure(self, window):
         import gtk
         import conduit.gtkui.SimpleConfigurator as SimpleConfigurator
 
@@ -72,7 +79,7 @@
 
         items = [
                     {
-                    "Name" : "Format (%s,unchanged)" % ",".join(encodings),
+                    "Name" : self.FORMAT_CONVERSION_STRING % (self.DEFAULT_FOLDER, ",".join(self.encodings)),
                     "Widget" : gtk.Entry,
                     "Callback" : setEnc,
                     "InitialValue" : self.encoding
@@ -87,19 +94,19 @@
                 os.mkdir(self.folder)
             except OSError:
                 raise Exceptions.RefreshError("Error Creating Directory")
-
         FileDataProvider.FolderTwoWay.refresh(self)
-
+        
+    def get_input_conversion_args(self):
+        try:
+            return self.encodings[self.encoding]
+        except KeyError:
+            return {}
+            
     def get_configuration(self):
-        return {
-            "folder" : self.folder,
-            "folderGroupName" : self.folderGroupName,
-            "includeHidden" : self.includeHidden,
-            "compareIgnoreMtime" : self.compareIgnoreMtime
-            }
+        return {'encoding':self.encoding}
 
     def get_UID(self):
-        return "%s:%s" % (self.folder, self.folderGroupName)
+        return "%s" % self.udi
 
 class N800FolderTwoWay(N800Base):
     """
@@ -115,13 +122,16 @@
     DEFAULT_FOLDER = _("Backups")
 
     def __init__(self, *args):
-        mount,udi = args
         N800Base.__init__(
                     self,
-                    mount,
-                    udi,
-                    os.path.join(mount,N800FolderTwoWay.DEFAULT_FOLDER)
+                    mount=args[0],
+                    udi=args[1],
+                    folder=os.path.join(args[0],self.DEFAULT_FOLDER)
                     )
+                    
+    def configure(self, window):
+        #No need to configure encodings for Files
+        self.set_configured(True)                    
 
 class N800AudioTwoWay(N800Base):
     """
@@ -138,27 +148,15 @@
     DEFAULT_FOLDER = _("Music")
 
     def __init__(self, *args):
-        mount,udi = args
         N800Base.__init__(
                     self,
-                    mount,
-                    udi,
-                    os.path.join(mount,N800AudioTwoWay.DEFAULT_FOLDER)
+                    mount=args[0],
+                    udi=args[1],
+                    folder=os.path.join(args[0],self.DEFAULT_FOLDER)
                     )
+        self.encodings =  Audio.PRESET_ENCODINGS.copy()
         self.encoding = "ogg"
          
-    def configure(self, window):
-        self._simple_configure(window, Audio.PRESET_ENCODINGS.keys())
-
-    def get_configuration(self):
-        return {'encoding':self.encoding}
-        
-    def get_input_conversion_args(self):
-        try:
-            return Audio.PRESET_ENCODINGS[self.encoding]
-        except KeyError:
-            return {}
-
 class N800VideoTwoWay(N800Base):
     """
     TwoWay dataprovider for synchronizing a folder on a N800
@@ -174,27 +172,15 @@
     DEFAULT_FOLDER = _("Video")
 
     def __init__(self, *args):
-        mount,udi = args
         N800Base.__init__(
                     self,
-                    mount,
-                    udi,
-                    os.path.join(mount,N800VideoTwoWay.DEFAULT_FOLDER)
+                    mount=args[0],
+                    udi=args[1],
+                    folder=os.path.join(args[0],self.DEFAULT_FOLDER)
                     )
+        self.encodings =  Video.PRESET_ENCODINGS.copy()
         self.encoding = "ogg"
                     
-    def configure(self, window):
-        self._simple_configure(window, Video.PRESET_ENCODINGS.keys())
-        
-    def get_configuration(self):
-        return {'encoding':self.encoding}
-        
-    def get_input_conversion_args(self):
-        try:
-            return Video.PRESET_ENCODINGS[self.encoding]
-        except KeyError:
-            return {}
-        
 class N800PhotoTwoWay(N800Base):
     """
     TwoWay dataprovider for synchronizing a folder on a N800
@@ -209,30 +195,17 @@
     #To translators: default photos folder of N800
     DEFAULT_FOLDER = _("Photo")
 
-    PRESET_ENCODINGS = {
-        "jpeg":{'formats':'image/jpeg','default-format':'image/jpeg','size':'800x480'},
-        "png":{'formats':'image/png','default-format':'image/png','size':'800x480'}
-        }
-
     def __init__(self, *args):
-        mount,udi = args
         N800Base.__init__(
                     self,
-                    mount,
-                    udi,
-                    os.path.join(mount,N800PhotoTwoWay.DEFAULT_FOLDER)
+                    mount=args[0],
+                    udi=args[1],
+                    folder=os.path.join(args[0],self.DEFAULT_FOLDER)
                     )
-        self.encoding = "jpg"
+        self.encodings =  Photo.PRESET_ENCODINGS.copy()
+        #Add size = 800x480 to the default photo encodings
+        for k in self.encodings.keys():
+            self.encodings[k]['size'] = '800x480'
+        self.encoding = "jpeg"
                     
-    def configure(self, window):
-        self._simple_configure(window, N800PhotoTwoWay.PRESET_ENCODINGS.keys())
-        
-    def get_configuration(self):
-        return {'encoding':self.encoding}
-        
-    def get_input_conversion_args(self):
-        try:
-            return N800PhotoTwoWay.PRESET_ENCODINGS[self.encoding]
-        except KeyError:
-            return {}
 

Added: trunk/conduit/modules/N800Module/__init__.py
==============================================================================

Added: trunk/test/python-tests/TestDataProviderN800.py
==============================================================================
--- (empty file)
+++ trunk/test/python-tests/TestDataProviderN800.py	Thu Jan 10 22:29:14 2008
@@ -0,0 +1,59 @@
+#common sets up the conduit environment
+from common import *
+
+import traceback
+
+import conduit.modules.N800Module.N800Module as N800Module
+
+#simulate a n800
+fakeN800Dir = os.path.join(os.environ['TEST_DIRECTORY'],"n800")
+if not os.path.exists(fakeN800Dir):
+    os.mkdir(fakeN800Dir)
+ok("Created fake n800 at %s" % fakeN800Dir, os.path.exists(fakeN800Dir))
+
+n800FolderDp = N800Module.N800FolderTwoWay(fakeN800Dir,"")
+
+TESTS = (
+#dpinstance,        #newdata_func,          #name
+(n800FolderDp,      new_file,               "N800FolderTwoWay"),
+)
+
+for dp, newdata_func, name in TESTS:
+    try:
+        dp.refresh()
+        ok("%s: Refresh" % name, True)
+    except Exception, err:
+        ok("%s: Refresh (%s)" % (name,err), False) 
+
+    #Make data and put it
+    newdata = newdata_func(None)
+    newtitle = newdata.get_UID()
+        
+    try:
+        rid = dp.put(newdata,False)
+        ok("%s: Put %s" % (name, newtitle), rid.get_UID() != None)
+    except Exception, err:
+        traceback.print_exc()
+        ok("%s: Put %s" % (name, err), False)
+
+    #Check that we saved the note back
+    dp.refresh()
+    ok("%s: Got all (%s in %s)" % (name,rid.get_UID(),dp.get_all()), rid.get_UID() in dp.get_all())
+
+    data = dp.get(rid.get_UID())
+    comp = data.compare(newdata)
+    ok("%s: Got back idenitcal. Comparison %s" % (name, comp), comp == conduit.datatypes.COMPARISON_EQUAL, False)
+
+    #check we overwrite the data ok
+    try:
+        newrid = dp.put(newdata,True,rid.get_UID())
+        ok("%s: Overwrite %s" % (name, newtitle), newrid.get_UID() == rid.get_UID())
+    except Exception, err:
+        ok("%s: Overwrite %s" % (name, err), False)
+
+    #Check that we saved the data back
+    newdata = dp.get(newrid.get_UID())
+    comp = data.compare(newdata)
+    ok("%s: Got back idenitcal. Comparison %s" % (name, comp), comp == conduit.datatypes.COMPARISON_EQUAL, False)
+
+finished()

Modified: trunk/test/python-tests/TestDataProvideriPod.py
==============================================================================
--- trunk/test/python-tests/TestDataProvideriPod.py	(original)
+++ trunk/test/python-tests/TestDataProvideriPod.py	Thu Jan 10 22:29:14 2008
@@ -1,14 +1,11 @@
 #common sets up the conduit environment
 from common import *
 
-import datetime
 import traceback
 
-import conduit.datatypes.Note as Note
-import conduit.Utils as Utils
 import conduit.modules.iPodModule as iPodModule
 
-#grossness, simulate an ipod
+#simulate an ipod
 fakeIpodDir = os.path.join(os.environ['TEST_DIRECTORY'],"iPod")
 if not os.path.exists(fakeIpodDir):
     os.mkdir(fakeIpodDir)
@@ -18,45 +15,45 @@
 
 TESTS = (
 #dpinstance,        #newdata_func,          #name
-(ipodNoteDp,        new_note,               "note"),
+(ipodNoteDp,        new_note,               "IPodNoteTwoWay"),
 )
 
-for ipod, newdata_func, name in TESTS:
+for dp, newdata_func, name in TESTS:
     try:
-        ipod.refresh()
-        ok("iPod %s: Refresh" % name, True)
+        dp.refresh()
+        ok("%s: Refresh" % name, True)
     except Exception, err:
-        ok("iPod %s: Refresh (%s)" % (name,err), False) 
+        ok("%s: Refresh (%s)" % (name,err), False) 
 
-    #Make a note and save it
-    newnote = newdata_func("")
-    newtitle = newnote.get_UID()
+    #Make data and put it
+    newdata = newdata_func(None)
+    newtitle = newdata.get_UID()
         
     try:
-        rid = ipod.put(newnote,False)
-        ok("iPod %s: Put %s" % (name, newtitle), rid.get_UID() != None)
+        rid = dp.put(newdata,False)
+        ok("%s: Put %s" % (name, newtitle), rid.get_UID() != None)
     except Exception, err:
         traceback.print_exc()
-        ok("iPod %s: Put %s" % (name, err), False)
+        ok("%s: Put %s" % (name, err), False)
 
     #Check that we saved the note back
-    ipod.refresh()
-    ok("iPod %s: Got all" % name, rid.get_UID() in ipod.get_all())
+    dp.refresh()
+    ok("%s: Got all" % name, rid.get_UID() in dp.get_all())
 
-    note = ipod.get(rid.get_UID())
-    comp = note.compare(newnote)
-    ok("iPod %s: Got back idenitcal. Comparison %s" % (name, comp), comp == conduit.datatypes.COMPARISON_EQUAL, False)
+    data = dp.get(rid.get_UID())
+    comp = data.compare(newdata)
+    ok("%s: Got back idenitcal. Comparison %s" % (name, comp), comp == conduit.datatypes.COMPARISON_EQUAL, False)
 
-    #check we overwrite the note ok
+    #check we overwrite the data ok
     try:
-        newrid = ipod.put(newnote,True,rid.get_UID())
-        ok("iPod %s: Overwrite %s" % (name, newtitle), newrid.get_UID() == rid.get_UID())
+        newrid = dp.put(newdata,True,rid.get_UID())
+        ok("%s: Overwrite %s" % (name, newtitle), newrid.get_UID() == rid.get_UID())
     except Exception, err:
-        ok("iPod %s: Overwrite %s" % (name, err), False)
+        ok("%s: Overwrite %s" % (name, err), False)
 
-    #Check that we saved the note back
-    newnote = ipod.get(newrid.get_UID())
-    comp = note.compare(newnote)
-    ok("iPod %s: Got back idenitcal. Comparison %s" % (name, comp), comp == conduit.datatypes.COMPARISON_EQUAL, False)
+    #Check that we saved the data back
+    newdata = dp.get(newrid.get_UID())
+    comp = data.compare(newdata)
+    ok("%s: Got back idenitcal. Comparison %s" % (name, comp), comp == conduit.datatypes.COMPARISON_EQUAL, False)
 
 finished()

Modified: trunk/test/python-tests/common.py
==============================================================================
--- trunk/test/python-tests/common.py	(original)
+++ trunk/test/python-tests/common.py	Thu Jan 10 22:29:14 2008
@@ -104,12 +104,13 @@
 #Functions to construct new types
 def new_file(filename):
     if filename == None:
-        txt = Utils.random_string()
+        f = Utils.new_tempfile(Utils.random_string())
     else:
-        txt = read_data_file_from_data_dir(filename)
-    f = Utils.new_tempfile(txt)
-    f.set_UID(Utils.random_string())
-    f.set_open_URI(Utils.random_string())
+        files = get_files_from_data_dir(filename)
+        f = conduit.datatypes.File.File(URI=files[0])
+    uri = f._get_text_uri()
+    f.set_UID(uri)
+    f.set_open_URI(uri)
     return f
 
 def new_note(title):



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