degal/filesystem.py
changeset 109 66a01c0806f1
parent 97 92c20f8b297f
child 117 a2e4562deaab
--- a/degal/filesystem.py	Thu Jun 11 23:57:53 2009 +0300
+++ b/degal/filesystem.py	Sun Jun 14 16:19:27 2009 +0300
@@ -211,7 +211,7 @@
     @lazy_load
     def _stat (self) :
         """
-            Cached OS-level stats.
+            Cached low-level stat.
 
             Returns None on ENOENT (node doesn't exist).
         """
@@ -300,7 +300,7 @@
         """
 
         if not self.exists() :
-            raise Exception("Filesystem node does not exist: %s" % self)
+            raise NodeErrno(self, errno.ENOENT)
 
         return self
     
@@ -343,22 +343,18 @@
         return self.unicodepath
     
     def __repr__ (self) :
-        """
-            Returns a str representing this dir
-        """
-
         return "Node(%r, %r)" % (self.parent.path, self.fsname)
     
     def __eq__ (self, other) :
         """
-            Compare for equality
+            A Node is equal if compared to another node that shares the same name, and the parents are also equal.
         """
 
         return isinstance(other, Node) and self.name == other.name and self.parent == other.parent
 
     def __cmp__ (self, other) :
         """
-            Arbitrary comparisons between Nodes
+            Compare two Nodes or with None. This does not support comparisons with other kinds of objects.
             
             >>> cmp(Node(None, 'foo'), Node(None, 'foo'))
             0
@@ -396,6 +392,8 @@
         Each node must either be the parent or the child of the following node.
 
         The first and last nodes may be Files, but all other objects must be Directories.
+
+        XXX: better to keep Paths symbolic/relative?
     """
 
     def __init__ (self, *nodes) :
@@ -554,13 +552,8 @@
     def open (self, mode='r', encoding=None, errors=None, bufsize=None) :
         """
             Wrapper for open/codecs.open.
-
-            Raises an error if read_only mode is set and mode contains any of 'wa+'
         """
 
-        if self.config.read_only and any((c in mode) for c in 'wa+') :
-            raise Exception("Unable to open file for %s due to read_only mode: %s" % (mode, self))
-
         if encoding :
             return codecs.open(self.path, mode, encoding, errors, bufsize)
 
@@ -578,14 +571,9 @@
         """
             Replace this file with a copy of the given file with default permissions.
 
-            Raises an error if read_only mode is set.
-
             XXX: accept mode
         """
 
-        if self.config.read_only :
-            raise Exception("Not copying file as read_only mode is set: %s -> %s" % (file, self))
-        
         # perform the copy
         shutil.copyfile(file.path, self.path)
 
@@ -620,8 +608,7 @@
         """
             Returns a Directory object representing the name underneath this dir.
 
-            If the create option is given, the directory will be created if it does not exist. Note that this will
-            raise an error if read_only mode is set
+            If the create option is given, the directory will be created if it does not exist.
         """
 
         subdir = Directory(self, name=name)
@@ -653,15 +640,9 @@
         """
             Create this directory with default permissions.
 
-            This will fail if read_only mode is set
-            
             XXX: mode argument
         """
         
-        if self.config.read_only :
-            # forbidden
-            raise Exception("Unable to create dir due to read_only mode: %s" % self)
-        
         # do it
         os.mkdir(self.path)
 
@@ -703,37 +684,6 @@
         # build using parent root_path
         return os.path.join('..', self.parent.root_path)
  
-    def children (self) :
-        """
-            Yield a series of Node subclasses representing the items in this dir.
-            
-            This uses self.NODE_TYPES to figure out what kind of sub-node object to build. This should be a list of
-                (test_func, node_type)
-
-            tuples, of which the first is a function that takes a Node as it's sole argument, and returns a boolean.
-            For the first test_func which returns True, a Node-subclass object is constructed using node_type.from_node.
-
-            XXX: never used
-        """
-
-        for node in self :
-            # figure out what type to use
-            for test_func, node_type in self.NODE_TYPES :
-                if test_func(node) :
-                    # matches, build
-                    yield node_type.from_node(node)
-
-            else :
-                # unknown file type!
-                raise Exception("unrecongized type of file: %s" % node);
-
-# assign default Directory.NODE_TYPES
-Directory.NODE_TYPES = [
-    (Node.is_dir,   Directory),
-    (Node.is_file,  File),
-]
-
-
 class Root (Directory) :
     """
         A special Directory that overrides the Node methods to anchor the recursion/etc at some 'real' filesystem path.