[conduit] Remove unused conduit.platform.File abstraction
- From: John Stowers <jstowers src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [conduit] Remove unused conduit.platform.File abstraction
- Date: Wed, 22 Sep 2010 04:19:13 +0000 (UTC)
commit 22c2259ee7464cacd1a678d31e22c98714141271
Author: John Stowers <john stowers gmail com>
Date: Sat Jan 23 12:40:33 2010 +0100
Remove unused conduit.platform.File abstraction
* We support GIO only
conduit/Main.py | 2 +-
conduit/Makefile.am | 3 +-
conduit/Module.py | 2 +-
conduit/Vfs.py | 290 ----------
conduit/__init__.py | 2 -
conduit/dataproviders/File.py | 9 +-
conduit/datatypes/File.py | 38 +--
conduit/defs.py.in | 3 -
conduit/gtkui/ConfigItems.py | 2 +-
conduit/gtkui/ConflictResolver.py | 2 +-
conduit/modules/FileModule/FileConfiguration.py | 7 +-
conduit/modules/FileModule/FileModule.py | 8 +-
conduit/modules/N800Module/N800Module.py | 2 +-
.../PicasaDesktopModule/PicasaDesktopModule.py | 2 +-
conduit/platform/FilePython.py | 95 ----
conduit/platform/Makefile.am | 2 -
conduit/platform/__init__.py | 177 ------
conduit/{platform/FileGio.py => vfs/File.py} | 190 +++++---
conduit/vfs/Makefile.am | 8 +
conduit/vfs/Monitor.py | 79 +++
conduit/vfs/__init__.py | 204 +++++++
configure.ac | 21 +-
test/python-tests/TestCoreFile.py | 570 ++++++++++----------
test/python-tests/TestCoreFileCopyMany.py | 9 +-
test/python-tests/TestCoreVfs.py | 164 +++---
test/python-tests/TestDataProviderFolder.py | 2 +-
test/python-tests/TestDataProviderPicasa.py | 2 +-
test/python-tests/TestDataProviderSmugMug.py | 2 +-
test/python-tests/common.py | 6 +-
test/soup/test_synchronization.py | 1 -
30 files changed, 816 insertions(+), 1088 deletions(-)
---
diff --git a/conduit/Main.py b/conduit/Main.py
index 6d268d9..aa9f45a 100644
--- a/conduit/Main.py
+++ b/conduit/Main.py
@@ -125,7 +125,7 @@ class Application(dbus.service.Object):
log.info("Conduit v%s Installed: %s" % (conduit.VERSION, conduit.IS_INSTALLED))
log.info("Python: %s" % sys.version)
- log.info("Platform Implementations: %s,%s,%s" % (conduit.FILE_IMPL,conduit.BROWSER_IMPL, conduit.SETTINGS_IMPL))
+ log.info("Platform Implementations: %s,%s" % (conduit.BROWSER_IMPL, conduit.SETTINGS_IMPL))
if settings:
log.info("Settings have been overridden: %s" % settings)
diff --git a/conduit/Makefile.am b/conduit/Makefile.am
index 22d1c91..bc8c7cf 100644
--- a/conduit/Makefile.am
+++ b/conduit/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = datatypes dataproviders modules gtkui hildonui utils platform
+SUBDIRS = datatypes dataproviders modules gtkui hildonui utils platform vfs
conduitbindir = $(bindir)
conduitbin_SCRIPTS = \
@@ -28,7 +28,6 @@ conduit_PYTHON = \
Synchronization.py \
SyncSet.py \
TypeConverter.py \
- Vfs.py \
Web.py \
XMLSerialization.py
diff --git a/conduit/Module.py b/conduit/Module.py
index ba632f6..e04a234 100644
--- a/conduit/Module.py
+++ b/conduit/Module.py
@@ -15,7 +15,7 @@ log = logging.getLogger("Module")
import conduit.dataproviders
import conduit.ModuleWrapper as ModuleWrapper
import conduit.Knowledge as Knowledge
-import conduit.Vfs as Vfs
+import conduit.vfs as Vfs
from gettext import gettext as _
diff --git a/conduit/__init__.py b/conduit/__init__.py
index 0a66122..97276a7 100644
--- a/conduit/__init__.py
+++ b/conduit/__init__.py
@@ -50,8 +50,6 @@ else:
SHARED_DATA_DIR = os.path.join(DIRECTORY, "data")
SHARED_MODULE_DIR = os.path.join(DIRECTORY, "conduit", "modules")
DESKTOP_FILE_DIR = os.path.join(DIRECTORY, "data")
- #{GIO, Python}
- FILE_IMPL = os.environ.get("CONDUIT_FILE_IMPL","GIO")
#{gtkmozembed, webkit, system}
BROWSER_IMPL = os.environ.get("CONDUIT_BROWSER_IMPL","webkit")
#{GConf,Python}
diff --git a/conduit/dataproviders/File.py b/conduit/dataproviders/File.py
index bdc7381..6fcd1e3 100644
--- a/conduit/dataproviders/File.py
+++ b/conduit/dataproviders/File.py
@@ -7,7 +7,8 @@ import conduit
import conduit.dataproviders.DataProvider as DataProvider
import conduit.datatypes as DataType
import conduit.datatypes.File as File
-import conduit.Vfs as Vfs
+import conduit.vfs as Vfs
+import conduit.vfs.File as VfsFile
import conduit.Database as DB
import conduit.Exceptions as Exceptions
@@ -72,7 +73,7 @@ def read_removable_volume_group_file(folderUri):
items.append((p,n))
return items
-class FileSource(DataProvider.DataSource, Vfs.FolderScannerThreadManager):
+class FileSource(DataProvider.DataSource, VfsFile.FolderScannerThreadManager):
_category_ = conduit.dataproviders.CATEGORY_FILES
_module_type_ = "source"
@@ -82,7 +83,7 @@ class FileSource(DataProvider.DataSource, Vfs.FolderScannerThreadManager):
def __init__(self):
DataProvider.DataSource.__init__(self)
- Vfs.FolderScannerThreadManager.__init__(self)
+ VfsFile.FolderScannerThreadManager.__init__(self)
#One table stores the top level files and folders (config)
#The other stores all files to sync.
@@ -253,7 +254,7 @@ class FolderTwoWay(DataProvider.TwoWay):
self.fstype = Vfs.uri_get_filesystem_type(self.folder)
#scan the folder
- scanThread = Vfs.FolderScanner(self.folder, self.includeHidden, self.followSymlinks)
+ scanThread = VfsFile.FolderScanner(self.folder, self.includeHidden, self.followSymlinks)
scanThread.start()
scanThread.join()
self.files = scanThread.get_uris()
diff --git a/conduit/datatypes/File.py b/conduit/datatypes/File.py
index 80580ab..770ab01 100644
--- a/conduit/datatypes/File.py
+++ b/conduit/datatypes/File.py
@@ -8,7 +8,9 @@ log = logging.getLogger("datatypes.File")
import conduit
import conduit.datatypes.DataType as DataType
-import conduit.Vfs as Vfs
+import conduit.vfs as Vfs
+import conduit.vfs.File as VfsFile
+
class FileTransferError(Exception):
pass
@@ -28,20 +30,8 @@ class File(DataType.DataType):
- group: A named group to which this file belongs
"""
DataType.DataType.__init__(self)
-
- #you can override the file implmentation at runtime
- #for testing purposes only
- implName = kwargs.get("implName", conduit.FILE_IMPL)
- if implName == "GIO":
- import conduit.platform.FileGio as FileImpl
- self.FileImpl = FileImpl
- elif implName == "Python":
- import conduit.platform.FilePython as FileImpl
- self.FileImpl = FileImpl
- else:
- raise Exception("File Implementation %s Not Supported" % implName)
-
- self._file = self.FileImpl.FileImpl(URI)
+
+ self._file = VfsFile.File(URI)
#optional args
self.basePath = kwargs.get("basepath","")
@@ -126,9 +116,6 @@ class File(DataType.DataType):
else:
return olduri
- def _get_impl(self):
- return self._file
-
def set_from_instance(self, f):
"""
Function to give this file all the properties of the
@@ -232,7 +219,7 @@ class File(DataType.DataType):
@type newURIString: C{string}
"""
- trans = self.FileImpl.FileTransferImpl(
+ trans = VfsFile.FileTransfer(
source=self._file,
dest=newURIString)
@@ -442,18 +429,7 @@ class File(DataType.DataType):
fd, name = tempfile.mkstemp(prefix="netsync")
os.write(fd, data['data'])
os.close(fd)
-
- implName = conduit.FILE_IMPL
- if implName == "GIO":
- import conduit.platform.FileGio as FileImpl
- self.FileImpl = FileImpl
- elif implName == "Python":
- import conduit.platform.FilePython as FileImpl
- self.FileImpl = FileImpl
- else:
- raise Exception("File Implementation %s Not Supported" % implName)
-
- self._file = self.FileImpl.FileImpl(name)
+ self._file = VfsFile.File(name)
self.basePath = data['basePath']
self.group = data['group']
self._defer_rename(data['filename'])
diff --git a/conduit/defs.py.in b/conduit/defs.py.in
index d5fe67a..c7f7b31 100644
--- a/conduit/defs.py.in
+++ b/conduit/defs.py.in
@@ -11,9 +11,6 @@ DESKTOP_FILE_DIR = "@DESKTOPFILEDIR@"
# Platform specific implementations
#
-#{GIO, Python}
-FILE_IMPL = "@FILE_IMPL@"
-
#{gtkmozembed, webkit, system}
BROWSER_IMPL = "@BROWSER_IMPL@"
diff --git a/conduit/gtkui/ConfigItems.py b/conduit/gtkui/ConfigItems.py
index d7c5a55..50bd2d8 100644
--- a/conduit/gtkui/ConfigItems.py
+++ b/conduit/gtkui/ConfigItems.py
@@ -13,7 +13,7 @@ log = logging.getLogger("gtkui.Config")
from gettext import gettext as _
-import conduit.Vfs as Vfs
+import conduit.vfs as Vfs
class Error(Exception):
"""Base exception for all exceptions raised in this module."""
diff --git a/conduit/gtkui/ConflictResolver.py b/conduit/gtkui/ConflictResolver.py
index 119a02d..67e372b 100644
--- a/conduit/gtkui/ConflictResolver.py
+++ b/conduit/gtkui/ConflictResolver.py
@@ -14,7 +14,7 @@ log = logging.getLogger("gtkui.ConflictResolver")
import conduit
import conduit.dataproviders.DataProvider as DataProvider
-import conduit.Vfs as Vfs
+import conduit.vfs as Vfs
import conduit.Conflict as Conflict
from gettext import gettext as _
diff --git a/conduit/modules/FileModule/FileConfiguration.py b/conduit/modules/FileModule/FileConfiguration.py
index 3407afa..30817db 100644
--- a/conduit/modules/FileModule/FileConfiguration.py
+++ b/conduit/modules/FileModule/FileConfiguration.py
@@ -5,7 +5,8 @@ import logging
log = logging.getLogger("modules.File")
import conduit
-import conduit.Vfs as Vfs
+import conduit.vfs as Vfs
+import conduit.vfs.File as VfsFile
import conduit.gtkui.Database as Database
import conduit.dataproviders.File as FileDataProvider
import conduit.Configurator as Configurator
@@ -18,7 +19,7 @@ CONTAINS_NUM_ITEMS_IDX = 3 #(folder only) How many items in the folder
SCAN_COMPLETE_IDX = 4 #(folder only) HAs the folder been recursively scanned
GROUP_NAME_IDX = 5 #(folder only) The visible identifier for the folder
-class _FileSourceConfigurator(Vfs.FolderScannerThreadManager, Configurator.BaseConfigContainer):
+class _FileSourceConfigurator(VfsFile.FolderScannerThreadManager, Configurator.BaseConfigContainer):
"""
Configuration dialog for the FileTwoway dataprovider
"""
@@ -30,7 +31,7 @@ class _FileSourceConfigurator(Vfs.FolderScannerThreadManager, Configurator.BaseC
pass
def __init__(self, dataprovider, configurator, db):
- Vfs.FolderScannerThreadManager.__init__(self)
+ VfsFile.FolderScannerThreadManager.__init__(self)
Configurator.BaseConfigContainer.__init__(self, dataprovider, configurator)
self.db = db
self.tree_model = Database.GenericDBListStore("config", self.db)
diff --git a/conduit/modules/FileModule/FileModule.py b/conduit/modules/FileModule/FileModule.py
index e22ffe7..b6f7d42 100644
--- a/conduit/modules/FileModule/FileModule.py
+++ b/conduit/modules/FileModule/FileModule.py
@@ -10,7 +10,9 @@ import conduit.dataproviders.File as FileDataProvider
import conduit.dataproviders.SimpleFactory as SimpleFactory
import conduit.dataproviders.AutoSync as AutoSync
import conduit.utils as Utils
-import conduit.Vfs as Vfs
+import conduit.vfs as Vfs
+import conduit.vfs.File as VfsFile
+import conduit.vfs.Monitor as VfsMonitor
MODULES = {
"FileSource" : { "type": "dataprovider" },
@@ -105,7 +107,7 @@ class FolderTwoWay(FileDataProvider.FolderTwoWay, AutoSync.AutoSync):
)
AutoSync.AutoSync.__init__(self)
- self._monitor = Vfs.FileMonitor()
+ self._monitor = VfsMonitor.FileMonitor()
self._monitor.connect("changed", self._monitor_folder_cb)
self.update_configuration(
@@ -157,7 +159,7 @@ class RemovableDeviceFactory(SimpleFactory.SimpleFactory):
SimpleFactory.SimpleFactory.__init__(self, **kwargs)
self._volumes = {}
self._categories = {}
- self._vm = Vfs.VolumeMonitor()
+ self._vm = VfsMonitor.VolumeMonitor()
self._vm.connect("volume-mounted",self._volume_mounted_cb)
self._vm.connect("volume-unmounted",self._volume_unmounted_cb)
diff --git a/conduit/modules/N800Module/N800Module.py b/conduit/modules/N800Module/N800Module.py
index f772e98..036dc6b 100644
--- a/conduit/modules/N800Module/N800Module.py
+++ b/conduit/modules/N800Module/N800Module.py
@@ -18,7 +18,7 @@ import conduit.dataproviders.VolumeFactory as VolumeFactory
import conduit.dataproviders.DataProviderCategory as DataProviderCategory
import conduit.dataproviders.File as FileDataProvider
import conduit.Exceptions as Exceptions
-import conduit.Vfs as Vfs
+import conduit.vfs as Vfs
from gettext import gettext as _
diff --git a/conduit/modules/UNSUPPORTED/PicasaDesktopModule/PicasaDesktopModule.py b/conduit/modules/UNSUPPORTED/PicasaDesktopModule/PicasaDesktopModule.py
index a8e74ac..b65f341 100644
--- a/conduit/modules/UNSUPPORTED/PicasaDesktopModule/PicasaDesktopModule.py
+++ b/conduit/modules/UNSUPPORTED/PicasaDesktopModule/PicasaDesktopModule.py
@@ -6,7 +6,7 @@ log = logging.getLogger("modules.Picasa")
import conduit
import conduit.utils as Utils
-import conduit.Vfs as Vfs
+import conduit.vfs as Vfs
import conduit.Exceptions as Exceptions
import conduit.dataproviders.DataProvider as DataProvider
import conduit.datatypes.Photo as Photo
diff --git a/conduit/platform/Makefile.am b/conduit/platform/Makefile.am
index 4891035..ddb653b 100644
--- a/conduit/platform/Makefile.am
+++ b/conduit/platform/Makefile.am
@@ -1,8 +1,6 @@
conduitdir = $(pythondir)/conduit/platform
conduit_PYTHON = \
__init__.py \
- FileGio.py \
- FilePython.py \
SettingsGConf.py \
SettingsPython.py \
WebBrowserWebkit.py \
diff --git a/conduit/platform/__init__.py b/conduit/platform/__init__.py
index 6851f0f..b4acca8 100644
--- a/conduit/platform/__init__.py
+++ b/conduit/platform/__init__.py
@@ -1,182 +1,5 @@
-import threading
import gobject
-class File:
- SCHEMES = ()
- NAME = None
- def __init__(self, URI):
- pass
-
- def get_text_uri(self):
- raise NotImplementedError
-
- def get_local_path(self):
- raise NotImplementedError
-
- def is_local(self):
- raise NotImplementedError
-
- def is_directory(self):
- raise NotImplementedError
-
- def delete(self):
- raise NotImplementedError
-
- def exists(self):
- raise NotImplementedError
-
- def set_mtime(self, timestamp=None, datetime=None):
- raise NotImplementedError
-
- def set_filename(self, filename):
- raise NotImplementedError
-
- def get_mtime(self):
- raise NotImplementedError
-
- def get_filename(self):
- raise NotImplementedError
-
- def get_uri_for_display(self):
- raise NotImplementedError
-
- def get_contents(self):
- raise NotImplementedError
-
- def set_contents(self, contents):
- raise NotImplementedError
-
- def get_mimetype(self):
- raise NotImplementedError
-
- def get_size(self):
- raise NotImplementedError
-
- def set_props(self, **props):
- pass
-
- def close(self):
- raise NotImplementedError
-
- def make_directory(self):
- raise NotImplementedError
-
- def make_directory_and_parents(self):
- raise NotImplementedError
-
- def is_on_removale_volume(self):
- return False
-
- def get_removable_volume_root_uri(self):
- return None
-
- def get_filesystem_type(self):
- return None
-
- @staticmethod
- def uri_join(first, *rest):
- raise NotImplementedError
-
- @staticmethod
- def uri_get_relative(fromURI, toURI):
- raise NotImplementedError
-
- @staticmethod
- def uri_get_scheme(URI):
- raise NotImplementedError
-
-class FileTransfer:
- def __init__(self, source, dest):
- pass
-
- def set_destination_filename(self, name):
- raise NotImplementedError
-
- def transfer(self, cancel_func):
- raise NotImplementedError
-
-class VolumeMonitor(gobject.GObject):
- __gsignals__ = {
- "volume-mounted" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [
- gobject.TYPE_STRING, #udi/uuid
- gobject.TYPE_STRING, #mount point
- gobject.TYPE_STRING]), #label
- "volume-unmounted" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [
- gobject.TYPE_STRING]) #udi/uuid
-
- }
- def __init__(self):
- gobject.GObject.__init__(self)
-
- def get_mounted_volumes(self):
- """
- @returs: Dict of mounted volumes, uuid : (mount, name)
- """
- return {}
-
-class FileMonitor(gobject.GObject):
-
- __gsignals__ = {
- "changed" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [
- gobject.TYPE_PYOBJECT, #uri that changed
- gobject.TYPE_PYOBJECT]) #event type
- }
-
- MONITOR_EVENT_CREATED = 1
- MONITOR_EVENT_CHANGED = 2
- MONITOR_EVENT_DELETED = 3
- MONITOR_DIRECTORY = 4
-
- def __init__(self):
- gobject.GObject.__init__(self)
-
- def add(self, folder, monitorType):
- pass
-
- def cancel(self):
- pass
-
-class FolderScanner(threading.Thread, gobject.GObject):
- """
- Recursively scans a given folder URI, returning the number of
- contained files.
- """
- __gsignals__ = {
- "scan-progress": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [
- gobject.TYPE_INT]),
- "scan-completed": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [])
- }
- CONFIG_FILE_NAME = ".conduit.conf"
- def __init__(self, baseURI, includeHidden, followSymlinks):
- threading.Thread.__init__(self)
- gobject.GObject.__init__(self)
- self.baseURI = str(baseURI)
- self.includeHidden = includeHidden
- self.followSymlinks = followSymlinks
- self.dirs = [self.baseURI]
- self.cancelled = False
- self.URIs = []
- self.setName("FolderScanner Thread: %s" % self.baseURI)
-
- def run(self):
- """
- Recursively adds all files in dirs within the given list.
-
- Code adapted from Listen (c) 2006 Mehdi Abaakouk
- (http://listengnome.free.fr/)
- """
- raise NotImplementedError
-
- def cancel(self):
- """
- Cancels the thread as soon as possible.
- """
- self.cancelled = True
-
- def get_uris(self):
- return self.URIs
-
-
class Settings:
def __init__(self, defaults, changedCb):
self._defaults = defaults
diff --git a/conduit/platform/FileGio.py b/conduit/vfs/File.py
similarity index 69%
rename from conduit/platform/FileGio.py
rename to conduit/vfs/File.py
index 8d81dd4..ecebbdd 100644
--- a/conduit/platform/FileGio.py
+++ b/conduit/vfs/File.py
@@ -1,13 +1,12 @@
import gio
-
-import conduit.platform
-
+import gobject
+import time
+import threading
import os.path
import logging
-log = logging.getLogger("platform.FileGio")
+log = logging.getLogger("vfs.File")
-class FileImpl(conduit.platform.File):
- SCHEMES = ("file://","http://","ftp://","smb://")
+class File:
NAME = "GIO"
def __init__(self, URI, impl=None):
if impl:
@@ -207,7 +206,7 @@ class FileImpl(conduit.platform.File):
f = gio.File(URI)
return f.get_uri_scheme()
-class FileTransferImpl(conduit.platform.FileTransfer):
+class FileTransfer:
def __init__(self, source, dest):
self._source = source._file
self._dest = gio.File(dest)
@@ -252,7 +251,7 @@ class FileTransferImpl(conduit.platform.FileTransfer):
parent.query_info("standard::name")
except gio.Error, e:
#does not exists
- d = FileImpl(None, impl=parent)
+ d = File(None, impl=parent)
d.make_directory_and_parents()
#Copy the file
@@ -263,68 +262,42 @@ class FileTransferImpl(conduit.platform.FileTransfer):
cancellable=self._cancellable,
progress_callback=self._xfer_progress_callback
)
- return ok, FileImpl(None, impl=self._dest)
+ return ok, File(None, impl=self._dest)
except gio.Error, e:
log.warn("File transfer error: %s" % e)
return False, None
-class VolumeMonitor(conduit.platform.VolumeMonitor):
-
- def __init__(self):
- conduit.platform.VolumeMonitor.__init__(self)
- self._vm = gio.volume_monitor_get()
- self._vm.connect("mount-added", self._mounted_cb)
- self._vm.connect("mount-removed", self._unmounted_cb)
-
- def _mounted_cb(self, sender, mount):
- self.emit("volume-mounted",
- mount.get_uuid(),
- mount.get_root().get_uri(),
- mount.get_name())
-
- def _unmounted_cb(self, sender, mount):
- self.emit("volume-unmounted", mount.get_uuid())
-
- def get_mounted_volumes(self):
- vols = {}
- for m in self._vm.get_mounts():
- vols[m.get_uuid()] = (m.get_root().get_uri(), m.get_name())
- return vols
-
-class FileMonitor(conduit.platform.FileMonitor):
+class FolderScanner(threading.Thread, gobject.GObject):
+ """
+ Recursively scans a given folder URI, returning the number of
+ contained files.
+ """
+
+ __gsignals__ = {
+ "scan-progress": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [
+ gobject.TYPE_INT]),
+ "scan-completed": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [])
+ }
+ CONFIG_FILE_NAME = ".conduit.conf"
+
+ def __init__(self, baseURI, includeHidden, followSymlinks):
+ threading.Thread.__init__(self)
+ gobject.GObject.__init__(self)
+ self.baseURI = str(baseURI)
+ self.includeHidden = includeHidden
+ self.followSymlinks = followSymlinks
+ self.dirs = [self.baseURI]
+ self.cancelled = False
+ self.URIs = []
+ self.setName("FolderScanner Thread: %s" % self.baseURI)
- MONITOR_EVENT_CREATED = gio.FILE_MONITOR_EVENT_CREATED
- MONITOR_EVENT_CHANGED = gio.FILE_MONITOR_EVENT_CHANGED
- MONITOR_EVENT_DELETED = gio.FILE_MONITOR_EVENT_DELETED
- MONITOR_DIRECTORY = 255
-
- def __init__(self):
- conduit.platform.FileMonitor.__init__(self)
- self._fm = None
-
- def _on_change(self, monitor, f1, f2, event):
- self.emit("changed", f1.get_uri(), event)
-
- def add(self, URI, monitorType):
- try:
- if monitorType == self.MONITOR_DIRECTORY:
- self._fm = gio.File(URI).monitor_directory()
- else:
- self._fm = gio.File(URI).monitor_file()
-
- self._fm.connect("changed", self._on_change)
- except gio.Error:
- log.warn("Could not add monitor", exc_info=True)
-
- def cancel(self):
- if self._fm:
- try:
- self._fm.disconnect_by_func(self._on_change)
- except TypeError:
- pass
-
-class FolderScanner(conduit.platform.FolderScanner):
def run(self):
+ """
+ Recursively adds all files in dirs within the given list.
+
+ Code adapted from Listen (c) 2006 Mehdi Abaakouk
+ (http://listengnome.free.fr/)
+ """
delta = 0
t = 1
last_estimated = estimated = 0
@@ -383,3 +356,92 @@ class FolderScanner(conduit.platform.FolderScanner):
log.debug("%s files loaded" % total)
self.emit("scan-completed")
+ def cancel(self):
+ """
+ Cancels the thread as soon as possible.
+ """
+ self.cancelled = True
+
+ def get_uris(self):
+ return self.URIs
+
+class FolderScannerThreadManager:
+ """
+ Manages many FolderScanner threads. This involves joining and cancelling
+ said threads, and respecting a maximum num of concurrent threads limit
+ """
+ def __init__(self, maxConcurrentThreads=2):
+ self.maxConcurrentThreads = maxConcurrentThreads
+ self.scanThreads = {}
+ self.pendingScanThreadsURIs = []
+
+ def make_thread(self, folderURI, includeHidden, followSymlinks, progressCb, completedCb, *args):
+ """
+ Makes a thread for scanning folderURI. The thread callsback the model
+ at regular intervals with the supplied args
+ """
+ running = len(self.scanThreads) - len(self.pendingScanThreadsURIs)
+
+ if folderURI not in self.scanThreads:
+ thread = FolderScanner(folderURI, includeHidden, followSymlinks)
+ thread.connect("scan-progress", progressCb, *args)
+ thread.connect("scan-completed", completedCb, *args)
+ thread.connect("scan-completed", self._register_thread_completed, folderURI)
+ self.scanThreads[folderURI] = thread
+ if running < self.maxConcurrentThreads:
+ log.debug("Starting thread %s" % folderURI)
+ self.scanThreads[folderURI].start()
+ else:
+ self.pendingScanThreadsURIs.append(folderURI)
+ return thread
+ else:
+ return self.scanThreads[folderURI]
+
+ def _register_thread_completed(self, sender, folderURI):
+ """
+ Decrements the count of concurrent threads and starts any
+ pending threads if there is space
+ """
+ #delete the old thread
+ del(self.scanThreads[folderURI])
+ running = len(self.scanThreads) - len(self.pendingScanThreadsURIs)
+
+ log.debug("Thread %s completed. %s running, %s pending" % (folderURI, running, len(self.pendingScanThreadsURIs)))
+
+ if running < self.maxConcurrentThreads:
+ try:
+ uri = self.pendingScanThreadsURIs.pop()
+ log.debug("Starting pending thread %s" % uri)
+ self.scanThreads[uri].start()
+ except IndexError: pass
+
+ def join_all_threads(self):
+ """
+ Joins all threads (blocks)
+
+ Unfortunately we join all the threads do it in a loop to account
+ for join() a non started thread failing. To compensate I time.sleep()
+ to not smoke CPU
+ """
+ joinedThreads = 0
+ while(joinedThreads < len(self.scanThreads)):
+ for thread in self.scanThreads.values():
+ try:
+ thread.join()
+ joinedThreads += 1
+ except (RuntimeError, AssertionError):
+ #deal with not started threads
+ time.sleep(0.1)
+
+ def cancel_all_threads(self):
+ """
+ Cancels all threads ASAP. My block for a small period of time
+ because we use our own cancel method
+ """
+ for thread in self.scanThreads.values():
+ if thread.isAlive():
+ log.debug("Cancelling thread %s" % thread)
+ thread.cancel()
+ thread.join() #May block
+
+
diff --git a/conduit/vfs/Makefile.am b/conduit/vfs/Makefile.am
new file mode 100644
index 0000000..05978e6
--- /dev/null
+++ b/conduit/vfs/Makefile.am
@@ -0,0 +1,8 @@
+conduitdir = $(pythondir)/conduit/vfs
+conduit_PYTHON = \
+ __init__.py \
+ File.py \
+ Monitor.py
+
+clean-local:
+ rm -rf *.pyc *.pyo
diff --git a/conduit/vfs/Monitor.py b/conduit/vfs/Monitor.py
new file mode 100644
index 0000000..66cf649
--- /dev/null
+++ b/conduit/vfs/Monitor.py
@@ -0,0 +1,79 @@
+import gio
+import gobject
+import logging
+log = logging.getLogger("vfs.FileMonitor")
+
+class FileMonitor(gobject.GObject):
+
+ __gsignals__ = {
+ "changed" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [
+ gobject.TYPE_PYOBJECT, #uri that changed
+ gobject.TYPE_PYOBJECT]) #event type
+ }
+
+ MONITOR_EVENT_CREATED = gio.FILE_MONITOR_EVENT_CREATED
+ MONITOR_EVENT_CHANGED = gio.FILE_MONITOR_EVENT_CHANGED
+ MONITOR_EVENT_DELETED = gio.FILE_MONITOR_EVENT_DELETED
+ MONITOR_DIRECTORY = 255
+
+ def __init__(self):
+ gobject.GObject.__init__(self)
+ self._fm = None
+
+ def _on_change(self, monitor, f1, f2, event):
+ self.emit("changed", f1.get_uri(), event)
+
+ def add(self, URI, monitorType):
+ try:
+ if monitorType == self.MONITOR_DIRECTORY:
+ self._fm = gio.File(URI).monitor_directory()
+ else:
+ self._fm = gio.File(URI).monitor_file()
+
+ self._fm.connect("changed", self._on_change)
+ except gio.Error:
+ log.warn("Could not add monitor", exc_info=True)
+
+ def cancel(self):
+ if self._fm:
+ try:
+ self._fm.disconnect_by_func(self._on_change)
+ except TypeError:
+ pass
+
+class VolumeMonitor(gobject.GObject):
+
+ __gsignals__ = {
+ "volume-mounted" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [
+ gobject.TYPE_STRING, #udi/uuid
+ gobject.TYPE_STRING, #mount point
+ gobject.TYPE_STRING]), #label
+ "volume-unmounted" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [
+ gobject.TYPE_STRING]) #udi/uuid
+
+ }
+
+ def __init__(self):
+ gobject.GObject.__init__(self)
+ self._vm = gio.volume_monitor_get()
+ self._vm.connect("mount-added", self._mounted_cb)
+ self._vm.connect("mount-removed", self._unmounted_cb)
+
+ def _mounted_cb(self, sender, mount):
+ self.emit("volume-mounted",
+ mount.get_uuid(),
+ mount.get_root().get_uri(),
+ mount.get_name())
+
+ def _unmounted_cb(self, sender, mount):
+ self.emit("volume-unmounted", mount.get_uuid())
+
+ def get_mounted_volumes(self):
+ """
+ @returs: Dict of mounted volumes, uuid : (mount, name)
+ """
+ vols = {}
+ for m in self._vm.get_mounts():
+ vols[m.get_uuid()] = (m.get_root().get_uri(), m.get_name())
+ return vols
+
diff --git a/conduit/vfs/__init__.py b/conduit/vfs/__init__.py
new file mode 100644
index 0000000..2ce63fd
--- /dev/null
+++ b/conduit/vfs/__init__.py
@@ -0,0 +1,204 @@
+import gobject
+import urllib
+import os.path
+import time
+
+import logging
+log = logging.getLogger("Vfs")
+
+import conduit
+import conduit.utils.Singleton as Singleton
+
+import File as File
+
+def backend_supports_remote_uri_schemes():
+ """
+ @returns: True if the file implementation supports non-local (file://)
+ uri schemes
+ """
+ return True
+
+def backend_name():
+ """
+ @returns: The name of the selected file impl backend
+ """
+ return "GIO"
+
+#FIXME: g_vfs_get_supported_uri_schemes needs to be wrapped
+def uri_is_valid(uri):
+ """
+ Checks if the uri is valid (i.e. not a local path), and its type
+ is supported by the underlying file implementation
+ """
+ SCHEMES = ("file://","http://","ftp://","smb://")
+
+ return uri[0] != "/" and uri.split("://")[0]+"://" in SCHEMES
+
+def uri_join(first, *rest):
+ """
+ Joins multiple uri components. Performs safely if the first
+ argument contains a uri scheme
+ """
+ return File.File.uri_join(first,*rest)
+
+def uri_get_scheme(uri):
+ """
+ @returns: The scheme (file,smb,ftp) for the uri, or None on error
+ """
+ return File.File.uri_get_scheme(uri)
+
+def uri_get_relative(fromURI, toURI):
+ """
+ Returns the relative path fromURI --> toURI
+ """
+ return File.File.uri_get_relative(fromURI, toURI)
+
+def uri_open(uri):
+ """
+ Opens a xdg compatible uri.
+ """
+ uri = conduit.utils.ensure_string(uri)
+ APP = "xdg-open"
+ os.spawnlp(os.P_NOWAIT, APP, APP, uri)
+
+def uri_to_local_path(uri):
+ """
+ @returns: The local path (/foo/bar) for the given URI
+ """
+ uri = conduit.utils.ensure_string(uri)
+ scheme = uri_get_scheme(uri)
+ if scheme == "file":
+ #len("file://") = 7
+ return uri[7:]
+ else:
+ return None
+
+def uri_get_volume_root_uri(uri):
+ """
+ @returns: The root path of the volume at the given uri, or None
+ """
+ f = File.File(uri)
+ return f.get_removable_volume_root_uri()
+
+def uri_is_on_removable_volume(uri):
+ """
+ @returns: True if the specified uri is on a removable volume, like a USB key
+ or removable/mountable disk.
+ """
+ f = File.File(uri)
+ return f.is_on_removale_volume()
+
+def uri_get_filesystem_type(uri):
+ """
+ @returns: The filesystem that uri is stored on or None if it cannot
+ be determined
+ """
+ f = File.File(uri)
+ return f.get_filesystem_type()
+
+def uri_escape(uri):
+ """
+ Escapes a uri, replacing only special characters that would not be found in
+ paths or host names.
+ (so '/', '&', '=', ':' and '@' will not be escaped by this function)
+ """
+ import urllib
+ uri = conduit.utils.ensure_string(uri)
+ return urllib.quote(uri,safe='/&=:@')
+
+def uri_unescape(uri):
+ """
+ Replace "%xx" escapes by their single-character equivalent.
+ """
+ import urllib
+ uri = conduit.utils.ensure_string(uri)
+ return urllib.unquote(uri)
+
+def uri_get_protocol(uri):
+ """
+ Returns the protocol (file, smb, etc) for a URI
+ """
+ uri = conduit.utils.ensure_string(uri)
+ if uri.rfind("://")==-1:
+ return ""
+ protocol = uri[:uri.index("://")+3]
+ return protocol.lower()
+
+def uri_get_filename(uri):
+ """
+ Method to return the filename of a file.
+ """
+ uri = conduit.utils.ensure_string(uri)
+ return uri.split(os.sep)[-1]
+
+def uri_get_filename_and_extension(uri):
+ """
+ Returns filename,file_extension
+ """
+ uri = conduit.utils.ensure_string(uri)
+ return os.path.splitext(uri_get_filename(uri))
+
+def uri_sanitize_for_filesystem(uri, filesystem=None):
+ """
+ Removes illegal characters in uri that cannot be stored on the
+ given filesystem - particuarly fat and ntfs types
+
+ Also see:
+ http://bugzilla.gnome.org/show_bug.cgi?id=309584#c20
+ """
+
+ uri = conduit.utils.ensure_string(uri)
+ import string
+
+ ILLEGAL_CHARS = {
+ "fat" : "\\:*?\"<>|",
+ "vfat" : "\\:*?\"<>|",
+ "msdos" : "\\:*?\"<>|",
+ "msdosfs" : "\\:*?\"<>|",
+ "ntfs" : "\\:*?\"<>|"
+ }
+
+ illegal = ILLEGAL_CHARS.get(filesystem,None)
+ if illegal:
+
+ #call urllib.unescape otherwise for example ? is rapresented as %3F
+ uri = urllib.unquote(uri)
+
+ #dont escape the scheme part
+ idx = uri.rfind("://")
+ if idx == -1:
+ start = 0
+ else:
+ start = idx + 3
+
+ #replace illegal chars with a -, ignoring the scheme (don't use a space because you can't create a directory with just a space)
+ ret = uri[0:start]+uri[start:].translate(string.maketrans(
+ illegal,
+ "_"*len(illegal)
+ )
+ )
+ ret = uri[0:start]+urllib.quote (ret[start:])
+ return ret
+ return uri
+
+def uri_is_folder(uri):
+ """
+ @returns: True if the uri is a folder and not a file
+ """
+ f = File.File(uri)
+ return f.is_directory()
+
+def uri_format_for_display(uri):
+ """
+ Formats the uri so it can be displayed to the user (strips passwords, etc)
+ """
+ f = File.File(uri)
+ return f.get_uri_for_display()
+
+def uri_exists(uri):
+ """
+ @returns: True if the uri exists
+ """
+ f = File.File(uri)
+ return f.exists()
+
diff --git a/configure.ac b/configure.ac
index 351841d..f4bec4d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,20 +25,6 @@ GNOME_DOC_INIT
AM_PATH_PYTHON(2.4)
################################################################################
-# File Implementation
-################################################################################
-FILE_IMPL="GIO"
-
-AC_ARG_WITH([file_impl],
- AC_HELP_STRING([--with-file-impl], [GIO (default), Python]))
-
-if test "$with_file_impl" = "Python" ; then
- FILE_IMPL=$with_file_impl
-fi
-
-AC_SUBST(FILE_IMPL)
-
-################################################################################
# Browser Implementation
################################################################################
BROWSER_IMPL="webkit"
@@ -60,10 +46,7 @@ AM_CHECK_PYMOD([vobject], , , AC_MSG_ERROR([Python module vobject required to ru
AM_CHECK_PYMOD([dateutil], , , AC_MSG_ERROR([Python module dateutil required to run Conduit]))
AM_CHECK_PYMOD_VERSION([goocanvas], [pygoocanvas_version], [0.9.0], , AC_MSG_ERROR([Python module goocanvas >= 0.9.0 required to run Conduit]))
AM_CHECK_PYMOD_VERSION([dbus], [__version__], [0.80.0], , AC_MSG_ERROR([Python module dbus >= 0.80.0 required to run Conduit]))
-
-if test $FILE_IMPL = "GIO" ; then
- AM_CHECK_PYMOD_VERSION([gio], [pygio_version], [2.16.1], , AC_MSG_ERROR([Python module gio >= 2.16.1 required to run Conduit]))
-fi
+AM_CHECK_PYMOD_VERSION([gio], [pygio_version], [2.16.1], , AC_MSG_ERROR([Python module gio >= 2.16.1 required to run Conduit]))
################################################################################
# DBus
@@ -164,6 +147,7 @@ Makefile
conduit/defs.py
conduit/Makefile
conduit/utils/Makefile
+conduit/vfs/Makefile
conduit/datatypes/Makefile
conduit/dataproviders/Makefile
conduit/gtkui/Makefile
@@ -228,7 +212,6 @@ echo
echo $PACKAGE v$VERSION
echo
echo Prefix............... : $prefix
-echo File Implementation.. : $FILE_IMPL
echo Browser Implementation: $BROWSER_IMPL
echo Dbus Services Dir.... : $DBUS_SERVICES_DIR
echo Nautilus Extension... : $enable_nautilus_extension
diff --git a/test/python-tests/TestCoreFile.py b/test/python-tests/TestCoreFile.py
index e51d4e5..c50b2f9 100644
--- a/test/python-tests/TestCoreFile.py
+++ b/test/python-tests/TestCoreFile.py
@@ -4,309 +4,295 @@ from common import *
import conduit
import conduit.datatypes.File as File
import conduit.utils as Utils
-import conduit.Vfs as Vfs
+import conduit.vfs as Vfs
import os
import time
import datetime
import tempfile
-if os.environ.has_key("CONDUIT_FILE_IMPL"):
- impls = (os.environ["CONDUIT_FILE_IMPL"],)
-else:
- impls = ("GIO", )
-
-for impl in impls:
- ok("--- TESTING FILE IMPL: %s" % impl, True)
-
- try:
- f = File.File(implName=impl)
- except:
- ok("Base: Must specify URI", True)
-
- null = File.File("/foo/bar",implName=impl)
- ok("Base: non-existant file", null.exists() == False)
-
- #test tempfile handling
- temp = Utils.new_tempfile(Utils.random_string(), implName=impl)
- ok("Base: Detected tempfile", temp.is_local() and temp._is_tempfile())
-
- uri = temp.get_local_uri()
- ok("Base: Tempfile in temp dir", uri and uri.startswith(tempfile.gettempdir()))
-
- temp.delete()
- gone = File.File(uri,implName=impl)
- ok("Base: Delete tempfile", not gone.exists())
-
- #test making directories
- tmpdir = Utils.new_tempdir()
- tmpdir2 = os.path.join(tmpdir, "subdir")
- f = File.File(tmpdir2,implName=impl)
- ok("Base: make directory", f.make_directory() == True)
-
- temp = Utils.new_tempfile(Utils.random_string(), implName=impl)
- temp.set_contents_as_text("123")
- contents = temp.get_contents_as_text()
- ok("Base: wrote contents", contents == "123")
-
- temp.set_contents_as_text("456")
- contents = temp.get_contents_as_text()
- ok("Base: wrote contents again", contents == "456")
-
- # write a random amount to the temp file
-
- tempsize = random.randint(100, 200)
- contents = "a"*tempsize
- temp.set_contents_as_text(contents)
- ok( "Base: file size is accurate", temp.get_size() == tempsize )
- old_mtime = temp.get_mtime();
- old_hash = temp.get_hash();
-
- # now, add some more
- tempsize = random.randint(100, 200)
- contents += "b"*tempsize
- temp.set_contents_as_text(contents)
- ok("Base: Check if appending to a file changes its hash", temp.get_hash() != old_hash)
-
- # reset the mtime, and make sure the hash is still different
- temp.set_mtime( old_mtime )
- ok( "Base: Check if reseting a file's mtime is successful", temp.get_mtime() == old_mtime )
- ok( "Base: Check that the hash is still different, even with the same mtime.", temp.get_hash() != old_hash )
-
- remUri = get_external_resources('folder')['removable-volume']
- rf = File.File(remUri,implName=impl)
- if Vfs.uri_exists(remUri):
- ok("Base: Removable volume detected", rf.is_on_removale_volume() == True)
- ok("Base: Removable volume calculate root path", rf.get_removable_volume_root_uri() == remUri)
-
- folder = File.File(os.environ["HOME"],implName=impl)
- ok("Base: check if HOME exists", folder.exists() == True)
- ok("Base: check if HOME is folder", folder.is_directory() == True)
-
- localURIs = [ os.path.abspath(os.path.join(my_path,"..", "test-data","oldest")),
- os.path.abspath(os.path.join(my_path,"..", "test-data","older")),
- os.path.abspath(os.path.join(my_path,"..", "test-data","newer")),
- os.path.abspath(os.path.join(my_path,"..", "test-data","newest"))
- ]
-
- #test the comparison of files by mtime
- oldest = File.File(localURIs[0],implName=impl)
- older = File.File(localURIs[1],implName=impl)
- newer = File.File(localURIs[2],implName=impl)
- newest = File.File(localURIs[3],implName=impl)
-
- for i in localURIs:
- f = File.File(i,implName=impl)
- ok("Local: %s exists" % i, f.exists())
- remote = f.is_local() == 1
- # these might not be local, we might be on nfs after all!
- ok("Local: is local = %s" % remote,remote,die=False)
+try:
+ f = File.File()
+except:
+ ok("Base: Must specify URI", True)
+
+null = File.File("/foo/bar")
+ok("Base: non-existant file", null.exists() == False)
+
+#test tempfile handling
+temp = Utils.new_tempfile(Utils.random_string())
+ok("Base: Detected tempfile", temp.is_local() and temp._is_tempfile())
+
+uri = temp.get_local_uri()
+ok("Base: Tempfile in temp dir", uri and uri.startswith(tempfile.gettempdir()))
+
+temp.delete()
+gone = File.File(uri)
+ok("Base: Delete tempfile", not gone.exists())
+
+#test making directories
+tmpdir = Utils.new_tempdir()
+tmpdir2 = os.path.join(tmpdir, "subdir")
+f = File.File(tmpdir2)
+ok("Base: make directory", f.make_directory() == True)
+
+temp = Utils.new_tempfile(Utils.random_string())
+temp.set_contents_as_text("123")
+contents = temp.get_contents_as_text()
+ok("Base: wrote contents", contents == "123")
+
+temp.set_contents_as_text("456")
+contents = temp.get_contents_as_text()
+ok("Base: wrote contents again", contents == "456")
+
+# write a random amount to the temp file
+
+tempsize = random.randint(100, 200)
+contents = "a"*tempsize
+temp.set_contents_as_text(contents)
+ok( "Base: file size is accurate", temp.get_size() == tempsize )
+old_mtime = temp.get_mtime();
+old_hash = temp.get_hash();
+
+# now, add some more
+tempsize = random.randint(100, 200)
+contents += "b"*tempsize
+temp.set_contents_as_text(contents)
+ok("Base: Check if appending to a file changes its hash", temp.get_hash() != old_hash)
+
+# reset the mtime, and make sure the hash is still different
+temp.set_mtime( old_mtime )
+ok( "Base: Check if reseting a file's mtime is successful", temp.get_mtime() == old_mtime )
+ok( "Base: Check that the hash is still different, even with the same mtime.", temp.get_hash() != old_hash )
+
+remUri = get_external_resources('folder')['removable-volume']
+rf = File.File(remUri)
+if Vfs.uri_exists(remUri):
+ ok("Base: Removable volume detected", rf.is_on_removale_volume() == True)
+ ok("Base: Removable volume calculate root path", rf.get_removable_volume_root_uri() == remUri)
+
+folder = File.File(os.environ["HOME"])
+ok("Base: check if HOME exists", folder.exists() == True)
+ok("Base: check if HOME is folder", folder.is_directory() == True)
+
+localURIs = [ os.path.abspath(os.path.join(my_path,"..", "test-data","oldest")),
+ os.path.abspath(os.path.join(my_path,"..", "test-data","older")),
+ os.path.abspath(os.path.join(my_path,"..", "test-data","newer")),
+ os.path.abspath(os.path.join(my_path,"..", "test-data","newest"))
+ ]
+
+#test the comparison of files by mtime
+oldest = File.File(localURIs[0])
+older = File.File(localURIs[1])
+newer = File.File(localURIs[2])
+newest = File.File(localURIs[3])
+
+for i in localURIs:
+ f = File.File(i)
+ ok("Local: %s exists" % i, f.exists())
+ remote = f.is_local() == 1
+ # these might not be local, we might be on nfs after all!
+ ok("Local: is local = %s" % remote,remote,die=False)
+ mime = f.get_mimetype()
+ ok("Local: file mimetype = %s" % mime,type(mime) == str and len(mime) > 0)
+ mtime = f.get_mtime()
+ ok("Local: file mtime = %s" % mtime,mtime != None)
+ size = f.get_size()
+ #the files are 5 bytes in size
+ ok("Local: file size = %s" % size,size == 5)
+ fname = f.get_filename()
+ #Not a strict test because my get_filename() is a bit of a hack
+ ok("Local: file name = %s" % fname,fname == Vfs.uri_get_filename(i))
+
+comp = oldest.compare(older)
+ok("Local Compare: checking oldest < older = %s" % comp,comp == conduit.datatypes.COMPARISON_OLDER)
+comp = newest.compare(newer)
+ok("Local Compare: checking newest > newer = %s" % comp,comp == conduit.datatypes.COMPARISON_NEWER)
+comp = newest.compare(newest)
+ok("Local Compare: checking newest == newest = %s" % comp,comp == conduit.datatypes.COMPARISON_EQUAL)
+comp = oldest.compare(null)
+ok("Local Compare: checking oldest w null = %s" % comp,comp == conduit.datatypes.COMPARISON_NEWER)
+
+#test the handling of weird characters and transferring files to unusual paths
+tmpdir = Utils.new_tempdir()
+f1 = Utils.new_tempfile(Utils.random_string())
+f2 = os.path.join(tmpdir,"I am", "a", "path with spaces", "foo.txt")
+
+f3 = Utils.new_tempfile(Utils.random_string())
+f4 = os.path.join(tmpdir,"I also am", "a", "wierd path", "foo.txt")
+
+f1.transfer(f2)
+f3.transfer(f4)
+
+if is_online():
+ #so conduit asks me for my password
+ remoteURIs = [ "http://www.gnome.org/~jstowers/conduit_test_data/Document.abw",
+ "http://www.gnome.org/~jstowers/conduit_test_data/Image.png",
+ "http://www.gnome.org/~jstowers/conduit_test_data/Tgz.tar.gz",
+ "http://www.gnome.org/~jstowers/conduit_test_data/Text.txt",
+ "http://www.gnome.org/~jstowers/conduit_test_data/Text",
+ "http://www.gnome.org/~jstowers/conduit_test_data/oldest",
+ "http://www.gnome.org/~jstowers/conduit_test_data/older",
+ "http://www.gnome.org/~jstowers/conduit_test_data/newer",
+ "http://www.gnome.org/~jstowers/conduit_test_data/newest"
+ ]
+
+
+ roldest = File.File(remoteURIs[5])
+ rolder = File.File(remoteURIs[6])
+ rnewer = File.File(remoteURIs[7])
+ rnewest = File.File(remoteURIs[8])
+
+ #test rebasing a remote file to local and returning its uri
+ lrnewer = File.File(remoteURIs[1])
+ lrnewerfname = Vfs.uri_get_filename(remoteURIs[1])
+ lrneweruri = lrnewer.get_local_uri()
+ ok("Base: getting local copy of a remote file = %s" % lrneweruri,type(lrneweruri) == str and len(lrneweruri) > 0)
+ remote = lrnewer.is_local() == 1
+ ok("Local: is local = %s" % remote,remote)
+ mime = lrnewer.get_mimetype()
+ ok("Local: file mimetype = %s" % mime,type(mime) == str and len(mime) > 0)
+ mtime = lrnewer.get_mtime()
+ ok("Local: file mtime = %s" % mtime,mtime != None)
+ size = lrnewer.get_size()
+ ok("Local: file size = %s" % size,size != None)
+ fname = lrnewer.get_filename()
+ #Not a strict test because my get_filename() is a bit of a hack
+ ok("Local: file name = %s" % fname,fname == lrnewerfname)
+
+ for i in remoteURIs:
+ f = File.File(i)
+ ok("Remote: %s exists" % i, f.exists())
+ remote = f.is_local() == 0
+ ok("Remote: is remote = %s" % remote,remote)
mime = f.get_mimetype()
- ok("Local: file mimetype = %s" % mime,type(mime) == str and len(mime) > 0)
+ ok("Remote: file mimetype = %s" % mime,type(mime) == str and len(mime) > 0)
mtime = f.get_mtime()
- ok("Local: file mtime = %s" % mtime,mtime != None)
+ ok("Remote: file mtime = %s" % mtime,mtime != None)
size = f.get_size()
- #the files are 5 bytes in size
- ok("Local: file size = %s" % size,size == 5)
+ ok("Remote: file size = %s" % size,size != None)
fname = f.get_filename()
#Not a strict test because my get_filename() is a bit of a hack
- ok("Local: file name = %s" % fname,fname == Vfs.uri_get_filename(i))
-
- comp = oldest.compare(older)
- ok("Local Compare: checking oldest < older = %s" % comp,comp == conduit.datatypes.COMPARISON_OLDER)
- comp = newest.compare(newer)
- ok("Local Compare: checking newest > newer = %s" % comp,comp == conduit.datatypes.COMPARISON_NEWER)
- comp = newest.compare(newest)
- ok("Local Compare: checking newest == newest = %s" % comp,comp == conduit.datatypes.COMPARISON_EQUAL)
- comp = oldest.compare(null)
- ok("Local Compare: checking oldest w null = %s" % comp,comp == conduit.datatypes.COMPARISON_NEWER)
-
- #test the handling of weird characters and transferring files to unusual paths
- tmpdir = Utils.new_tempdir()
- f1 = Utils.new_tempfile(Utils.random_string(), implName=impl)
- f2 = os.path.join(tmpdir,"I am", "a", "path with spaces", "foo.txt")
-
- f3 = Utils.new_tempfile(Utils.random_string(), implName=impl)
- f4 = os.path.join(tmpdir,"I also am", "a", "wierd path", "foo.txt")
-
- f1.transfer(f2)
- f3.transfer(f4)
-
- if is_online():
- #so conduit asks me for my password
- remoteURIs = [ "http://www.gnome.org/~jstowers/conduit_test_data/Document.abw",
- "http://www.gnome.org/~jstowers/conduit_test_data/Image.png",
- "http://www.gnome.org/~jstowers/conduit_test_data/Tgz.tar.gz",
- "http://www.gnome.org/~jstowers/conduit_test_data/Text.txt",
- "http://www.gnome.org/~jstowers/conduit_test_data/Text",
- "http://www.gnome.org/~jstowers/conduit_test_data/oldest",
- "http://www.gnome.org/~jstowers/conduit_test_data/older",
- "http://www.gnome.org/~jstowers/conduit_test_data/newer",
- "http://www.gnome.org/~jstowers/conduit_test_data/newest"
- ]
-
-
- roldest = File.File(remoteURIs[5],implName=impl)
- rolder = File.File(remoteURIs[6],implName=impl)
- rnewer = File.File(remoteURIs[7],implName=impl)
- rnewest = File.File(remoteURIs[8],implName=impl)
-
- #test rebasing a remote file to local and returning its uri
- lrnewer = File.File(remoteURIs[1],implName=impl)
- lrnewerfname = Vfs.uri_get_filename(remoteURIs[1])
- lrneweruri = lrnewer.get_local_uri()
- ok("Base: getting local copy of a remote file = %s" % lrneweruri,type(lrneweruri) == str and len(lrneweruri) > 0)
- remote = lrnewer.is_local() == 1
- ok("Local: is local = %s" % remote,remote)
- mime = lrnewer.get_mimetype()
- ok("Local: file mimetype = %s" % mime,type(mime) == str and len(mime) > 0)
- mtime = lrnewer.get_mtime()
- ok("Local: file mtime = %s" % mtime,mtime != None)
- size = lrnewer.get_size()
- ok("Local: file size = %s" % size,size != None)
- fname = lrnewer.get_filename()
- #Not a strict test because my get_filename() is a bit of a hack
- ok("Local: file name = %s" % fname,fname == lrnewerfname)
-
- for i in remoteURIs:
- f = File.File(i,implName=impl)
- ok("Remote: %s exists" % i, f.exists())
- remote = f.is_local() == 0
- ok("Remote: is remote = %s" % remote,remote)
- mime = f.get_mimetype()
- ok("Remote: file mimetype = %s" % mime,type(mime) == str and len(mime) > 0)
- mtime = f.get_mtime()
- ok("Remote: file mtime = %s" % mtime,mtime != None)
- size = f.get_size()
- ok("Remote: file size = %s" % size,size != None)
- fname = f.get_filename()
- #Not a strict test because my get_filename() is a bit of a hack
- ok("Remote: file name = %s" % fname,fname == Vfs.uri_get_filename(i))
-
-
- comp = roldest.compare(rolder)
- ok("Remote Compare: checking roldest < rolder = %s" % comp,comp == conduit.datatypes.COMPARISON_OLDER)
- comp = rnewest.compare(rnewer)
- ok("Remote Compare: checking rnewest > rnewer = %s" % comp,comp == conduit.datatypes.COMPARISON_NEWER)
- comp = rnewest.compare(rnewest)
- ok("Remote Compare: checking rnewest == rnewest = %s" % comp,comp == conduit.datatypes.COMPARISON_EQUAL)
- comp = roldest.compare(null)
- ok("Remote Compare: checking roldest w null = %s" % comp,comp == conduit.datatypes.COMPARISON_NEWER)
-
- comp = oldest.compare(rolder)
- ok("Remote & Local Compare: checking oldest < rolder = %s" % comp,comp == conduit.datatypes.COMPARISON_OLDER, False)
- comp = rnewest.compare(newer)
- ok("Remote & Local Compare: checking rnewest > newer = %s" % comp,comp == conduit.datatypes.COMPARISON_NEWER, False)
- comp = rnewest.compare(newest)
- ok("Remote & Local Compare: checking rnewest == newest = %s" % comp,comp == conduit.datatypes.COMPARISON_EQUAL, False)
-
- tmpdir = tempfile.mkdtemp()
- ok("Created tempdir %s" % tmpdir, True)
-
- #remote file on readonly location
- f = File.File("http://files.conduit-project.org/screenshot.png",implName=impl)
- ok("Remote file exists", f.exists() == True)
-
- #make another local file
- local = Utils.new_tempfile(Utils.random_string(), implName=impl)
-
- #save the old information
- fOldName = f.get_filename()
- fOldSize = f.get_size()
- fOldMtime = f.get_mtime()
- localOldName = local.get_filename()
- localOldSize = local.get_size()
- localOldMtime = local.get_mtime()
-
- ok("Got R/O file info (%s)" % fOldName, fOldSize > 0 and fOldMtime != None)
- ok("Got file info (%s)" % localOldName, localOldSize > 0 and localOldMtime != None)
-
- #the new filenames
- fNewName = Utils.random_string()
- localNewName = Utils.random_string()
- newDate = datetime.datetime(1983,8,16)
-
- #change the filenames
- f.force_new_filename(fNewName)
- local.force_new_filename(localNewName)
- ok("Renamed R/O file correctly (%s)" % fNewName, fNewName == f.get_filename())
- ok("Renamed correctly (%s)" % localNewName, localNewName == local.get_filename())
-
- #change the file mtime
- f.force_new_mtime(newDate)
- local.force_new_mtime(newDate)
- ok("Set mtime R/O file mtime correctly (%s)" % fNewName, f.get_mtime() == newDate)
- ok("Set mtime correctly (%s)" % localNewName, local.get_mtime() == newDate)
-
- #transfer to new directory and check that the filenames get withheld in the transfer
- f.transfer(tmpdir)
- local.transfer(tmpdir)
- ok("Transferred R/O file correctly (%s)" % fNewName, f.get_filename() == fNewName)
- ok("Transferred correctly (%s)" % localNewName, local.get_filename() == localNewName)
-
- #play with proxy files, i.e. files that are like remote files, but stop being such
- #when transferred to the local system
- day0 = datetime.datetime(1983,8,16)
- day1 = datetime.datetime(1983,8,17)
-
- #compare two proxy files based on mtime only
- f = File.ProxyFile(
- URI=get_external_resources("file")["remote"],
- name=None,
- modified=day0,
- size=None,
- implName=impl)
- f2 = File.ProxyFile(
- URI=get_external_resources("file")["remote"],
- name=None,
- modified=day1,
- size=None,
- implName=impl)
- comp = f.compare(f2)
- ok("Proxy file comparison (mtime): %s" % comp,comp == conduit.datatypes.COMPARISON_OLDER)
-
- #compare two proxy files based on size only
- proxyFileName = Utils.random_string()
- f = File.ProxyFile(
- URI=get_external_resources("file")["remote"],
- name=None,
- modified=day0,
- size=10,
- implName=impl)
- f2 = File.ProxyFile(
- URI=get_external_resources("file")["remote"],
- name=proxyFileName,
- modified=day0,
- size=10,
- implName=impl)
- comp = f.compare(f2)
- ok("Proxy file comparison (size): %s" % comp,comp == conduit.datatypes.COMPARISON_EQUAL)
-
- f2.transfer(tmpdir)
- ok("Transferred ProxyFile correctly (%s)" % proxyFileName, f2.get_filename() == proxyFileName)
-
- ok("ProxyFile graduated to real file", f2._is_proxyfile() == False)
-
- #Now go back and test successful, i.e. non temp file, mtime and setting
- nn = "new name"
- nmt = datetime.datetime(2007,10,29)
-
- #remember old data
- f = File.File(localURIs[0],implName=impl)
- on = f.get_filename()
- omt = f.get_mtime()
-
- f.force_new_filename(nn)
- ok("Local: set new name", f.get_filename() == nn)
-
- f.force_new_mtime(nmt)
- ok("Local: set new mtime", f.get_mtime() == nmt)
-
- #restore old values
- f.force_new_filename(on)
- f.force_new_mtime(omt)
-
-
+ ok("Remote: file name = %s" % fname,fname == Vfs.uri_get_filename(i))
+
+
+ comp = roldest.compare(rolder)
+ ok("Remote Compare: checking roldest < rolder = %s" % comp,comp == conduit.datatypes.COMPARISON_OLDER)
+ comp = rnewest.compare(rnewer)
+ ok("Remote Compare: checking rnewest > rnewer = %s" % comp,comp == conduit.datatypes.COMPARISON_NEWER)
+ comp = rnewest.compare(rnewest)
+ ok("Remote Compare: checking rnewest == rnewest = %s" % comp,comp == conduit.datatypes.COMPARISON_EQUAL)
+ comp = roldest.compare(null)
+ ok("Remote Compare: checking roldest w null = %s" % comp,comp == conduit.datatypes.COMPARISON_NEWER)
+
+ comp = oldest.compare(rolder)
+ ok("Remote & Local Compare: checking oldest < rolder = %s" % comp,comp == conduit.datatypes.COMPARISON_OLDER, False)
+ comp = rnewest.compare(newer)
+ ok("Remote & Local Compare: checking rnewest > newer = %s" % comp,comp == conduit.datatypes.COMPARISON_NEWER, False)
+ comp = rnewest.compare(newest)
+ ok("Remote & Local Compare: checking rnewest == newest = %s" % comp,comp == conduit.datatypes.COMPARISON_EQUAL, False)
+
+ tmpdir = tempfile.mkdtemp()
+ ok("Created tempdir %s" % tmpdir, True)
+
+ #remote file on readonly location
+ f = File.File("http://files.conduit-project.org/screenshot.png")
+ ok("Remote file exists", f.exists() == True)
+
+ #make another local file
+ local = Utils.new_tempfile(Utils.random_string())
+
+ #save the old information
+ fOldName = f.get_filename()
+ fOldSize = f.get_size()
+ fOldMtime = f.get_mtime()
+ localOldName = local.get_filename()
+ localOldSize = local.get_size()
+ localOldMtime = local.get_mtime()
+
+ ok("Got R/O file info (%s)" % fOldName, fOldSize > 0 and fOldMtime != None)
+ ok("Got file info (%s)" % localOldName, localOldSize > 0 and localOldMtime != None)
+
+ #the new filenames
+ fNewName = Utils.random_string()
+ localNewName = Utils.random_string()
+ newDate = datetime.datetime(1983,8,16)
+
+ #change the filenames
+ f.force_new_filename(fNewName)
+ local.force_new_filename(localNewName)
+ ok("Renamed R/O file correctly (%s)" % fNewName, fNewName == f.get_filename())
+ ok("Renamed correctly (%s)" % localNewName, localNewName == local.get_filename())
+
+ #change the file mtime
+ f.force_new_mtime(newDate)
+ local.force_new_mtime(newDate)
+ ok("Set mtime R/O file mtime correctly (%s)" % fNewName, f.get_mtime() == newDate)
+ ok("Set mtime correctly (%s)" % localNewName, local.get_mtime() == newDate)
+
+ #transfer to new directory and check that the filenames get withheld in the transfer
+ f.transfer(tmpdir)
+ local.transfer(tmpdir)
+ ok("Transferred R/O file correctly (%s)" % fNewName, f.get_filename() == fNewName)
+ ok("Transferred correctly (%s)" % localNewName, local.get_filename() == localNewName)
+
+ #play with proxy files, i.e. files that are like remote files, but stop being such
+ #when transferred to the local system
+ day0 = datetime.datetime(1983,8,16)
+ day1 = datetime.datetime(1983,8,17)
+
+ #compare two proxy files based on mtime only
+ f = File.ProxyFile(
+ URI=get_external_resources("file")["remote"],
+ name=None,
+ modified=day0,
+ size=None)
+ f2 = File.ProxyFile(
+ URI=get_external_resources("file")["remote"],
+ name=None,
+ modified=day1,
+ size=None)
+ comp = f.compare(f2)
+ ok("Proxy file comparison (mtime): %s" % comp,comp == conduit.datatypes.COMPARISON_OLDER)
+
+ #compare two proxy files based on size only
+ proxyFileName = Utils.random_string()
+ f = File.ProxyFile(
+ URI=get_external_resources("file")["remote"],
+ name=None,
+ modified=day0,
+ size=10)
+ f2 = File.ProxyFile(
+ URI=get_external_resources("file")["remote"],
+ name=proxyFileName,
+ modified=day0,
+ size=10)
+ comp = f.compare(f2)
+ ok("Proxy file comparison (size): %s" % comp,comp == conduit.datatypes.COMPARISON_EQUAL)
+
+ f2.transfer(tmpdir)
+ ok("Transferred ProxyFile correctly (%s)" % proxyFileName, f2.get_filename() == proxyFileName)
+
+ ok("ProxyFile graduated to real file", f2._is_proxyfile() == False)
+
+#Now go back and test successful, i.e. non temp file, mtime and setting
+nn = "new name"
+nmt = datetime.datetime(2007,10,29)
+
+#remember old data
+f = File.File(localURIs[0])
+on = f.get_filename()
+omt = f.get_mtime()
+
+f.force_new_filename(nn)
+ok("Local: set new name", f.get_filename() == nn)
+
+f.force_new_mtime(nmt)
+ok("Local: set new mtime", f.get_mtime() == nmt)
+
+#restore old values
+f.force_new_filename(on)
+f.force_new_mtime(omt)
finished()
diff --git a/test/python-tests/TestCoreFileCopyMany.py b/test/python-tests/TestCoreFileCopyMany.py
index 81e20a9..e65677b 100644
--- a/test/python-tests/TestCoreFileCopyMany.py
+++ b/test/python-tests/TestCoreFileCopyMany.py
@@ -1,7 +1,8 @@
#common sets up the conduit environment
from common import *
-import conduit.Vfs as Vfs
+import conduit.vfs as Vfs
+import conduit.vfs.File as VfsFile
import conduit.utils as Utils
import conduit.datatypes.File as File
@@ -43,8 +44,8 @@ for music in lines:
sinkDir,
Vfs.uri_get_relative(sourceDir, music))
- xfer = Vfs.FileTransfer(
- File.File(music)._get_impl(),
+ xfer = VfsFile.FileTransfer(
+ VfsFile.File(music),
dest)
i = xfer.transfer(False, None)[0]
if not i:
@@ -55,7 +56,7 @@ wait_seconds(2)
def prog(*args): pass
def done(*args): pass
-stm = Vfs.FolderScannerThreadManager(maxConcurrentThreads=1)
+stm = VfsFile.FolderScannerThreadManager(maxConcurrentThreads=1)
t1 = stm.make_thread(sourceDir, True, True, prog, done)
t2 = stm.make_thread(sinkDir, True, True, prog, done)
stm.join_all_threads()
diff --git a/test/python-tests/TestCoreVfs.py b/test/python-tests/TestCoreVfs.py
index 4aa2d81..b4240a5 100644
--- a/test/python-tests/TestCoreVfs.py
+++ b/test/python-tests/TestCoreVfs.py
@@ -1,102 +1,98 @@
#common sets up the conduit environment
from common import *
-import conduit.Vfs as Vfs
+import conduit.vfs as Vfs
+import conduit.vfs.File as VfsFile
import conduit.utils as Utils
-for impl in ("GIO",):
- conduit.FILE_IMPL = impl
- reload(Vfs)
- reload(Utils)
+ok("--- TESTING VFS WITH FILE IMPL: %s" % Vfs.backend_name(), True)
+ok("Supports remote uri schemes: %s" % Vfs.backend_supports_remote_uri_schemes(), True)
- ok("--- TESTING VFS WITH FILE IMPL: %s" % Vfs.backend_name(), True)
- ok("Supports remote uri schemes: %s" % Vfs.backend_supports_remote_uri_schemes(), True)
+safe = '/&=:@'
+unsafe = ' !<>#%()[]{}'
+safeunsafe = '%20%21%3C%3E%23%25%28%29%5B%5D%7B%7D'
- safe = '/&=:@'
- unsafe = ' !<>#%()[]{}'
- safeunsafe = '%20%21%3C%3E%23%25%28%29%5B%5D%7B%7D'
+ok("Dont escape path characters",Vfs.uri_escape(safe+unsafe) == safe+safeunsafe)
+ok("Unescape back to original",Vfs.uri_unescape(safe+safeunsafe) == safe+unsafe)
+ok("Get protocol", Vfs.uri_get_protocol("file:///foo/bar") == "file://")
+name, ext = Vfs.uri_get_filename_and_extension("file:///foo/bar.ext")
+ok("Get filename (%s,%s)" % (name,ext), name == "bar" and ext == ".ext")
+ok("file:///home exists", Vfs.uri_exists("file:///home") == True)
+ok("/home exists", Vfs.uri_exists("/home") == True)
+ok("/home is folder", Vfs.uri_is_folder("/home") == True)
+ok("/foo/bar does not exist", Vfs.uri_exists("/foo/bar") == False)
+ok("format uri", Vfs.uri_format_for_display("file:///foo") == "/foo")
- ok("Dont escape path characters",Vfs.uri_escape(safe+unsafe) == safe+safeunsafe)
- ok("Unescape back to original",Vfs.uri_unescape(safe+safeunsafe) == safe+unsafe)
- ok("Get protocol", Vfs.uri_get_protocol("file:///foo/bar") == "file://")
- name, ext = Vfs.uri_get_filename_and_extension("file:///foo/bar.ext")
- ok("Get filename (%s,%s)" % (name,ext), name == "bar" and ext == ".ext")
- ok("file:///home exists", Vfs.uri_exists("file:///home") == True)
- ok("/home exists", Vfs.uri_exists("/home") == True)
- ok("/home is folder", Vfs.uri_is_folder("/home") == True)
- ok("/foo/bar does not exist", Vfs.uri_exists("/foo/bar") == False)
- ok("format uri", Vfs.uri_format_for_display("file:///foo") == "/foo")
+tmpdiruri = Utils.new_tempdir()
- tmpdiruri = Utils.new_tempdir()
+# Test the folder scanner theading stuff
+fileuri = Utils.new_tempfile("bla").get_local_uri()
+stm = VfsFile.FolderScannerThreadManager(maxConcurrentThreads=1)
- # Test the folder scanner theading stuff
- fileuri = Utils.new_tempfile("bla").get_local_uri()
- stm = Vfs.FolderScannerThreadManager(maxConcurrentThreads=1)
+def prog(*args): pass
+def done(*args): pass
- def prog(*args): pass
- def done(*args): pass
+t1 = stm.make_thread("file:///tmp", False, False, prog, done)
+t2 = stm.make_thread("file://"+tmpdiruri, False, False, prog, done)
+stm.join_all_threads()
- t1 = stm.make_thread("file:///tmp", False, False, prog, done)
- t2 = stm.make_thread("file://"+tmpdiruri, False, False, prog, done)
- stm.join_all_threads()
+ok("Scanned /tmp ok - found %s" % fileuri, "file://"+fileuri in t1.get_uris())
+ok("Scanned %s ok (empty)" % tmpdiruri, t2.get_uris() == [])
- ok("Scanned /tmp ok - found %s" % fileuri, "file://"+fileuri in t1.get_uris())
- ok("Scanned %s ok (empty)" % tmpdiruri, t2.get_uris() == [])
+# Test the volume management stuff
+ntfsUri = get_external_resources('folder')['ntfs-volume']
+if Vfs.uri_exists(ntfsUri):
+ fstype = Vfs.uri_get_filesystem_type(ntfsUri)
+ ok("Get filesystem type (%s)" % fstype,fstype == "ntfs", False)
+ #ok("Escape illegal chars in filenames",
+ # Vfs.uri_sanitize_for_filesystem("invalid:name","ntfs") == "invalid name")
+ #ok("Escape illegal chars in uris",
+ # Vfs.uri_sanitize_for_filesystem("file:///i:n/i:n","ntfs") == "file:///i n/i n")
- # Test the volume management stuff
- ntfsUri = get_external_resources('folder')['ntfs-volume']
- if Vfs.uri_exists(ntfsUri):
- fstype = Vfs.uri_get_filesystem_type(ntfsUri)
- ok("Get filesystem type (%s)" % fstype,fstype == "ntfs", False)
- #ok("Escape illegal chars in filenames",
- # Vfs.uri_sanitize_for_filesystem("invalid:name","ntfs") == "invalid name")
- #ok("Escape illegal chars in uris",
- # Vfs.uri_sanitize_for_filesystem("file:///i:n/i:n","ntfs") == "file:///i n/i n")
+localUri = get_external_resources('folder')['folder']
+ok("Local uri --> path", Vfs.uri_to_local_path(localUri) == "/tmp")
+ok("Local uri not removable", Vfs.uri_is_on_removable_volume(localUri) == False)
- localUri = get_external_resources('folder')['folder']
- ok("Local uri --> path", Vfs.uri_to_local_path(localUri) == "/tmp")
- ok("Local uri not removable", Vfs.uri_is_on_removable_volume(localUri) == False)
+removableUri = get_external_resources('folder')['removable-volume']
+if Vfs.uri_exists(removableUri):
+ fstype = Vfs.uri_get_filesystem_type(removableUri)
+ ok("Get filesystem type (%s)" % fstype,fstype in ("vfat","msdos"))
+ ok("Removable volume detected removable", Vfs.uri_is_on_removable_volume(removableUri))
+ ok("Removable volume calculate root path", Vfs.uri_get_volume_root_uri(removableUri).startswith("file:///media/"))
- removableUri = get_external_resources('folder')['removable-volume']
- if Vfs.uri_exists(removableUri):
- fstype = Vfs.uri_get_filesystem_type(removableUri)
- ok("Get filesystem type (%s)" % fstype,fstype in ("vfat","msdos"))
- ok("Removable volume detected removable", Vfs.uri_is_on_removable_volume(removableUri))
- ok("Removable volume calculate root path", Vfs.uri_get_volume_root_uri(removableUri).startswith("file:///media/"))
+URIS_TO_JOIN = (
+ ( ("file:///foo/bar","gax","ssss"),
+ "file:///foo/bar/gax/ssss"),
+ ( ("smb://192.168.1.1","Disk-2","Travel%20Videos/","Switzerland"),
+ "smb://192.168.1.1/Disk-2/Travel%20Videos/Switzerland"),
+ ( ("ssh://john open grcnz com/home","john","phd"),
+ "ssh://john open grcnz com/home/john/phd"),
+ ( ("foo","bar","baz"),
+ "foo/bar/baz")
+)
- URIS_TO_JOIN = (
- ( ("file:///foo/bar","gax","ssss"),
- "file:///foo/bar/gax/ssss"),
- ( ("smb://192.168.1.1","Disk-2","Travel%20Videos/","Switzerland"),
- "smb://192.168.1.1/Disk-2/Travel%20Videos/Switzerland"),
- ( ("ssh://john open grcnz com/home","john","phd"),
- "ssh://john open grcnz com/home/john/phd"),
- ( ("foo","bar","baz"),
- "foo/bar/baz")
- )
-
- for parts, result in URIS_TO_JOIN:
- got = Vfs.uri_join(*parts)
- ok("Join uri: %s" % result, got == result)
-
- RELATIVE_URIS = (
- #from #to #relativ
- ( "file:///foo/bar", "file:///baz/bob", "file:///baz/bob" ),
- ( "file:///foo/bar", "file:///foo/bar/baz/bob", "baz/bob" ),
- ( "file:///foo/bar", "file:///foo/bar/baz", "baz" ))
- for f,t,result in RELATIVE_URIS:
- got = Vfs.uri_get_relative(f,t)
- ok("Get relative uri: %s" % result, got == result)
-
- VALID_URIS = (
- #uri #valid
- ( "smb://192.168.1.1/foo/bar", True ),
- ( "ftp://192.168.1.1/foo/bar", True ),
- ( "file:///foo/bar", True ),
- ( "file:/foo/bar", False ),
- ( "ftp:192.168.1.1", False ),
- ( "/foo/bar", False ))
- for uri,result in VALID_URIS:
- desc = ("Invalid","Valid")[int(result)]
- ok("%s uri: %s" % (desc,uri),Vfs.uri_is_valid(uri) == result)
+for parts, result in URIS_TO_JOIN:
+ got = Vfs.uri_join(*parts)
+ ok("Join uri: %s" % result, got == result)
+
+RELATIVE_URIS = (
+ #from #to #relativ
+( "file:///foo/bar", "file:///baz/bob", "file:///baz/bob" ),
+( "file:///foo/bar", "file:///foo/bar/baz/bob", "baz/bob" ),
+( "file:///foo/bar", "file:///foo/bar/baz", "baz" ))
+for f,t,result in RELATIVE_URIS:
+ got = Vfs.uri_get_relative(f,t)
+ ok("Get relative uri: %s" % result, got == result)
+
+VALID_URIS = (
+ #uri #valid
+( "smb://192.168.1.1/foo/bar", True ),
+( "ftp://192.168.1.1/foo/bar", True ),
+( "file:///foo/bar", True ),
+( "file:/foo/bar", False ),
+( "ftp:192.168.1.1", False ),
+( "/foo/bar", False ))
+for uri,result in VALID_URIS:
+ desc = ("Invalid","Valid")[int(result)]
+ ok("%s uri: %s" % (desc,uri),Vfs.uri_is_valid(uri) == result)
finished()
diff --git a/test/python-tests/TestDataProviderFolder.py b/test/python-tests/TestDataProviderFolder.py
index a97728e..ae65880 100644
--- a/test/python-tests/TestDataProviderFolder.py
+++ b/test/python-tests/TestDataProviderFolder.py
@@ -4,7 +4,7 @@ from common import *
import conduit.dataproviders.File as FileDataProvider
import conduit.datatypes.File as File
import conduit.utils as Utils
-import conduit.Vfs as Vfs
+import conduit.vfs as Vfs
GROUP_NAME = "Cheese"
NESTED_DIR_NAME = "A Directory"
diff --git a/test/python-tests/TestDataProviderPicasa.py b/test/python-tests/TestDataProviderPicasa.py
index 266c815..6aa701d 100644
--- a/test/python-tests/TestDataProviderPicasa.py
+++ b/test/python-tests/TestDataProviderPicasa.py
@@ -4,7 +4,7 @@ from common import *
import traceback
import conduit.datatypes.File as File
-import conduit.Vfs as Vfs
+import conduit.vfs as Vfs
if not is_online():
skip()
diff --git a/test/python-tests/TestDataProviderSmugMug.py b/test/python-tests/TestDataProviderSmugMug.py
index 4a8f202..6fe28d3 100644
--- a/test/python-tests/TestDataProviderSmugMug.py
+++ b/test/python-tests/TestDataProviderSmugMug.py
@@ -5,7 +5,7 @@ import traceback
import conduit.datatypes.File as File
import conduit.utils as Utils
-import conduit.Vfs as Vfs
+import conduit.vfs as Vfs
if not is_online():
skip()
diff --git a/test/python-tests/common.py b/test/python-tests/common.py
index d21987a..a0b83eb 100644
--- a/test/python-tests/common.py
+++ b/test/python-tests/common.py
@@ -23,7 +23,6 @@ conduit.IS_INSTALLED = False
conduit.IS_DEVELOPMENT_VERSION = True
conduit.SHARED_DATA_DIR = os.path.join(base_path,"data")
conduit.SHARED_MODULE_DIR = os.path.join(base_path,"conduit","modules")
-conduit.FILE_IMPL = os.environ.get("CONDUIT_FILE_IMPL","GIO")
conduit.BROWSER_IMPL = os.environ.get("CONDUIT_BROWSER_IMPL","system")
conduit.SETTINGS_IMPL = os.environ.get("CONDUIT_SETTINGS_IMPL","GConf")
conduit.GLOBALS.settings = Settings.Settings()
@@ -33,7 +32,7 @@ import conduit.Logging as Logging
Logging.enable_debugging()
import conduit.utils as Utils
-import conduit.Vfs as Vfs
+import conduit.vfs as Vfs
import conduit.Module as Module
import conduit.TypeConverter as TypeConverter
import conduit.Synchronization as Synchronization
@@ -578,7 +577,8 @@ class SimpleSyncTest(SimpleTest):
def get_source_count(self):
try:
self.source.module.refresh()
- except Exception: pass
+ except Exception, e:
+ print e
return self.source.module.get_num_items()
diff --git a/test/soup/test_synchronization.py b/test/soup/test_synchronization.py
index 28b2cb3..875bf44 100644
--- a/test/soup/test_synchronization.py
+++ b/test/soup/test_synchronization.py
@@ -38,7 +38,6 @@ def make_testcase(src, src_data, snk, snk_data):
conduit.IS_DEVELOPMENT_VERSION = True
conduit.SHARED_DATA_DIR = os.path.join(soup.get_root(),"data")
conduit.SHARED_MODULE_DIR = os.path.join(soup.get_root(),"conduit","modules")
- conduit.FILE_IMPL = os.environ.get("CONDUIT_FILE_IMPL","GIO")
conduit.BROWSER_IMPL = os.environ.get("CONDUIT_BROWSER_IMPL","system")
conduit.SETTINGS_IMPL = os.environ.get("CONDUIT_SETTINGS_IMPL","Python")
conduit.GLOBALS.settings = Settings.Settings()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]