conduit r1703 - in trunk: . conduit/datatypes conduit/modules conduit/platform conduit/utils test/python-tests
- From: jstowers svn gnome org
- To: svn-commits-list gnome org
- Subject: conduit r1703 - in trunk: . conduit/datatypes conduit/modules conduit/platform conduit/utils test/python-tests
- Date: Fri, 29 Aug 2008 23:40:48 +0000 (UTC)
Author: jstowers
Date: Fri Aug 29 23:40:48 2008
New Revision: 1703
URL: http://svn.gnome.org/viewvc/conduit?rev=1703&view=rev
Log:
* conduit/datatypes/File.py:
* conduit/modules/ConverterModule.py:
* conduit/platform/FileGio.py:
* conduit/platform/FileGnomeVfs.py:
* conduit/utils/__init__.py:
* test/python-tests/TestCoreFile.py: Implement make_directory_and_parents
in python because it is not wrapped yet. Add tests for this, make_directory
and delete.
Modified:
trunk/ (props changed)
trunk/ChangeLog
trunk/conduit/datatypes/File.py
trunk/conduit/modules/ConverterModule.py
trunk/conduit/platform/FileGio.py
trunk/conduit/platform/FileGnomeVfs.py
trunk/conduit/utils/__init__.py
trunk/test/python-tests/TestCoreFile.py
Modified: trunk/conduit/datatypes/File.py
==============================================================================
--- trunk/conduit/datatypes/File.py (original)
+++ trunk/conduit/datatypes/File.py Fri Aug 29 23:40:48 2008
@@ -187,14 +187,14 @@
"""
Makes a directory with the default permissions.
"""
- self._file.make_directory()
+ return self._file.make_directory()
def make_directory_and_parents(self):
"""
Makes a directory and all parents up till the root. Equivilent
to mkdir -p
"""
- self._file.make_directory_and_parents()
+ return self._file.make_directory_and_parents()
def force_new_filename(self, filename):
"""
@@ -444,12 +444,12 @@
"""
Creates a file in the system temp directory with the given contents.
"""
- def __init__(self, contents=""):
+ def __init__(self, contents, **kwargs):
#create the file containing contents
fd, name = tempfile.mkstemp(prefix="conduit")
os.write(fd, contents)
os.close(fd)
- File.__init__(self, name)
+ File.__init__(self, name, **kwargs)
log.debug("New tempfile created at %s" % name)
class ProxyFile(File):
Modified: trunk/conduit/modules/ConverterModule.py
==============================================================================
--- trunk/conduit/modules/ConverterModule.py (original)
+++ trunk/conduit/modules/ConverterModule.py Fri Aug 29 23:40:48 2008
@@ -224,9 +224,7 @@
return setting
def setting_to_file(self, setting):
- f = File.TempFile(
- self._to_text(setting)
- )
+ f = File.TempFile(self._to_text(setting))
f.force_new_filename(setting.key.replace("/","_"))
f.force_new_file_extension(".txt")
return f
@@ -281,9 +279,7 @@
return bookmark
def bookmark_to_file(self, bookmark):
- f = File.TempFile(
- self._to_text(bookmark)
- )
+ f = File.TempFile(self._to_text(bookmark))
f.force_new_filename(bookmark.title.replace("/","_"))
f.force_new_file_extension(".txt")
return f
Modified: trunk/conduit/platform/FileGio.py
==============================================================================
--- trunk/conduit/platform/FileGio.py (original)
+++ trunk/conduit/platform/FileGio.py Fri Aug 29 23:40:48 2008
@@ -58,18 +58,20 @@
def set_mtime(self, timestamp=None, datetime=None):
try:
self._file.set_attribute_uint64(
- "time::changed",
+ "time::modified",
long(timestamp)
)
+ self.close()
return timestamp
- except gio.Error:
+ except gio.Error, e:
return None
def set_filename(self, filename):
try:
self._file = self._file.set_display_name(filename)
+ self.close()
return filename
- except gio.Error:
+ except gio.Error, e:
return None
def get_mtime(self):
@@ -110,6 +112,64 @@
self.fileExists = False
self.triedOpen = False
+ def make_directory(self):
+ try:
+ result = self._file.make_directory()
+ self.close()
+ return result
+ except gio.Error, e:
+ return False
+
+ def make_directory_and_parents(self):
+ #recursively create all parent dirs if needed
+ #port the code from gio into python until the following is fixed
+ #http://bugzilla.gnome.org/show_bug.cgi?id=546575
+ dirs = []
+
+ try:
+ result = self._file.make_directory()
+ code = 0;
+ except gio.Error, e:
+ result = False
+ code = e.code
+
+ work_file = self._file
+ while code == gio.ERROR_NOT_FOUND and not result:
+ parent_file = work_file.get_parent()
+ if not parent_file:
+ break
+
+ try:
+ result = parent_file.make_directory()
+ code = 0;
+ except gio.Error, e:
+ result = False
+ code = e.code
+
+ if code == gio.ERROR_NOT_FOUND and not result:
+ dirs.append(parent_file)
+
+ work_file = parent_file;
+
+ #make all dirs in reverse order
+ dirs.reverse()
+ for d in dirs:
+ try:
+ result = d.make_directory()
+ except gio.Error:
+ result = False
+ break
+
+ #make the final dir
+ if result:
+ try:
+ result = self._file.make_directory()
+ except gio.Error:
+ result = False
+
+ self.close()
+ return result
+
def is_on_removale_volume(self):
try:
return self._file.find_enclosing_mount().can_unmount()
@@ -168,13 +228,13 @@
log.debug("Transfering File %s -> %s (overwrite: %s)" % (self._source.get_uri(), self._dest.get_uri(), overwrite))
#recursively create all parent dirs if needed
- #http://bugzilla.gnome.org/show_bug.cgi?id=546575
- #
- #recursively create all parent dirs if needed
- #parent = str(self._dest.parent)
- #if not gnomevfs.exists(parent):
- # d = FileImpl(None, impl=self._dest.parent)
- # d.make_directory_and_parents()
+ parent = self._dest.get_parent()
+ try:
+ parent.query_info("standard::name")
+ except gio.Error, e:
+ #does not exists
+ d = FileImpl(None, impl=parent)
+ d.make_directory_and_parents()
#Copy the file
#http://bugzilla.gnome.org/show_bug.cgi?id=546601
Modified: trunk/conduit/platform/FileGnomeVfs.py
==============================================================================
--- trunk/conduit/platform/FileGnomeVfs.py (original)
+++ trunk/conduit/platform/FileGnomeVfs.py Fri Aug 29 23:40:48 2008
@@ -143,11 +143,12 @@
self.triedOpen = False
def make_directory(self):
- uri = _ensure_type(uri)
gnomevfs.make_directory(
self.get_text_uri(),
gnomevfs.PERM_USER_ALL | gnomevfs.PERM_GROUP_READ | gnomevfs.PERM_GROUP_EXEC | gnomevfs.PERM_OTHER_READ | gnomevfs.PERM_OTHER_EXEC
)
+ self.close()
+ return True
def make_directory_and_parents(self):
exists = False
Modified: trunk/conduit/utils/__init__.py
==============================================================================
--- trunk/conduit/utils/__init__.py (original)
+++ trunk/conduit/utils/__init__.py Fri Aug 29 23:40:48 2008
@@ -108,7 +108,7 @@
#
# Temporary file functions
#
-def new_tempfile(contents, contentsAreText=True):
+def new_tempfile(contents, **kwargs):
"""
Returns a new File onject, which has been created in the
system temporary directory, and that has been filled with
@@ -117,13 +117,10 @@
The file is closed when it is returned
@param contents: The data to write into the file
- @param contentsAreText: Indicates to the OS if the file is text (as opposed
- to a binary type file
- @param contentsAreText: C{bool}
@returns: a L{conduit.datatypes.File}
"""
import conduit.datatypes.File as File
- return File.TempFile(contents)
+ return File.TempFile(contents, **kwargs)
def new_tempdir():
"""
Modified: trunk/test/python-tests/TestCoreFile.py
==============================================================================
--- trunk/test/python-tests/TestCoreFile.py (original)
+++ trunk/test/python-tests/TestCoreFile.py Fri Aug 29 23:40:48 2008
@@ -11,6 +11,7 @@
import datetime
import tempfile
+#for impl in ("GIO",):
for impl in ("GIO","GnomeVfs"):
ok("--- TESTING FILE IMPL: %s" % impl, True)
@@ -23,15 +24,22 @@
ok("Base: non-existant file", null.exists() == False)
#test tempfile handling
- temp = Utils.new_tempfile(Utils.random_string())
- ok("Detected tempfile", temp.is_local() and temp._is_tempfile())
+ 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("Tempfile in temp dir", uri and uri.startswith(tempfile.gettempdir()))
+ ok("Base: Tempfile in temp dir", uri and uri.startswith(tempfile.gettempdir()))
temp.delete()
gone = File.File(uri,implName=impl)
- ok("Delete tempfile", not gone.exists())
+ 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)
+
folder = File.File(os.environ["HOME"],implName=impl)
ok("Base: check if HOME exists", folder.exists() == True)
@@ -76,10 +84,10 @@
#test the handling of weird characters and transferring files to unusual paths
tmpdir = Utils.new_tempdir()
- f1 = Utils.new_tempfile(Utils.random_string())
+ 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())
+ 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)
@@ -161,7 +169,7 @@
ok("Remote file exists", f.exists() == True)
#make another local file
- local = Utils.new_tempfile(Utils.random_string())
+ local = Utils.new_tempfile(Utils.random_string(), implName=impl)
#save the old information
fOldName = f.get_filename()
@@ -240,6 +248,27 @@
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)
+
+
+
finished()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]