teichmann@452: # -*- coding: UTF-8 -*- teichmann@452: # teichmann@452: # Copyright (C) 2010 by Intevation GmbH teichmann@452: # Authors: teichmann@452: # Sascha L. Teichmann teichmann@452: # teichmann@452: # This program is free software under the GPL (>=v2) teichmann@452: # Read the file COPYING coming with the software for details. teichmann@452: teichmann@452: from mod_python import psp teichmann@452: teichmann@452: import os teichmann@452: teichmann@452: from lxml import etree teichmann@452: teichmann@452: TREEPKG_DIR = os.path.join(os.path.dirname(__file__), "treepkgs") teichmann@452: teichmann@452: def index(req): teichmann@473: req.content_type = 'text/html;charset=utf-8' teichmann@452: template = psp.PSP(req, filename='templates/overview.html') teichmann@452: teichmann@452: descriptions = [] teichmann@452: teichmann@452: for f in os.listdir(TREEPKG_DIR): teichmann@452: d = os.path.join(TREEPKG_DIR, f) teichmann@452: if not os.path.isdir(d): continue teichmann@452: treepkg_xml = os.path.join(d, "treepkg.xml") teichmann@452: if not os.path.isfile(treepkg_xml): continue teichmann@452: xml = None teichmann@452: try: teichmann@452: xml = open(treepkg_xml, "rb") teichmann@452: dom = etree.parse(xml) teichmann@452: finally: teichmann@452: if xml: xml.close() teichmann@452: teichmann@452: description = ''.join(dom.xpath("//description/text()")) teichmann@452: teichmann@452: descriptions.append((os.path.basename(d), description)) teichmann@452: teichmann@483: template.run({ teichmann@483: 'page_title' : 'Free Software forestry', teichmann@483: 'back_link' : '/', teichmann@483: 'descriptions': descriptions teichmann@483: })