conduit r1748 - in branches/gnome-2-24: . conduit conduit/datatypes conduit/platform scripts test/python-tests
- From: jstowers svn gnome org
- To: svn-commits-list gnome org
- Subject: conduit r1748 - in branches/gnome-2-24: . conduit conduit/datatypes conduit/platform scripts test/python-tests
- Date: Mon, 6 Oct 2008 06:47:42 +0000 (UTC)
Author: jstowers
Date: Mon Oct 6 06:47:42 2008
New Revision: 1748
URL: http://svn.gnome.org/viewvc/conduit?rev=1748&view=rev
Log:
2008-10-06 John Stowers <john stowers gmail com>
* conduit/Vfs.py:
* conduit/datatypes/File.py:
* conduit/platform/FileGio.py:
* conduit/platform/FileGnomeVfs.py:
* conduit/platform/__init__.py: Delegate uri joining to the
File implementation. This improves unicode support when using GIO.
Fixes #523181
* test/python-tests/TestCoreFile.py:
* test/python-tests/TestCoreVfs.py: Test new uri functions
* test/python-tests/common.py: Dont modifiy PYTHONPATH in tests. GIO
is the default now
Modified:
branches/gnome-2-24/ChangeLog
branches/gnome-2-24/conduit/Vfs.py
branches/gnome-2-24/conduit/datatypes/File.py
branches/gnome-2-24/conduit/platform/FileGio.py
branches/gnome-2-24/conduit/platform/FileGnomeVfs.py
branches/gnome-2-24/conduit/platform/__init__.py
branches/gnome-2-24/scripts/run-tests.sh
branches/gnome-2-24/test/python-tests/TestCoreFile.py
branches/gnome-2-24/test/python-tests/TestCoreVfs.py
Modified: branches/gnome-2-24/conduit/Vfs.py
==============================================================================
--- branches/gnome-2-24/conduit/Vfs.py (original)
+++ branches/gnome-2-24/conduit/Vfs.py Mon Oct 6 06:47:42 2008
@@ -19,6 +19,7 @@
VolumeMonitor = FileImpl.VolumeMonitor
FileMonitor = FileImpl.FileMonitor
FolderScanner = FileImpl.FolderScanner
+FileTransfer = FileImpl.FileTransferImpl
def uri_is_valid(uri):
"""
@@ -32,31 +33,19 @@
Joins multiple uri components. Performs safely if the first
argument contains a uri scheme
"""
- first = conduit.utils.ensure_string(first)
- return os.path.join(first,*rest)
+ return FileImpl.FileImpl.uri_join(first,*rest)
def uri_get_scheme(uri):
"""
@returns: The scheme (file,smb,ftp) for the uri, or None on error
"""
- try:
- scheme,path = uri.split("://")
- return scheme
- except exceptions.ValueError:
- return None
+ return FileImpl.FileImpl.uri_get_scheme(uri)
def uri_get_relative(fromURI, toURI):
"""
Returns the relative path fromURI --> toURI
"""
- fromURI = conduit.utils.ensure_string(fromURI)
- toURI = conduit.utils.ensure_string(toURI)
- rel = toURI.replace(fromURI,"")
- #strip leading /
- if rel[0] == os.sep:
- return rel[1:]
- else:
- return rel
+ return FileImpl.FileImpl.uri_get_relative(fromURI, toURI)
def uri_open(uri):
"""
Modified: branches/gnome-2-24/conduit/datatypes/File.py
==============================================================================
--- branches/gnome-2-24/conduit/datatypes/File.py (original)
+++ branches/gnome-2-24/conduit/datatypes/File.py Mon Oct 6 06:47:42 2008
@@ -129,6 +129,9 @@
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
@@ -333,6 +336,9 @@
def get_contents_as_text(self):
return self._file.get_contents()
+
+ def set_contents_as_text(self, contents):
+ return self._file.set_contents(contents)
def get_local_uri(self):
"""
Modified: branches/gnome-2-24/conduit/platform/FileGio.py
==============================================================================
--- branches/gnome-2-24/conduit/platform/FileGio.py (original)
+++ branches/gnome-2-24/conduit/platform/FileGio.py Mon Oct 6 06:47:42 2008
@@ -2,6 +2,7 @@
import conduit.platform
+import os.path
import logging
log = logging.getLogger("platform.FileGio")
@@ -97,7 +98,11 @@
return self._file.get_parse_name()
def get_contents(self):
- return self._file.load_contents()
+ contents,length,etag = self._file.load_contents()
+ return contents
+
+ def set_contents(self, contents):
+ self._file.replace_contents(contents)
def get_mimetype(self):
self._get_file_info()
@@ -189,6 +194,25 @@
except gio.Error, e:
return None
+ @staticmethod
+ def uri_join(first, *rest):
+ return os.path.join(first, *rest)
+
+ @staticmethod
+ def uri_get_relative(fromURI, toURI):
+ f = gio.File(fromURI)
+ t = gio.File(toURI)
+ res = f.get_relative_path(t)
+ #if not relative, return abs path
+ if not res:
+ res = toURI
+ return res
+
+ @staticmethod
+ def uri_get_scheme(URI):
+ f = gio.File(URI)
+ return f.get_uri_scheme()
+
class FileTransferImpl(conduit.platform.FileTransfer):
def __init__(self, source, dest):
self._source = source._file
@@ -203,7 +227,7 @@
log.info("Transfer of %s -> %s cancelled" % (self._source.get_uri(), self._dest.get_uri()))
c.cancel()
except Exception:
- log.warn("Could not call gnomevfs cancel function")
+ log.warn("Could not call transfer cancel function", exc_info=True)
return True
def set_destination_filename(self, name):
@@ -218,7 +242,8 @@
pass
def transfer(self, overwrite, cancel_func):
- self._cancel_func = cancel_func
+ if cancel_func:
+ self._cancel_func = cancel_func
if overwrite:
mode = gio.FILE_COPY_OVERWRITE
@@ -270,7 +295,7 @@
f = gio.File(dir)
enumerator = f.enumerate_children('standard::type,standard::name,standard::is-hidden,standard::is-symlink')
except gio.Error:
- log.warn("Folder %s Not found" % dir)
+ log.warn("Folder %s Not found" % dir, exc_info=True)
continue
try: fileinfo = enumerator.next()
Modified: branches/gnome-2-24/conduit/platform/FileGnomeVfs.py
==============================================================================
--- branches/gnome-2-24/conduit/platform/FileGnomeVfs.py (original)
+++ branches/gnome-2-24/conduit/platform/FileGnomeVfs.py Mon Oct 6 06:47:42 2008
@@ -6,6 +6,7 @@
import conduit.platform
import conduit.utils.Singleton as Singleton
+import os.path
import logging
log = logging.getLogger("platform.FileGnomeVfs")
@@ -121,6 +122,16 @@
def get_contents(self):
return gnomevfs.read_entire_file(self.get_text_uri())
+
+ def set_contents(self, contents):
+ if self.exists():
+ h = gnomevfs.Handle(self._URI, open_mode=gnomevfs.OPEN_WRITE)
+ else:
+ h = gnomevfs.create(self._URI, open_mode=gnomevfs.OPEN_WRITE)
+
+ h.write(contents)
+ h.close()
+ self.close()
def get_mimetype(self):
self._get_file_info()
@@ -151,10 +162,10 @@
return True
def make_directory_and_parents(self):
- exists = False
dirs = []
directory = self._URI
+ exists = gnomevfs.exists(self._URI)
while not exists:
dirs.append(directory)
directory = directory.parent
@@ -186,6 +197,30 @@
return VolumeMonitor().volume_get_fstype(path)
return None
+ @staticmethod
+ def uri_join(first, *rest):
+ first = conduit.utils.ensure_string(first)
+ return os.path.join(first,*rest)
+
+ @staticmethod
+ def uri_get_relative(fromURI, toURI):
+ fromURI = conduit.utils.ensure_string(fromURI)
+ toURI = conduit.utils.ensure_string(toURI)
+ rel = toURI.replace(fromURI,"")
+ #strip leading /
+ if rel[0] == os.sep:
+ return rel[1:]
+ else:
+ return rel
+
+ @staticmethod
+ def uri_get_scheme(uri):
+ try:
+ scheme,path = uri.split("://")
+ return scheme
+ except exceptions.ValueError:
+ return None
+
class FileTransferImpl(conduit.platform.FileTransfer):
def __init__(self, source, dest):
self._source = source._URI
@@ -198,8 +233,8 @@
if self._cancel_func():
log.info("Transfer of %s -> %s cancelled" % (info.source_name, info.target_name))
return 0
- except Exception, ex:
- log.warn("Could not call gnomevfs cancel function")
+ except Exception:
+ log.warn("Could not call transfer cancel function", exc_info=True)
return 0
return True
@@ -213,7 +248,8 @@
self._dest = self._dest.append_file_name(name)
def transfer(self, overwrite, cancel_func):
- self._cancel_func = cancel_func
+ if cancel_func:
+ self._cancel_func = cancel_func
if overwrite:
mode = gnomevfs.XFER_OVERWRITE_MODE_REPLACE
Modified: branches/gnome-2-24/conduit/platform/__init__.py
==============================================================================
--- branches/gnome-2-24/conduit/platform/__init__.py (original)
+++ branches/gnome-2-24/conduit/platform/__init__.py Mon Oct 6 06:47:42 2008
@@ -5,7 +5,7 @@
SCHEMES = ()
def __init__(self, URI):
pass
-
+
def get_text_uri(self):
raise NotImplementedError
@@ -42,6 +42,9 @@
def get_contents(self):
raise NotImplementedError
+ def set_contents(self, contents):
+ raise NotImplementedError
+
def get_mimetype(self):
raise NotImplementedError
@@ -69,6 +72,18 @@
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
Modified: branches/gnome-2-24/scripts/run-tests.sh
==============================================================================
--- branches/gnome-2-24/scripts/run-tests.sh (original)
+++ branches/gnome-2-24/scripts/run-tests.sh Mon Oct 6 06:47:42 2008
@@ -9,8 +9,6 @@
COVERAGE_APP="scripts/coverage.py"
COVERAGE_RESULTS="$BASEDIR/results/coverage"
-export PYTHONPATH=/opt/conduit/lib/python2.5/site-packages/gtk-2.0/
-
USAGE="\
Usage:\n\
./scripts/run-tests.sh [OPTIONS]\n\n\
Modified: branches/gnome-2-24/test/python-tests/TestCoreFile.py
==============================================================================
--- branches/gnome-2-24/test/python-tests/TestCoreFile.py (original)
+++ branches/gnome-2-24/test/python-tests/TestCoreFile.py Mon Oct 6 06:47:42 2008
@@ -40,6 +40,14 @@
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")
folder = File.File(os.environ["HOME"],implName=impl)
ok("Base: check if HOME exists", folder.exists() == True)
Modified: branches/gnome-2-24/test/python-tests/TestCoreVfs.py
==============================================================================
--- branches/gnome-2-24/test/python-tests/TestCoreVfs.py (original)
+++ branches/gnome-2-24/test/python-tests/TestCoreVfs.py Mon Oct 6 06:47:42 2008
@@ -75,7 +75,8 @@
)
for parts, result in URIS_TO_JOIN:
- ok("Join uri: %s" % result, Vfs.uri_join(*parts) == result)
+ got = Vfs.uri_join(*parts)
+ ok("Join uri: %s" % result, got == result)
RELATIVE_URIS = (
#from #to #relativ
@@ -83,7 +84,8 @@
( "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:
- ok("Get relative uri: %s" % result, Vfs.uri_get_relative(f,t) == result)
+ got = Vfs.uri_get_relative(f,t)
+ ok("Get relative uri: %s" % result, got == result)
VALID_URIS = (
#uri #valid
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]