move .config from filesystem to gallery/folder/image, rename degal_dir to app_dir
authorTero Marttila <terom@fixme.fi>
Wed, 01 Jul 2009 20:40:00 +0300
changeset 141 9387da0dc183
parent 140 7ea9766e33ed
child 142 2b8dfacc6d2d
move .config from filesystem to gallery/folder/image, rename degal_dir to app_dir
degal/filesystem.py
degal/folder.py
degal/gallery.py
degal/image.py
--- a/degal/filesystem.py	Wed Jul 01 20:25:35 2009 +0300
+++ b/degal/filesystem.py	Wed Jul 01 20:40:00 2009 +0300
@@ -77,7 +77,7 @@
         # this should fail for non-ASCII str
         return name.encode('utf-8')
 
-    def __init__ (self, parent, fsname=None, name=None, config=None) :
+    def __init__ (self, parent, fsname=None, name=None) :
         """
             Initialize the node with a parent and both name/fsname.
 
@@ -100,23 +100,12 @@
 
         if parent and not fsname and not name :
             # no name given -> we're the same as parent
-            self.parent, self.config, self.fsname, self.name = parent.parent, parent.config, parent.fsname, parent.name
+            self.parent, self.fsname, self.name = parent.parent, parent.fsname, parent.name
 
         else :
             # store
             self.parent = parent
             
-            # config, either as given, or copy from parent
-            if config :
-                self.config = config
-            
-            elif parent :
-                self.config = parent.config
-
-            else :
-                # XXX: no config
-                self.config = None
-     
             # fsname
             if fsname :
                 self.fsname = fsname
@@ -397,7 +386,7 @@
         The first and last nodes may be Files, but all other objects must be Directories.
 
         XXX: better to keep Paths symbolic/relative?
-        XXX: welcome to Circular Reference Hell, a place has been reserved for you
+        XXX: welcome to Circular Reference Hell
     """
 
     def __init__ (self, *nodes) :
@@ -696,14 +685,14 @@
         A special Directory that overrides the Node methods to anchor the recursion/etc at some 'real' filesystem path.
     """
 
-    # XXX: config needs a default
-    def __init__ (self, fspath, config=None) :
+    def __init__ (self, fspath) :
         """
             Construct the directory tree root at the given 'real' path, which must be a raw str
         """
 
         # abuse Node's concept of a "name" a bit
-        super(Root, self).__init__(None, fspath, config=config)
+        # XXX: this will break path manipulations, methinks
+        super(Root, self).__init__(None, fspath)
 
     def nodepath (self) :
         """
--- a/degal/folder.py	Wed Jul 01 20:25:35 2009 +0300
+++ b/degal/folder.py	Wed Jul 01 20:40:00 2009 +0300
@@ -13,7 +13,7 @@
         A Folder is a filesystem Directory that:
             * has a title/description (XXX: Page)
             * contains any number of other sub-Folders and Images.
-            * can load custom configuration for itself and sub-nodes to override the base config
+            * maintains a hierarchial Configuration that can be overrided for sub-nodes
             * holds sub-dirs for previews/thumbs
             * has a HTML view
     """
@@ -26,11 +26,22 @@
         """
 
         yield self.subfile('degal.cfg')
+    
+    def _init_config (self) :
+        """
+            Initialize .config for ourselves.
+        """
+
+        # use parent's config
+        return self.parent.config
 
     def __init__ (self, *args, **kwargs) :
         super(Folder, self).__init__(*args, **kwargs)
-
-        # find config
+        
+        # load .config
+        self.config = self._init_config()
+ 
+        # find custom config?
         for file in self.iter_config_files() :
             if file.exists() :
                 # yay! More configuration!
@@ -46,7 +57,7 @@
             # disable it so it won't be used by children
             # XXX: figure out a better way of doing this
             self.config.title = None
-    
+   
     @lazy_load
     def title (self) :
         """
--- a/degal/gallery.py	Wed Jul 01 20:25:35 2009 +0300
+++ b/degal/gallery.py	Wed Jul 01 20:40:00 2009 +0300
@@ -10,6 +10,13 @@
     """
         A Gallery is a single place in the filesystem which acts as a Folder of Images, but had some additional stuff
     """
+    
+    def _init_config (self) :
+        """
+            Keep using our given .config
+        """
+
+        return self.config
 
     def __init__ (self, path, config) :
         """
@@ -18,20 +25,24 @@
             XXX: replace path with config.gallery_path?
         """
 
-        super(Gallery, self).__init__(path, config)
+        # store config for access by Folder.__init__
+        self.config = config
+        
+        # cooperative
+        super(Gallery, self).__init__(path)
 
     @property
-    def _degal_dir (self) :
+    def _app_dir (self) :
         """
-            The dir containing the degal configuration.
+            The dir containing our application data.
         """
 
         return self.subdir('.degal')
 
     @lazy_load
-    def degal_dir (self) :
+    def app_dir (self) :
         """
-            The dir containing the degal configuration.
+            The dir containing our application data.
 
             It will be created if it does not exist.
         """
@@ -46,7 +57,7 @@
             It will be copied from internal resources if it does not exist.
         """
 
-        stylesheet = self.degal_dir.subfile('style.css')
+        stylesheet = self.app_dir.subfile('style.css')
         
         if not stylesheet.exists() :
             # load the resources dir
@@ -54,6 +65,8 @@
 
             # copy it from the static resource file
             stylesheet.copy_from(STATIC_DIR.subfile('style.css'))
+        
+        # elif stylesheet-is-older-than-resources-one: warn
 
         return stylesheet
 
--- a/degal/image.py	Wed Jul 01 20:25:35 2009 +0300
+++ b/degal/image.py	Wed Jul 01 20:40:00 2009 +0300
@@ -19,11 +19,15 @@
 
         super(Image, self).__init__(*args, **kwargs)
 
+        # use config from our folder
+        self.config = self.parent.config
+
         # links
         self.prev = None
         self.next = None
 
         # the .html file for this image
+        # XXX: keep .jpg/etc file extension?
         self.html = self.parent.subfile(self.basename + '.html')
 
         # our preview/thumbnail