Source

muyhomepage2 / muyhomepage2 / site.py

Full commit

import os
from muyhomepage2 import page
from muyhomepage2 import metadata

class Site(object):
    def __init__(self):
        self.statemap = {}
        self.tagmap = {}
        self.pages = set()

    def getpagefile(self, filename):
        for page in self.pages:
            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