conduit r1687 - in trunk: . conduit conduit/datatypes test/python-tests



Author: jstowers
Date: Fri Aug 29 23:36:30 2008
New Revision: 1687
URL: http://svn.gnome.org/viewvc/conduit?rev=1687&view=rev

Log:
	* conduit/Main.py:
	* conduit/Settings.py:
	* conduit/__init__.py:
	* conduit/datatypes/File.py:
	* test/python-tests/common.py: Adjusted the manner in which the
	settings and file implementations can be changed at run (and test) time.


Modified:
   trunk/   (props changed)
   trunk/ChangeLog
   trunk/conduit/Main.py
   trunk/conduit/Settings.py
   trunk/conduit/__init__.py
   trunk/conduit/datatypes/File.py
   trunk/test/python-tests/common.py

Modified: trunk/conduit/Main.py
==============================================================================
--- trunk/conduit/Main.py	(original)
+++ trunk/conduit/Main.py	Fri Aug 29 23:36:30 2008
@@ -48,7 +48,7 @@
         self.dbFile = os.path.join(conduit.USER_DIR, "mapping.db")
 
         #initialize application settings
-        conduit.GLOBALS.settings = Settings(conduit.SETTINGS_IMPL)
+        conduit.GLOBALS.settings = Settings()
 
         buildGUI = True
         iconify = False

Modified: trunk/conduit/Settings.py
==============================================================================
--- trunk/conduit/Settings.py	(original)
+++ trunk/conduit/Settings.py	Fri Aug 29 23:36:30 2008
@@ -7,6 +7,7 @@
 License: GPLv2
 """
 import gobject
+import conduit
 
 #these dicts are used for mapping config setting types to type names
 #and back again (isnt python cool...)
@@ -81,16 +82,22 @@
         'web_login_browser'         :   "gtkmozembed"   #When loggin into websites use: "system","gtkmozembed","webkit","gtkhtml"
     }
         
-    def __init__(self, implName):
+    def __init__(self, **kwargs):
         gobject.GObject.__init__(self)
+        
+        #you can override the settings implementation at runtime
+        #for testing purposes only
+        implName = kwargs.get("implName", conduit.SETTINGS_IMPL)
         if implName == "GConf":
-            from conduit.platform.SettingsGConf import SettingsImpl            
+            import conduit.platform.SettingsGConf as SettingsImpl
+        elif implName == "Python":
+            import conduit.platform.SettingsPython as SettingsImpl
         else:
-            from conduit.platform.SettingsPython import SettingsImpl
+            raise Exception("Settings Implementation %s Not Supported" % implName)
 
-        self._impl = SettingsImpl(
-                        defaults=self.DEFAULTS,
-                        changedCb=self._key_changed)
+        self._settings = SettingsImpl.SettingsImpl(
+                                defaults=self.DEFAULTS,
+                                changedCb=self._key_changed)
         
     def _key_changed(self, key):
         self.emit('changed::%s' % key)
@@ -100,20 +107,20 @@
         Sets values of settings that only exist for this setting, and are
         never saved, nor updated.
         """
-        self._impl.set_overrides(**overrides)
+        self._settings.set_overrides(**overrides)
 
     def get(self, key, **kwargs):
         """
         Returns the value of the key or the default value if the key is 
         not yet stored
         """
-        return self._impl.get(key, **kwargs)
+        return self._settings.get(key, **kwargs)
 
     def set(self, key, value, **kwargs):
         """
         Sets the key to value.
         """
-        return self._impl.set(key, value, **kwargs)
+        return self._settings.set(key, value, **kwargs)
         
     def proxy_enabled(self):
         """
@@ -121,7 +128,7 @@
         the http_proxy environment variable, or in the appropriate settings
         backend, such as gconf
         """
-        return self._impl.proxy_enabled()
+        return self._settings.proxy_enabled()
         
     def get_proxy(self):
         """
@@ -129,12 +136,12 @@
         The http_proxy environment variable overrides the GNOME setting
         @returns: host,port,user,password
         """
-        return self._impl.get_proxy()
+        return self._settings.get_proxy()
 
     def save(self):
         """
         Performs any necessary tasks to ensure settings are saved between sessions
         """
-        self._impl.save()
+        self._settings.save()
 
 

Modified: trunk/conduit/__init__.py
==============================================================================
--- trunk/conduit/__init__.py	(original)
+++ trunk/conduit/__init__.py	Fri Aug 29 23:36:30 2008
@@ -53,6 +53,7 @@
     GLADE_FILE =                os.path.join(DIRECTORY, "data","conduit.glade")
     SHARED_MODULE_DIR =         os.path.join(DIRECTORY, "conduit", "modules")
     SETTINGS_IMPL =             "GConf"
+    FILE_IMPL =                 "GnomeVfs"
 
 import Globals
 GLOBALS = Globals.Globals()

Modified: trunk/conduit/datatypes/File.py
==============================================================================
--- trunk/conduit/datatypes/File.py	(original)
+++ trunk/conduit/datatypes/File.py	Fri Aug 29 23:36:30 2008
@@ -1,3 +1,4 @@
+import sys
 import os
 import tempfile
 import datetime
@@ -9,8 +10,6 @@
 import conduit.datatypes.DataType as DataType
 import conduit.Vfs as Vfs
 
-from conduit.platform.FileGnomeVfs import FileImpl, FileTransferImpl
-
 class FileTransferError(Exception):
     pass
 
@@ -29,8 +28,21 @@
           - group: A named group to which this file belongs
         """
         DataType.DataType.__init__(self)
-        self._file = FileImpl(URI)
-
+        
+        #you can override the file implmentation at runtime
+        #for testing purposes only
+        implName = kwargs.get("implName", conduit.FILE_IMPL)
+        if implName == "GnomeVfs":
+            import conduit.platform.FileGnomeVfs as FileImpl
+            self.FileImpl = FileImpl
+        elif implName == "GIO":
+            import conduit.platform.FileGio as FileImpl
+            self.FileImpl = FileImpl
+        else:
+            raise Exception("File Implementation %s Not Supported" % implName)
+            
+        self._file = self.FileImpl.FileImpl(URI)
+        
         #optional args
         self.basePath = kwargs.get("basepath","")
         self.group = kwargs.get("group","")
@@ -204,9 +216,9 @@
 
         @type newURIString: C{string}
         """
-        trans = FileTransferImpl(
-                        source=self._file,
-                        dest=newURIString)
+        trans = self.FileImpl.FileTransferImpl(
+                                source=self._file,
+                                dest=newURIString)
         
         #the default cancel function just checks conduit.GLOBALS.cancelled
         if cancel_function == None:
@@ -404,7 +416,7 @@
         os.write(fd, data['data'])
         os.close(fd)
         
-        self._file = FileImpl(name)
+        self._file = FileImpl.FileImpl(name)
         self.basePath = data['basePath']
         self.group = data['group']
         self._defer_rename(data['filename'])

Modified: trunk/test/python-tests/common.py
==============================================================================
--- trunk/test/python-tests/common.py	(original)
+++ trunk/test/python-tests/common.py	Fri Aug 29 23:36:30 2008
@@ -41,7 +41,7 @@
 
 # override some conduit settings. 
 # without a gobject main loop the gtkmozembed browser hangs
-conduit.GLOBALS.settings = Settings.Settings(conduit.SETTINGS_IMPL)
+conduit.GLOBALS.settings = Settings.Settings()
 conduit.GLOBALS.settings.set_overrides(web_login_browser="system")
 
 def is_online():



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