--- a/degal/filesystem.py Fri Jun 05 23:02:30 2009 +0300
+++ b/degal/filesystem.py Fri Jun 05 23:02:47 2009 +0300
@@ -349,6 +349,13 @@
else :
return open(self.path, mode, bufsize)
+ def open_write (self, encoding=None, errors=None, bufsize=None) :
+ """
+ Open for write using open('w').
+ """
+
+ return self.open('w', encoding, errors, bufsize)
+
def copy_from (self, file) :
"""
Replace this file with a copy of the given file with default permissions.
@@ -381,14 +388,42 @@
"""
subdir = Directory(self, name=name)
-
- # try and mkdir?
+
if create and not subdir.is_dir() :
# create it!
subdir.mkdir()
- return subdir
+ return dir
+ def test_subdir (self, name, create=False) :
+ """
+ Test for the presence of a subdir with the given name, and possibly return it, or None.
+
+ Returns a (exists, created, dir) tuple.
+
+ XXX: ugly, not used
+ """
+
+ subdir = Directory(self, name=name)
+
+ # already exists?
+ if subdir.is_dir() :
+ if create :
+ # create it!
+ subdir.mkdir()
+
+ # didn't exist, did create
+ return True, True, subdir
+
+ else :
+ # doesn't exist, don't create
+ return False, False, subdir
+
+ else :
+ # already existing
+ return True, False, subdir
+
+
def subfile (self, name) :
"""
Returns a File object representing the name underneath this dir