conduit r1179 - in trunk: . conduit conduit/dataproviders conduit/gtkui conduit/modules/FileModule test/python-tests
- From: jstowers svn gnome org
- To: svn-commits-list gnome org
- Subject: conduit r1179 - in trunk: . conduit conduit/dataproviders conduit/gtkui conduit/modules/FileModule test/python-tests
- Date: Thu, 10 Jan 2008 04:33:19 +0000 (GMT)
Author: jstowers
Date: Thu Jan 10 04:33:19 2008
New Revision: 1179
URL: http://svn.gnome.org/viewvc/conduit?rev=1179&view=rev
Log:
Move all gnomevfs functions from Utils.py to Vfs.py
Added:
trunk/test/python-tests/TestCoreVfs.py
- copied, changed from r1176, /trunk/test/python-tests/TestCoreUtil.py
Modified:
trunk/ChangeLog
trunk/conduit/Utils.py
trunk/conduit/Vfs.py
trunk/conduit/dataproviders/File.py
trunk/conduit/gtkui/ConflictResolver.py
trunk/conduit/modules/FileModule/FileConfiguration.py
trunk/test/python-tests/TestCoreFile.py
trunk/test/python-tests/TestCoreUtil.py
Modified: trunk/conduit/Utils.py
==============================================================================
--- trunk/conduit/Utils.py (original)
+++ trunk/conduit/Utils.py Thu Jan 10 04:33:19 2008
@@ -8,7 +8,6 @@
License: GPLv2
"""
import sys
-import os
import os.path
import socket
import datetime
@@ -17,11 +16,6 @@
import os
import signal
import popen2
-try:
- import gnomevfs
-except ImportError:
- from gnome import gnomevfs # for maemo
-
import logging
log = logging.getLogger("Utils")
@@ -61,77 +55,6 @@
return False
#
-# URI Manipulation functions
-#
-def uri_make_canonical(uri):
- """
- Standardizes the format of the uri
- @param uri:an absolute or relative stringified uri. It might have scheme.
- """
- return gnomevfs.make_uri_canonical(uri)
-
-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)
- """
- #FIXME: This function lies, it escapes @
- #return gnomevfs.escape_host_and_path_string(uri)
- import urllib
- return urllib.quote(uri,safe='/&=:@')
-
-def uri_unescape(uri):
- """
- Replace "%xx" escapes by their single-character equivalent.
- """
- import urllib
- return urllib.unquote(uri)
-
-def uri_get_protocol(uri):
- """
- Returns the protocol (file, smb, etc) for a 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. Could use GnomeVFS for this
- is it wasnt so slow
- """
- return uri.split(os.sep)[-1]
-
-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
- """
- import string
- if filesystem in ("vfat","ntfs"):
- ILLEGAL_CHARS = "\\:*?\"<>|"
- #replace illegal chars with a space
- return uri.translate(string.maketrans(
- ILLEGAL_CHARS,
- " "*len(ILLEGAL_CHARS)))
- return uri
-
-def uri_is_folder(uri):
- """
- @returns: True if the uri is a folder and not a file
- """
- info = gnomevfs.get_file_info(uri)
- return info.type == gnomevfs.FILE_TYPE_DIRECTORY
-
-def uri_format_for_display(uri):
- """
- Formats the uri so it can be displayed to the user (strips passwords, etc)
- """
- return gnomevfs.format_uri_for_display(uri)
-
-#
# Temporary file functions
#
def new_tempfile(contents, contentsAreText=True):
@@ -266,17 +189,6 @@
username = os.environ.get("USER","")
return "%s %s" % (username, hostname)
-def open_URI(uri):
- """
- Opens a gnomevfs or xdg compatible uri.
- FIXME: Use xdg-open?
- """
- if uri == None:
- log.warn("Cannot open non-existant URI")
-
- APP = "gnome-open"
- os.spawnlp(os.P_NOWAIT, APP, APP, uri)
-
def datetime_from_timestamp(t):
"""
Makes a datetime object from a unix timestamp.
@@ -371,188 +283,6 @@
))
return VmSize,VmRSS,VmStack
-#
-# Scanner ThreadManager
-#
-class ScannerThreadManager(object):
- """
- 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, 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)
- 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 AssertionError:
- #deal with not started threads
- time.sleep(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
-
-#
-# FOLDER SCANNER
-#
-import threading
-import gobject
-import time
-
-CONFIG_FILE_NAME = ".conduit.conf"
-
-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, [])
- }
-
- def __init__(self, baseURI, includeHidden):
- threading.Thread.__init__(self)
- gobject.GObject.__init__(self)
- self.baseURI = str(baseURI)
- self.includeHidden = includeHidden
-
- 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 = uri_escape(fileinfo.name)
- if filename in [".","..",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:
- 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
-
class CommandLineConverter:
def __init__(self):
self.percentage_match = re.compile('.*')
Modified: trunk/conduit/Vfs.py
==============================================================================
--- trunk/conduit/Vfs.py (original)
+++ trunk/conduit/Vfs.py Thu Jan 10 04:33:19 2008
@@ -1,3 +1,4 @@
+import os.path
import logging
log = logging.getLogger("Vfs")
@@ -5,7 +6,111 @@
import gnomevfs
except ImportError:
from gnome import gnomevfs
+
+#
+# URI Functions
+#
+def uri_open(uri):
+ """
+ Opens a gnomevfs or xdg compatible uri.
+ """
+ if uri == None:
+ log.warn("Cannot open non-existant URI")
+ #FIXME: Use xdg-open?
+ APP = "gnome-open"
+ os.spawnlp(os.P_NOWAIT, APP, APP, uri)
+
+def uri_get_filesystem_type(uri):
+ """
+ @returns: The filesystem that uri is stored on or None if it cannot
+ be determined
+ """
+ scheme = gnomevfs.get_uri_scheme(uri)
+ if scheme == "file":
+ try:
+ path = gnomevfs.get_local_path_from_uri(uri)
+ volume = VolumeMonitor().get_volume_for_path(path)
+ return volume.get_filesystem_type()
+ except RuntimeError:
+ log.warn("Could not get local path from URI")
+ return None
+ except AttributeError:
+ log.warn("Could not determine volume for path")
+ return None
+ return None
+
+def uri_make_canonical(uri):
+ """
+ Standardizes the format of the uri
+ @param uri:an absolute or relative stringified uri. It might have scheme.
+ """
+ return gnomevfs.make_uri_canonical(uri)
+
+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)
+ """
+ #FIXME: This function lies, it escapes @
+ #return gnomevfs.escape_host_and_path_string(uri)
+ import urllib
+ return urllib.quote(uri,safe='/&=:@')
+
+def uri_unescape(uri):
+ """
+ Replace "%xx" escapes by their single-character equivalent.
+ """
+ import urllib
+ return urllib.unquote(uri)
+
+def uri_get_protocol(uri):
+ """
+ Returns the protocol (file, smb, etc) for a 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. Could use GnomeVFS for this
+ is it wasnt so slow
+ """
+ return uri.split(os.sep)[-1]
+
+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
+ """
+ import string
+ if filesystem in ("vfat","ntfs"):
+ ILLEGAL_CHARS = "\\:*?\"<>|"
+ #replace illegal chars with a space
+ return uri.translate(string.maketrans(
+ ILLEGAL_CHARS,
+ " "*len(ILLEGAL_CHARS)))
+ return uri
+
+def uri_is_folder(uri):
+ """
+ @returns: True if the uri is a folder and not a file
+ """
+ info = gnomevfs.get_file_info(uri)
+ return info.type == gnomevfs.FILE_TYPE_DIRECTORY
+
+def uri_format_for_display(uri):
+ """
+ Formats the uri so it can be displayed to the user (strips passwords, etc)
+ """
+ return gnomevfs.format_uri_for_display(uri)
+
+#
+# For monitoring locations
+#
MONITOR_EVENT_CREATED = gnomevfs.MONITOR_EVENT_CREATED
MONITOR_EVENT_CHANGED = gnomevfs.MONITOR_EVENT_CHANGED
MONITOR_EVENT_DELETED = gnomevfs.MONITOR_EVENT_DELETED
@@ -15,9 +120,6 @@
MONITOR_FILE = gnomevfs.MONITOR_FILE
MONITOR_DIRECTORY = gnomevfs.MONITOR_DIRECTORY
-class VolumeMonitor(gnomevfs.VolumeMonitor):
- pass
-
def monitor_add(folder, type, monitor_cb):
try:
return gnomevfs.monitor_add (folder, type, monitor_cb)
@@ -28,27 +130,190 @@
def monitor_cancel(monitor_id):
gnomevfs.monitor_cancel(monitor_id)
-def get_filesystem_type(uri):
+class VolumeMonitor(gnomevfs.VolumeMonitor):
+ pass
+
+#
+# Scanner ThreadManager
+#
+class FolderScannerThreadManager(object):
"""
- @returns: The filesystem that uri is stored on or None if it cannot
- be determined
+ Manages many FolderScanner threads. This involves joining and cancelling
+ said threads, and respecting a maximum num of concurrent threads limit
"""
- scheme = gnomevfs.get_uri_scheme(uri)
- if scheme == "file":
- try:
- path = gnomevfs.get_local_path_from_uri(uri)
- volume = VolumeMonitor().get_volume_for_path(path)
- return volume.get_filesystem_type()
- except RuntimeError:
- log.warn("Could not get local path from URI")
- return None
- except AttributeError:
- log.warn("Could not determine volume for path")
- return None
- return None
+ def __init__(self, maxConcurrentThreads=2):
+ self.maxConcurrentThreads = maxConcurrentThreads
+ self.scanThreads = {}
+ self.pendingScanThreadsURIs = []
+
+ def make_thread(self, folderURI, includeHidden, 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)
+ 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 AssertionError:
+ #deal with not started threads
+ time.sleep(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
+
+#
+# FOLDER SCANNER
+#
+import threading
+import gobject
+import time
+CONFIG_FILE_NAME = ".conduit.conf"
+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, [])
+ }
+
+ def __init__(self, baseURI, includeHidden):
+ threading.Thread.__init__(self)
+ gobject.GObject.__init__(self)
+ self.baseURI = str(baseURI)
+ self.includeHidden = includeHidden
+
+ 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 = uri_escape(fileinfo.name)
+ if filename in [".","..",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:
+ 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/dataproviders/File.py
==============================================================================
--- trunk/conduit/dataproviders/File.py (original)
+++ trunk/conduit/dataproviders/File.py Thu Jan 10 04:33:19 2008
@@ -6,13 +6,13 @@
import conduit.dataproviders.DataProvider as DataProvider
import conduit.datatypes as DataType
import conduit.datatypes.File as File
-import conduit.Utils as Utils
+import conduit.Vfs as Vfs
import conduit.Database as DB
TYPE_FILE = "0"
TYPE_FOLDER = "1"
-class FileSource(DataProvider.DataSource, Utils.ScannerThreadManager):
+class FileSource(DataProvider.DataSource, Vfs.FolderScannerThreadManager):
_category_ = conduit.dataproviders.CATEGORY_FILES
_module_type_ = "source"
@@ -22,7 +22,7 @@
def __init__(self):
DataProvider.DataSource.__init__(self)
- Utils.ScannerThreadManager.__init__(self)
+ Vfs.FolderScannerThreadManager.__init__(self)
#One table stores the top level files and folders (config)
#The other stores all files to sync.
@@ -180,7 +180,7 @@
def refresh(self):
DataProvider.TwoWay.refresh(self)
#scan the folder
- scanThread = Utils.FolderScanner(self.folder, self.includeHidden)
+ scanThread = Vfs.FolderScanner(self.folder, self.includeHidden)
scanThread.start()
scanThread.join()
Modified: trunk/conduit/gtkui/ConflictResolver.py
==============================================================================
--- trunk/conduit/gtkui/ConflictResolver.py (original)
+++ trunk/conduit/gtkui/ConflictResolver.py Thu Jan 10 04:33:19 2008
@@ -15,7 +15,7 @@
import conduit
import conduit.dataproviders.DataProvider as DataProvider
-import conduit.Utils as Utils
+import conduit.Vfs as Vfs
import conduit.Conflict as Conflict
from gettext import gettext as _
@@ -335,8 +335,8 @@
def on_compare_conflicts(self, sender):
model, rowref = self.view.get_selection().get_selected()
conflict = model.get_value(rowref, CONFLICT_IDX)
- Utils.open_URI(conflict.sourceData.get_open_URI())
- Utils.open_URI(conflict.sinkData.get_open_URI())
+ Vfs.uri_open(conflict.sourceData.get_open_URI())
+ Vfs.uri_open(conflict.sinkData.get_open_URI())
def on_selection_changed(self, treeSelection):
"""
Modified: trunk/conduit/modules/FileModule/FileConfiguration.py
==============================================================================
--- trunk/conduit/modules/FileModule/FileConfiguration.py (original)
+++ trunk/conduit/modules/FileModule/FileConfiguration.py Thu Jan 10 04:33:19 2008
@@ -5,6 +5,7 @@
import conduit
import conduit.Utils as Utils
+import conduit.Vfs as Vfs
import conduit.gtkui.Database as Database
import conduit.dataproviders.File as FileDataProvider
@@ -16,7 +17,7 @@
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(Utils.ScannerThreadManager):
+class _FileSourceConfigurator(Vfs.FolderScannerThreadManager):
"""
Configuration dialog for the FileTwoway dataprovider
"""
@@ -28,7 +29,7 @@
pass
def __init__(self, mainWindow, db):
- Utils.ScannerThreadManager.__init__(self)
+ Vfs.FolderScannerThreadManager.__init__(self)
self.tree = Utils.dataprovider_glade_get_widget(
__file__,
"config.glade",
@@ -77,7 +78,7 @@
for uri in selection.get_uris():
try:
log.debug("Drag recieved %s" % uri)
- if Utils.uri_is_folder(uri):
+ if Vfs.uri_is_folder(uri):
self._add_folder(uri)
else:
self._add_file(uri)
@@ -146,7 +147,7 @@
if self.model[path][GROUP_NAME_IDX] != "":
displayName = self.model[path][GROUP_NAME_IDX]
else:
- displayName = Utils.uri_format_for_display(uri)
+ displayName = Vfs.uri_format_for_display(uri)
cell_renderer.set_property("text", displayName)
cell_renderer.set_property("ellipsize", True)
@@ -240,7 +241,7 @@
if response == gtk.RESPONSE_OK:
fileURI = dialog.get_uri()
#FIXME: Returns a quoted uri string. Inconsistant with other gnomevfs methods
- #fileURI = Utils.uri_unescape(fileURI)
+ #fileURI = Vfs.uri_unescape(fileURI)
self._add_file(fileURI)
elif response == gtk.RESPONSE_CANCEL:
pass
@@ -262,7 +263,7 @@
if response == gtk.RESPONSE_OK:
folderURI = dialog.get_uri()
#FIXME: Returns a quoted uri string. Inconsistant with other gnomevfs methods
- #folderURI = Utils.uri_unescape(folderURI)
+ #folderURI = Vfs.uri_unescape(folderURI)
self._add_folder(folderURI)
elif response == gtk.RESPONSE_CANCEL:
pass
@@ -341,7 +342,7 @@
else:
self.folderGroupName = self.folderEntry.get_text()
uri = self.folderChooser.get_uri()
- self.folder = Utils.uri_make_canonical(uri)
+ self.folder = Vfs.uri_make_canonical(uri)
self.includeHidden = self.hiddenCb.get_active()
self.compareIgnoreMtime = self.mtimeCb.get_active()
Modified: trunk/test/python-tests/TestCoreFile.py
==============================================================================
--- trunk/test/python-tests/TestCoreFile.py (original)
+++ trunk/test/python-tests/TestCoreFile.py Thu Jan 10 04:33:19 2008
@@ -4,6 +4,7 @@
import conduit
import conduit.datatypes.File as File
import conduit.Utils as Utils
+import conduit.Vfs as Vfs
import os
@@ -49,7 +50,7 @@
ok("Local: 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 == Utils.uri_get_filename(i))
+ 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)
@@ -92,7 +93,7 @@
#test rebasing a remote file to local and returning its uri
lrnewer = File.File(remoteURIs[1])
- lrnewerfname = Utils.uri_get_filename(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
@@ -119,7 +120,7 @@
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 == Utils.uri_get_filename(i))
+ ok("Remote: file name = %s" % fname,fname == Vfs.uri_get_filename(i))
comp = roldest.compare(rolder)
Modified: trunk/test/python-tests/TestCoreUtil.py
==============================================================================
--- trunk/test/python-tests/TestCoreUtil.py (original)
+++ trunk/test/python-tests/TestCoreUtil.py Thu Jan 10 04:33:19 2008
@@ -21,17 +21,6 @@
ok("Test program installed finds sh", Utils.program_installed('sh'))
ok("Test program installed doesnt find foobar", Utils.program_installed('foobar') == False)
-ok("URI make canonical", Utils.uri_make_canonical("file:///foo/bar/baz/../../bar//") == "file:///foo/bar")
-
-safe = '/&=:@'
-unsafe = ' !<>#%()[]{}'
-safeunsafe = '%20%21%3C%3E%23%25%28%29%5B%5D%7B%7D'
-
-ok("Dont escape path characters",Utils.uri_escape(safe+unsafe) == safe+safeunsafe)
-ok("Unescape back to original",Utils.uri_unescape(safe+safeunsafe) == safe+unsafe)
-ok("Get protocol", Utils.uri_get_protocol("file:///foo/bar") == "file://")
-ok("Get filename", Utils.uri_get_filename("file:///foo/bar") == "bar")
-
fileuri = Utils.new_tempfile("bla").get_local_uri()
ok("New tempfile: %s" % fileuri, os.path.isfile(fileuri))
tmpdiruri = Utils.new_tempdir()
@@ -57,18 +46,6 @@
VmSize,VmRSS,VmStack = m.calculate()
ok("Memstats: size:%s rss:%s stack:%s" % (VmSize,VmRSS,VmStack), VmSize > 0 and VmRSS > 0 and VmStack > 0)
-# Test the folder scanner theading stuff
-def prog(*args): pass
-def done(*args): pass
-
-stm = Utils.ScannerThreadManager(maxConcurrentThreads=1)
-t1 = stm.make_thread("file:///tmp", False, prog, done)
-t2 = stm.make_thread("file://"+tmpdiruri, 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() == [])
-
# Test the shink command line executer
conv = Utils.CommandLineConverter()
conv.build_command("ls %s %s")
Copied: trunk/test/python-tests/TestCoreVfs.py (from r1176, /trunk/test/python-tests/TestCoreUtil.py)
==============================================================================
--- /trunk/test/python-tests/TestCoreUtil.py (original)
+++ trunk/test/python-tests/TestCoreVfs.py Thu Jan 10 04:33:19 2008
@@ -1,67 +1,27 @@
#common sets up the conduit environment
from common import *
+import conduit.Vfs as Vfs
import conduit.Utils as Utils
-import datetime
-import os.path
-
-#Test resizing an image 200wx100h
-w,h = Utils.get_proportional_resize(100,None,200,100)
-ok("Resized Image in one dimension OK", w==100 and h==50)
-w,h = Utils.get_proportional_resize(None,1000,200,100)
-ok("Resized Image in one dimension OK", w==2000 and h==1000)
-w,h = Utils.get_proportional_resize(200,1000,200,100)
-ok("Resized Image in both dimension OK", w==2000 and h==1000)
-w,h = Utils.get_proportional_resize(2000,100,200,100)
-ok("Resized Image in both dimension OK", w==2000 and h==1000)
-w,h = Utils.get_proportional_resize(10,5,200,100)
-ok("Resized Image in both dimension OK", w==10 and h==5)
-ok("Resized Image returns integers", type(w)==int and type(h)==int)
-
-ok("Test program installed finds sh", Utils.program_installed('sh'))
-ok("Test program installed doesnt find foobar", Utils.program_installed('foobar') == False)
-
-ok("URI make canonical", Utils.uri_make_canonical("file:///foo/bar/baz/../../bar//") == "file:///foo/bar")
+ok("URI make canonical", Vfs.uri_make_canonical("file:///foo/bar/baz/../../bar//") == "file:///foo/bar")
safe = '/&=:@'
unsafe = ' !<>#%()[]{}'
safeunsafe = '%20%21%3C%3E%23%25%28%29%5B%5D%7B%7D'
-ok("Dont escape path characters",Utils.uri_escape(safe+unsafe) == safe+safeunsafe)
-ok("Unescape back to original",Utils.uri_unescape(safe+safeunsafe) == safe+unsafe)
-ok("Get protocol", Utils.uri_get_protocol("file:///foo/bar") == "file://")
-ok("Get filename", Utils.uri_get_filename("file:///foo/bar") == "bar")
+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://")
+ok("Get filename", Vfs.uri_get_filename("file:///foo/bar") == "bar")
-fileuri = Utils.new_tempfile("bla").get_local_uri()
-ok("New tempfile: %s" % fileuri, os.path.isfile(fileuri))
+# Test the folder scanner theading stuff
tmpdiruri = Utils.new_tempdir()
-ok("New tempdir: %s" % tmpdiruri, os.path.isdir(tmpdiruri))
-
-ok("Unique list keep order", Utils.unique_list([1,1,2,2,3,3,5,5,4,4]) == [1,2,3,5,4])
-
-s = Utils.random_string()
-ok("Random string: %s" % s, len(s) > 0 and type(s) == str)
-s = Utils.md5_string('Foo')
-ok("md5 string: %s" % s, len(s) > 0 and type(s) == str)
-s = Utils.uuid_string()
-ok("uuid string: %s" % s, len(s) > 0 and type(s) == str)
-s = Utils.get_user_string()
-ok("user string: %s" % s, len(s) > 0 and type(s) == str)
-
-ts = 0
-dt = datetime.datetime(1970, 1, 1, 12, 0)
-ok("Datetime to unix timestamp", Utils.datetime_get_timestamp(dt) == ts)
-ok("Unix timestamp to datetime", Utils.datetime_from_timestamp(ts) == dt)
-
-m = Utils.Memstats()
-VmSize,VmRSS,VmStack = m.calculate()
-ok("Memstats: size:%s rss:%s stack:%s" % (VmSize,VmRSS,VmStack), VmSize > 0 and VmRSS > 0 and VmStack > 0)
+fileuri = Utils.new_tempfile("bla").get_local_uri()
+stm = Vfs.FolderScannerThreadManager(maxConcurrentThreads=1)
-# Test the folder scanner theading stuff
def prog(*args): pass
def done(*args): pass
-stm = Utils.ScannerThreadManager(maxConcurrentThreads=1)
t1 = stm.make_thread("file:///tmp", False, prog, done)
t2 = stm.make_thread("file://"+tmpdiruri, False, prog, done)
stm.join_all_threads()
@@ -69,11 +29,4 @@
ok("Scanned /tmp ok - found %s" % fileuri, "file://"+fileuri in t1.get_uris())
ok("Scanned %s ok (empty)" % tmpdiruri, t2.get_uris() == [])
-# Test the shink command line executer
-conv = Utils.CommandLineConverter()
-conv.build_command("ls %s %s")
-cmdok,output = conv.convert("/tmp","/dev/null",callback=None,save_output=True)
-
-ok("Command executed ok", cmdok == True and len(output) > 0)
-
finished()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]