Commits

John Mulligan committed 79050d8

it generates and caches stuff

Comments (0)

Files changed (7)

muyhomepage2/app/build.py

 
 def build(config):
     website = site.Site()
+    website.pages = site.read_site_pages(config.page_cache())
     rebuild = set()
+    cached = [p.filename for p in website.pages]
     for pagefile in page.walkpages(config.root()):
-        if pagefile not in (p.filename for p in website.pages):
+        if pagefile not in cached:
             npage = page.parse(pagefile)
             rebuild.add(npage)
             website.pages.add(npage)
         if spage.action in config.always_rebuild():
             rebuild.add(page.parse(spage.filename))
     compile_pages(config, website, rebuild)
+    site.write_site_pages(website, config.page_cache())
 
 
 def compile_pages(config, website, rebuild):
 
 
 def compile_page(config, website, pctx):
-    print 'XXX', pctx.page.filename
+    print 'Building:', pctx.page.title
     tname = pctx.template()
     scope = dict(current=pctx, site=website, config=config)
     template = config.templateloader().load(config.templateenv(), tname)

muyhomepage2/app/configuration.py

     def destination(self):
         return '/tmp/garbage'
 
+    def page_cache(self):
+        return '/tmp/garbage/.pcache'
+
+    def tag_cache(self):
+        return '/tmp/garbage/.tcache'
+
     def handlers(self):
         """Return the handlers registry
         """

muyhomepage2/metadata.py

 """metadata functions
 """
 
+import urllib
+
 
 def writepagecache(data, fp):
-    pass
+    for (filename, ccode, title, action) in data:
+        parts = [filename, ccode, title, action]
+        parts = [p or '.' for p in parts]
+        parts = [urllib.quote(p) for p in parts]
+        fp.write('%s\n' % ' '.join(parts))
 
 
 def readpagecache(fp):
-    pass
+    def _unquote(value):
+        if value == '.':
+            return ''
+        else:
+            return urllib.unquote(value)
+    for line in fp:
+        parts = line.split()
+        assert len(parts) == 4
+        yield tuple([_unquote(p) for p in parts])
 
 
 def writetagcache(data, fp):

muyhomepage2/page.py

 
     @property
     def contentcode(self):
-        util.contentcode(self.filename)
+        return util.contentcode(self.filename)
 
 
 class PseduoPage(object):

muyhomepage2/pagehandlers/handler.py

         raise NotImplementedError('PageHandler.content')
 
     def finalname(self):
+        if 'x-force-file-name' in self.page.headers:
+            return self.page.headers['x-force-file-name']
         return '%s.html' % util.encodetitle(self.page.title)
 
     def template(self):

muyhomepage2/site.py

 
+import os
+from muyhomepage2 import page
+from muyhomepage2 import metadata
 
 class Site(object):
     def __init__(self):
             if page.filename == filename:
                 return page
         raise KeyError(filename)
+
+
+def write_site_pages(wsite, filename):
+    pdata = ((p.filename, p.contentcode, p.title, p.action)
+            for p in wsite.pages)
+    fp = open(filename, 'w')
+    try:
+        metadata.writepagecache(pdata, fp)
+    finally:
+        fp.close()
+
+def read_site_pages(filename):
+    pages = set()
+    if not os.path.isfile(filename):
+        return pages
+    fp = open(filename)
+    try:
+        for fn, ccode, title, action in metadata.readpagecache(fp):
+            pages.add(page.PseduoPage(fn, ccode, title, action))
+    finally:
+        fp.close()
+    return pages

muyhomepage2/util.py

 """
 
 import string
+from hashlib import md5
 
 
 def encodetitle(title):
     """Create a simplified title string.
     """
     permitted = string.letters + string.digits + ':'
+    eliminate = "'"
     temp = []
     for ch in title.lower():
         if ch in permitted:
             temp.append(ch)
-        elif temp[-1] == '-':
+        elif temp[-1] == '-' or ch in eliminate:
             pass
         else:
             temp.append('-')