conduit r1697 - in trunk: . conduit conduit/datatypes conduit/platform test/python-tests
- From: jstowers svn gnome org
- To: svn-commits-list gnome org
- Subject: conduit r1697 - in trunk: . conduit conduit/datatypes conduit/platform test/python-tests
- Date: Fri, 29 Aug 2008 23:39:24 +0000 (UTC)
Author: jstowers
Date: Fri Aug 29 23:39:24 2008
New Revision: 1697
URL: http://svn.gnome.org/viewvc/conduit?rev=1697&view=rev
Log:
* conduit/Vfs.py:
* conduit/__init__.py:
* conduit/datatypes/File.py:
* conduit/platform/FileGio.py:
* conduit/platform/FileGnomeVfs.py:
* conduit/platform/FilePython.py:
* conduit/platform/__init__.py:
* test/python-tests/TestDataProviderShutterfly.py: Remove the last hard
dependency on gnomevfs. Add a minimal working Python file implementation
which lets conduit start up.
Modified:
trunk/ (props changed)
trunk/ChangeLog
trunk/conduit/Vfs.py
trunk/conduit/__init__.py
trunk/conduit/datatypes/File.py
trunk/conduit/platform/FileGio.py
trunk/conduit/platform/FileGnomeVfs.py
trunk/conduit/platform/FilePython.py
trunk/conduit/platform/__init__.py
trunk/test/python-tests/TestDataProviderShutterfly.py
Modified: trunk/conduit/Vfs.py
==============================================================================
--- trunk/conduit/Vfs.py (original)
+++ trunk/conduit/Vfs.py Fri Aug 29 23:39:24 2008
@@ -1,13 +1,9 @@
import os.path
import logging
import gobject
+import time
log = logging.getLogger("Vfs")
-try:
- import gnomevfs
-except ImportError:
- from gnome import gnomevfs
-
import conduit
import conduit.utils.Singleton as Singleton
@@ -20,7 +16,9 @@
else:
raise Exception("File Implementation %s Not Supported" % conduit.FILE_IMPL)
-VolumeMonitor = FileImpl.VolumeMonitor
+VolumeMonitor = FileImpl.VolumeMonitor
+FileMonitor = FileImpl.FileMonitor
+FolderScanner = FileImpl.FolderScanner
def uri_is_valid(uri):
"""
@@ -196,50 +194,6 @@
f = FileImpl.FileImpl(uri)
return f.exists()
-class FileMonitor(gobject.GObject):
-
- __gsignals__ = {
- "changed" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [
- gobject.TYPE_PYOBJECT,
- gobject.TYPE_PYOBJECT,
- gobject.TYPE_PYOBJECT])
- }
-
- MONITOR_EVENT_CREATED = gnomevfs.MONITOR_EVENT_CREATED
- MONITOR_EVENT_CHANGED = gnomevfs.MONITOR_EVENT_CHANGED
- MONITOR_EVENT_DELETED = gnomevfs.MONITOR_EVENT_DELETED
- MONITOR_EVENT_METADATA_CHANGED = gnomevfs.MONITOR_EVENT_METADATA_CHANGED
- MONITOR_EVENT_STARTEXECUTING = gnomevfs.MONITOR_EVENT_STARTEXECUTING
- MONITOR_EVENT_STOPEXECUTING = gnomevfs.MONITOR_EVENT_STOPEXECUTING
- MONITOR_FILE = gnomevfs.MONITOR_FILE
- MONITOR_DIRECTORY = gnomevfs.MONITOR_DIRECTORY
-
- def __init__(self):
- gobject.GObject.__init__(self)
- self._monitor_folder_id = None
-
- def _monitor_cb(self, monitor_uri, event_uri, event):
- self.emit("changed", monitor_uri, event_uri, event)
-
- def add(self, folder, monitorType):
- if self._monitor_folder_id != None:
- gnomevfs.monitor_cancel(self._monitor_folder_id)
- self._monitor_folder_id = None
-
- try:
- self._monitor_folder_id = gnomevfs.monitor_add(folder, monitorType, self._monitor_cb)
- except gnomevfs.NotSupportedError:
- # silently fail if we are looking at a folder that doesn't support directory monitoring
- self._monitor_folder_id = None
-
- def cancel(self):
- if self._monitor_folder_id != None:
- gnomevfs.monitor_cancel(self._monitor_folder_id)
- self._monitor_folder_id = None
-
-#
-# Scanner ThreadManager
-#
class FolderScannerThreadManager:
"""
Manages many FolderScanner threads. This involves joining and cancelling
@@ -319,105 +273,4 @@
thread.cancel()
thread.join() #May block
-#
-# FOLDER SCANNER
-#
-import threading
-import gobject
-import time
-
-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/)
- """
- delta = 0
-
- startTime = time.time()
- t = 1
- last_estimated = estimated = 0
- while len(self.dirs)>0:
- if self.cancelled:
- return
- dir = self.dirs.pop(0)
- try: hdir = gnomevfs.DirectoryHandle(dir)
- except:
- log.warn("Folder %s Not found" % dir)
- continue
- try: fileinfo = hdir.next()
- except StopIteration: continue;
- while fileinfo:
- filename = fileinfo.name
- if filename in [".","..",self.CONFIG_FILE_NAME]:
- pass
- else:
- if fileinfo.type == gnomevfs.FILE_TYPE_DIRECTORY:
- #Include hidden directories
- if filename[0] != "." or self.includeHidden:
- self.dirs.append(dir+"/"+filename)
- t += 1
- elif fileinfo.type == gnomevfs.FILE_TYPE_REGULAR or \
- (fileinfo.type == gnomevfs.FILE_TYPE_SYMBOLIC_LINK and self.followSymlinks):
- try:
- uri = uri_make_canonical(dir+"/"+filename)
- #Include hidden files
- if filename[0] != "." or self.includeHidden:
- self.URIs.append(uri)
- except UnicodeDecodeError:
- raise "UnicodeDecodeError",uri
- else:
- log.debug("Unsupported file type: %s (%s)" % (filename, fileinfo.type))
- try: fileinfo = hdir.next()
- except StopIteration: break;
- #Calculate the estimated complete percentags
- estimated = 1.0-float(len(self.dirs))/float(t)
- estimated *= 100
- #Enly emit progress signals every 10% (+/- 1%) change to save CPU
- if delta+10 - estimated <= 1:
- log.debug("Folder scan %s%% complete" % estimated)
- self.emit("scan-progress", len(self.URIs))
- delta += 10
- last_estimated = estimated
-
- i = 0
- total = len(self.URIs)
- endTime = time.time()
- log.debug("%s files loaded in %s seconds" % (total, (endTime - startTime)))
- self.emit("scan-completed")
-
- def cancel(self):
- """
- Cancels the thread as soon as possible.
- """
- self.cancelled = True
-
- def get_uris(self):
- return self.URIs
-
-
Modified: trunk/conduit/__init__.py
==============================================================================
--- trunk/conduit/__init__.py (original)
+++ trunk/conduit/__init__.py Fri Aug 29 23:39:24 2008
@@ -52,7 +52,7 @@
SHARED_DATA_DIR = os.path.join(DIRECTORY, "data")
GLADE_FILE = os.path.join(DIRECTORY, "data","conduit.glade")
SHARED_MODULE_DIR = os.path.join(DIRECTORY, "conduit", "modules")
- FILE_IMPL = "GnomeVfs" #{GnomeVfs, GIO}
+ FILE_IMPL = "GnomeVfs" #{GnomeVfs, GIO, Python}
BROWSER_IMPL = "gtkmozembed" #{gtkmozembed, webkit, system}
SETTINGS_IMPL = "GConf" #{GConf,Python}
Modified: trunk/conduit/datatypes/File.py
==============================================================================
--- trunk/conduit/datatypes/File.py (original)
+++ trunk/conduit/datatypes/File.py Fri Aug 29 23:39:24 2008
@@ -38,6 +38,9 @@
elif 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)
Modified: trunk/conduit/platform/FileGio.py
==============================================================================
--- trunk/conduit/platform/FileGio.py (original)
+++ trunk/conduit/platform/FileGio.py Fri Aug 29 23:39:24 2008
@@ -188,4 +188,10 @@
class VolumeMonitor(conduit.platform.VolumeMonitor):
pass
+class FileMonitor(conduit.platform.FileMonitor):
+ pass
+
+class FolderScanner(conduit.platform.FolderScanner):
+ def run(self):
+ self.emit("scan-completed")
Modified: trunk/conduit/platform/FileGnomeVfs.py
==============================================================================
--- trunk/conduit/platform/FileGnomeVfs.py (original)
+++ trunk/conduit/platform/FileGnomeVfs.py Fri Aug 29 23:39:24 2008
@@ -267,8 +267,88 @@
def volume_get_root_uri(self, path):
return self._vm.get_volume_for_path(path).get_activation_uri()
-
+class FileMonitor(conduit.platform.FileMonitor):
-
+ MONITOR_EVENT_CREATED = gnomevfs.MONITOR_EVENT_CREATED
+ MONITOR_EVENT_CHANGED = gnomevfs.MONITOR_EVENT_CHANGED
+ MONITOR_EVENT_DELETED = gnomevfs.MONITOR_EVENT_DELETED
+ MONITOR_DIRECTORY = gnomevfs.MONITOR_DIRECTORY
+
+ def __init__(self):
+ conduit.platform.FileMonitor.__init__(self)
+ self._id = None
+
+ def _monitor_cb(self, monitor_uri, event_uri, event):
+ self.emit("changed", monitor_uri, event_uri, event)
+
+ def add(self, folder, monitorType):
+ if self._id != None:
+ gnomevfs.monitor_cancel(self._id)
+ self._id = None
+
+ try:
+ self._id = gnomevfs.monitor_add(folder, monitorType, self._monitor_cb)
+ except gnomevfs.NotSupportedError:
+ # silently fail if we are looking at a folder that doesn't support directory monitoring
+ self._id = None
+
+ def cancel(self):
+ if self._id != None:
+ gnomevfs.monitor_cancel(self._id)
+ self._id = None
+
+class FolderScanner(conduit.platform.FolderScanner):
+
+ def run(self):
+ delta = 0
+ t = 1
+ last_estimated = estimated = 0
+ while len(self.dirs)>0:
+ if self.cancelled:
+ return
+ dir = self.dirs.pop(0)
+ try: hdir = gnomevfs.DirectoryHandle(dir)
+ except:
+ log.warn("Folder %s Not found" % dir)
+ continue
+ try: fileinfo = hdir.next()
+ except StopIteration: continue;
+ while fileinfo:
+ filename = fileinfo.name
+ if filename in [".","..",self.CONFIG_FILE_NAME]:
+ pass
+ else:
+ if fileinfo.type == gnomevfs.FILE_TYPE_DIRECTORY:
+ #Include hidden directories
+ if filename[0] != "." or self.includeHidden:
+ self.dirs.append(dir+"/"+filename)
+ t += 1
+ elif fileinfo.type == gnomevfs.FILE_TYPE_REGULAR or \
+ (fileinfo.type == gnomevfs.FILE_TYPE_SYMBOLIC_LINK and self.followSymlinks):
+ try:
+ uri = gnomevfs.make_uri_canonical(dir+"/"+filename)
+ #Include hidden files
+ if filename[0] != "." or self.includeHidden:
+ self.URIs.append(uri)
+ except UnicodeDecodeError:
+ raise "UnicodeDecodeError",uri
+ else:
+ log.debug("Unsupported file type: %s (%s)" % (filename, fileinfo.type))
+ try: fileinfo = hdir.next()
+ except StopIteration: break;
+ #Calculate the estimated complete percentags
+ estimated = 1.0-float(len(self.dirs))/float(t)
+ estimated *= 100
+ #Enly emit progress signals every 10% (+/- 1%) change to save CPU
+ if delta+10 - estimated <= 1:
+ log.debug("Folder scan %s%% complete" % estimated)
+ self.emit("scan-progress", len(self.URIs))
+ delta += 10
+ last_estimated = estimated
+
+ i = 0
+ total = len(self.URIs)
+ log.debug("%s files loaded" % total)
+ self.emit("scan-completed")
Modified: trunk/conduit/platform/FilePython.py
==============================================================================
--- trunk/conduit/platform/FilePython.py (original)
+++ trunk/conduit/platform/FilePython.py Fri Aug 29 23:39:24 2008
@@ -1,7 +1,7 @@
import os.path
+import mimetypes
import shutil
-import conduit.Vfs as Vfs
import conduit.platform
import logging
@@ -12,8 +12,83 @@
def __init__(self, URI):
self._path = URI.split("file://")[-1]
+ def get_text_uri(self):
+ return self._path
+
+ def get_local_path(self):
+ return self._path
+
+ def is_local(self):
+ return True
+
+ def is_directory(self):
+ return os.path.isdir(self._path)
+
+ def delete(self):
+ os.unlink(self._path)
+
+ def exists(self):
+ os.path.exists(self._path)
+
+ 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):
+ return os.path.basename(self._path)
+
+ def get_uri_for_display(self):
+ return self.get_filename()
+
+ def get_contents(self):
+ f = open(self._path, 'r')
+ data = f.read()
+ f.close()
+ return data
+
+ def get_mimetype(self):
+ mimetype, encoding = mimetypes.guess_type(self._path)
+ return mimetype
+
+ def get_size(self):
+ return os.path.getsize(self._path)
+
+ def set_props(self, **props):
+ pass
+
+ def close(self):
+ pass
+
+ 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
+
class FileTransferImpl(conduit.platform.FileTransfer):
pass
class VolumeMonitor(conduit.platform.VolumeMonitor):
pass
+
+class FileMonitor(conduit.platform.FileMonitor):
+ pass
+
+class FolderScanner(conduit.platform.FolderScanner):
+ def run(self):
+ self.emit("scan-completed")
+
Modified: trunk/conduit/platform/__init__.py
==============================================================================
--- trunk/conduit/platform/__init__.py (original)
+++ trunk/conduit/platform/__init__.py Fri Aug 29 23:39:24 2008
@@ -1,3 +1,4 @@
+import threading
import gobject
class File:
@@ -101,6 +102,70 @@
def volume_get_root_uri(self, path):
return None
+class FileMonitor(gobject.GObject):
+
+ __gsignals__ = {
+ "changed" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [
+ gobject.TYPE_PYOBJECT,
+ gobject.TYPE_PYOBJECT,
+ gobject.TYPE_PYOBJECT])
+ }
+
+ 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
Modified: trunk/test/python-tests/TestDataProviderShutterfly.py
==============================================================================
--- trunk/test/python-tests/TestDataProviderShutterfly.py (original)
+++ trunk/test/python-tests/TestDataProviderShutterfly.py Fri Aug 29 23:39:24 2008
@@ -1,9 +1,6 @@
#common sets up the conduit environment
from common import *
-import traceback
-import gnomevfs
-
from conduit.Module import ModuleManager
from conduit.TypeConverter import TypeConverter
import conduit.datatypes.File as File
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]