conduit r1209 - in trunk: . conduit conduit/datatypes conduit/modules/N800Module test/python-tests
- From: jstowers svn gnome org
- To: svn-commits-list gnome org
- Subject: conduit r1209 - in trunk: . conduit conduit/datatypes conduit/modules/N800Module test/python-tests
- Date: Sun, 13 Jan 2008 12:17:30 +0000 (GMT)
Author: jstowers
Date: Sun Jan 13 12:17:29 2008
New Revision: 1209
URL: http://svn.gnome.org/viewvc/conduit?rev=1209&view=rev
Log:
Wrap more uri functions in Vfs.py and use them in N800Module
Modified:
trunk/ChangeLog
trunk/conduit/Vfs.py
trunk/conduit/datatypes/File.py
trunk/conduit/modules/N800Module/N800Module.py
trunk/test/python-tests/TestCoreVfs.py
Modified: trunk/conduit/Vfs.py
==============================================================================
--- trunk/conduit/Vfs.py (original)
+++ trunk/conduit/Vfs.py Sun Jan 13 12:17:29 2008
@@ -10,6 +10,12 @@
#
# URI Functions
#
+def uri_join(*args):
+ """
+ Joins multiple uri components
+ """
+ return os.path.join(*args)
+
def uri_open(uri):
"""
Opens a gnomevfs or xdg compatible uri.
@@ -117,6 +123,31 @@
except Exception, err:
print err
return False
+
+def uri_make_directory_and_parents(uri):
+ """
+ Because gnomevfs.make_dir does not perform as mkdir -p this function
+ is required to make a heirarchy of directories.
+
+ @param uri: A directory that does not exist
+ @type uri: str
+ """
+ exists = False
+ dirs = []
+
+ directory = gnomevfs.URI(uri)
+ while not exists:
+ dirs.append(directory)
+ directory = directory.parent
+ exists = gnomevfs.exists(directory)
+
+ dirs.reverse()
+ for d in dirs:
+ log.debug("Making directory %s" % d)
+ gnomevfs.make_directory(
+ d,
+ gnomevfs.PERM_USER_ALL | gnomevfs.PERM_GROUP_READ | gnomevfs.PERM_GROUP_EXEC | gnomevfs.PERM_OTHER_READ | gnomevfs.PERM_OTHER_EXEC
+ )
#
# For monitoring locations
Modified: trunk/conduit/datatypes/File.py
==============================================================================
--- trunk/conduit/datatypes/File.py (original)
+++ trunk/conduit/datatypes/File.py Sun Jan 13 12:17:29 2008
@@ -11,7 +11,8 @@
from gnome import gnomevfs # for maemo
import conduit
-from conduit.datatypes import DataType
+import conduit.datatypes.DataType as DataType
+import conduit.Vfs as Vfs
class File(DataType.DataType):
@@ -100,29 +101,6 @@
else:
log.warn("Cannot get info on non-existant file %s" % self.URI)
- def _make_directory_and_parents(self, directory):
- """
- Because gnomevfs.make_dir does not perform as mkdir -p this function
- is required to make a heirarchy of directories.
-
- @param directory: A directory that does not exist
- @type directory: gnomevfs.URI
- """
- exists = False
- dirs = []
- while not exists:
- dirs.append(directory)
- directory = directory.parent
- exists = gnomevfs.exists(directory)
-
- dirs.reverse()
- for d in dirs:
- log.debug("Making directory %s" % d)
- gnomevfs.make_directory(
- d,
- gnomevfs.PERM_USER_ALL | gnomevfs.PERM_GROUP_READ | gnomevfs.PERM_GROUP_EXEC | gnomevfs.PERM_OTHER_READ | gnomevfs.PERM_OTHER_EXEC
- )
-
def _defer_rename(self, filename):
"""
In the event that the file is on a read-only volume this call defers the
@@ -309,9 +287,9 @@
log.debug("Transfering File %s -> %s" % (self.URI, newURI))
#recursively create all parent dirs if needed
- parent = newURI.parent
+ parent = str(newURI.parent)
if not gnomevfs.exists(parent):
- self._make_directory_and_parents(parent)
+ Vfs.uri_make_directory_and_parents(parent)
#Copy the file
result = gnomevfs.xfer_uri(
Modified: trunk/conduit/modules/N800Module/N800Module.py
==============================================================================
--- trunk/conduit/modules/N800Module/N800Module.py (original)
+++ trunk/conduit/modules/N800Module/N800Module.py Sun Jan 13 12:17:29 2008
@@ -6,7 +6,6 @@
Copyright 2007: Jaime Frutos Morales, John Stowers
License: GPLv2
"""
-import os.path
import logging
log = logging.getLogger("modules.N800")
@@ -18,6 +17,7 @@
import conduit.dataproviders.DataProviderCategory as DataProviderCategory
import conduit.dataproviders.File as FileDataProvider
import conduit.Exceptions as Exceptions
+import conduit.Vfs as Vfs
from gettext import gettext as _
@@ -61,7 +61,7 @@
def __init__(self, mount, udi, folder):
FileDataProvider.FolderTwoWay.__init__(self,
- folder,
+ "file://"+folder,
"N800",
False,
False
@@ -92,10 +92,10 @@
dialog.run()
def refresh(self):
- if not os.path.exists(self.folder):
+ if not Vfs.uri_exists(self.folder):
try:
- os.mkdir(self.folder)
- except OSError:
+ Vfs.uri_make_directory_and_parents(self.folder)
+ except:
raise Exceptions.RefreshError("Error Creating Directory")
FileDataProvider.FolderTwoWay.refresh(self)
@@ -129,7 +129,7 @@
self,
mount=args[0],
udi=args[1],
- folder=os.path.join(args[0],self.DEFAULT_FOLDER)
+ folder=Vfs.uri_join(args[0],self.DEFAULT_FOLDER)
)
def configure(self, window):
@@ -155,7 +155,7 @@
self,
mount=args[0],
udi=args[1],
- folder=os.path.join(args[0],self.DEFAULT_FOLDER)
+ folder=Vfs.uri_join(args[0],self.DEFAULT_FOLDER)
)
self.encodings = Audio.PRESET_ENCODINGS.copy()
self.encoding = "ogg"
@@ -179,7 +179,7 @@
self,
mount=args[0],
udi=args[1],
- folder=os.path.join(args[0],self.DEFAULT_FOLDER)
+ folder=Vfs.uri_join(args[0],self.DEFAULT_FOLDER)
)
self.encodings = Video.PRESET_ENCODINGS.copy()
self.encoding = "ogg"
@@ -203,7 +203,7 @@
self,
mount=args[0],
udi=args[1],
- folder=os.path.join(args[0],self.DEFAULT_FOLDER)
+ folder=Vfs.uri_join(args[0],self.DEFAULT_FOLDER)
)
self.encodings = Photo.PRESET_ENCODINGS.copy()
#Add size = 800x480 to the default photo encodings
Modified: trunk/test/python-tests/TestCoreVfs.py
==============================================================================
--- trunk/test/python-tests/TestCoreVfs.py (original)
+++ trunk/test/python-tests/TestCoreVfs.py Sun Jan 13 12:17:29 2008
@@ -17,8 +17,12 @@
ok("/home exists", Vfs.uri_exists("/home") == True)
ok("/foo/bar does not exist", Vfs.uri_exists("/foo/bar") == False)
-# Test the folder scanner theading stuff
tmpdiruri = Utils.new_tempdir()
+newtmpdiruri = Vfs.uri_join(tmpdiruri, "foo", "bar", "baz")
+Vfs.uri_make_directory_and_parents(newtmpdiruri)
+ok("Made directory and parents: %s" % newtmpdiruri, Vfs.uri_exists(newtmpdiruri) == True)
+
+# Test the folder scanner theading stuff
fileuri = Utils.new_tempfile("bla").get_local_uri()
stm = Vfs.FolderScannerThreadManager(maxConcurrentThreads=1)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]