Commits

John Mulligan committed 6509d00

real configuration file support

Comments (0)

Files changed (2)

muyhomepage2/app/build.py

         self._jenv = None
 
     def templateloader(self):
-        p = '/home/john/projects/newgenerator/skins/default'
-        loader = jinja2.FileSystemLoader(p)
+        tpath = self.templates()
+        loader = jinja2.FileSystemLoader(tpath)
         return loader
 
     def templateenv(self):
         return self._jenv
 
     def besticon(self, tags):
-        for tag, icon in self.icontags().iteritems():
+        for tag, icon in self.tagicons().iteritems():
             if tag in tags:
                 return (tag, icon)
         return None

muyhomepage2/app/configuration.py

+"""Muyhomepage configuration
+"""
+
+import os
+import vanity.configreader
 
 from muyhomepage2.pagehandlers.standard import StandardHandler
 from muyhomepage2.pagehandlers.tagsummary import TagSummaryHandler
 
     def __init__(self, filename):
         self._filename = filename
+        self.reader = vanity.configreader.ConfigReader()
+        self.reader.read(filename, require=True)
+
+    def _get(self, section, name, default=None):
+        return self.reader.get(section, name, default)
+
+    def _list(self, section):
+        return list(self.reader.items(section))
+
 
     def root(self):
-        return '.'
+        return self._get('build', 'root', '.')
 
     def destination(self):
-        return '/home/john/www/cruft/'
+        return self._get('build', 'destination', '.html')
+
+    def templates(self):
+        return self._get('build', 'templates', '.templates')
 
     def page_cache(self):
-        return '/tmp/garbage/.pcache'
+        return self._get('build', 'cache.pages', '.pagecache')
 
     def tag_cache(self):
-        return '/tmp/garbage/.tcache'
+        return self._get('build', 'cache.tags', '.tagcache')
 
     def handlers(self):
         """Return the handlers registry
         return ['tagsummary', 'tagglobal', 'atom', 'rss2', 'blog']
 
     def blog_count(self):
-        return 10
+        blog = self._get('site', 'blogcount', '10')
+        return int(blog)
 
     def feed_count(self):
-        return 20
+        feed = self._get('site', 'feedcount', '20')
+        return int(feed)
 
-    def icontags(self):
-        return {'Technology': '/~john/cruft/static/tagicon-tech.png'}
+    def tagicons(self):
+        return dict(self._list('tagicons'))
 
     def base_url(self):
-        return 'http://karnak.nile/~john/cruft'
+        return self._get('site', 'baseurl', '/')
 
     def site_author(self):
-        return 'John Mulligan'
+        return self._get('site', 'author', 'John Doe')
 
     def site_atom_id(self):
-        return 'tag:asynchrono.us,2006-01-02:birch-street-computing'
+        return self._get('site', 'feed_id', 'tag:my-site,2009-01-01:default')
 
     def atom_id_base(self):
-        return 'tag:asynchrono.us'
+        return self._get('site', 'id_base', 'tag:my-site')