# HG changeset patch # User Tero Marttila # Date 1244985567 -10800 # Node ID 66a01c0806f19893994a76dba3ede50f68b2bd72 # Parent 698dc68a985d53fbfd4043a9edb25bf7372db090 backout config.read_only as a useless feature diff -r 698dc68a985d -r 66a01c0806f1 degal/config.py --- a/degal/config.py Thu Jun 11 23:57:53 2009 +0300 +++ b/degal/config.py Sun Jun 14 16:19:27 2009 +0300 @@ -10,9 +10,6 @@ """ ## runtime settings - # do not modify anything - read_only = False - # the path to the gallery gallery_path = "." diff -r 698dc68a985d -r 66a01c0806f1 degal/filesystem.py --- 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. diff -r 698dc68a985d -r 66a01c0806f1 degal/main.py --- a/degal/main.py Thu Jun 11 23:57:53 2009 +0300 +++ b/degal/main.py Sun Jun 14 16:19:27 2009 +0300 @@ -18,9 +18,6 @@ parser.add_option('-G', "--gallery-path", metavar='DIR', dest='gallery_path', default=None, help="Use DIR as the Gallery path [default: CWD]") - parser.add_option('-R', "--read-only", dest='read_only', action="store_true", default=False, - help="Do not attempt to modify the gallery") - parser.add_option('-F', "--force-update", dest='force_update', action="store_true", default=False, help="--force-thumb + --force-html") @@ -50,9 +47,6 @@ if options.gallery_path : config.gallery_path = options.gallery_path - if options.read_only : - config.read_only = True - if options.force_update : config.force_html = True config.force_thumb = True diff -r 698dc68a985d -r 66a01c0806f1 degal/utils.py --- a/degal/utils.py Thu Jun 11 23:57:53 2009 +0300 +++ b/degal/utils.py Sun Jun 14 16:19:27 2009 +0300 @@ -68,15 +68,11 @@ class LazyIteratorProperty (LazyProperty) : """ - A lazy-loaded property that automatically converts an iterator/genexp into a list. + A lazy-loaded property that automatically converts an iterator/genexp into a non-mutable tuple. """ def run (self, obj) : - """ - Wrap LazyProperty.run to return a list - """ - - return list(self.func(obj)) + return tuple(self.func(obj)) lazy_load = LazyProperty lazy_load_iter = LazyIteratorProperty