| 1 |
#!/usr/bin/python -W ignore
|
| 2 |
|
| 3 |
#
|
| 4 |
# This Python script is:
|
| 5 |
# (C) 2007-2008, David Paleino <d.paleino@gmail.com>,
|
| 6 |
# Andreas Tille <tille@debian.org>
|
| 7 |
#
|
| 8 |
# It is licensed under the terms of GNU General Public License (GPL)
|
| 9 |
# v3, or any later revision.
|
| 10 |
#
|
| 11 |
|
| 12 |
import apt
|
| 13 |
import apt_pkg
|
| 14 |
import apt_inst
|
| 15 |
import HTMLTemplate
|
| 16 |
import re
|
| 17 |
from sys import argv, exit, stderr
|
| 18 |
import time
|
| 19 |
from datetime import datetime
|
| 20 |
from email.Utils import formatdate
|
| 21 |
|
| 22 |
from cddtasktools import CddDependencies, HTMLBASE, REPOS
|
| 23 |
|
| 24 |
CDD='debian-med'
|
| 25 |
|
| 26 |
###
|
| 27 |
# Template handlers
|
| 28 |
###
|
| 29 |
|
| 30 |
# Do not Encode our strings - we do it ourself and want to take over responsiblity
|
| 31 |
# for Links etc.
|
| 32 |
def myEncoder(txt):
|
| 33 |
# Used to HTML-encode value in 'node.content = value'.
|
| 34 |
return txt
|
| 35 |
|
| 36 |
# Do not Decode our strings - we do it ourself and want to take over responsiblity
|
| 37 |
# for Links etc.
|
| 38 |
def myDecoder(txt):
|
| 39 |
# Used to HTML-encode value in 'node.content = value'.
|
| 40 |
return txt
|
| 41 |
|
| 42 |
|
| 43 |
def renderIndex(node, tasks):
|
| 44 |
node.tasks.repeat(renderTaskList, tasks)
|
| 45 |
t = datetime.now()
|
| 46 |
node.date.content = formatdate(time.mktime(t.timetuple()))
|
| 47 |
|
| 48 |
def renderTaskList(node, task):
|
| 49 |
node.task.raw = """<a href="%s.php" name="%s" id="%s">%s</a>""" % (task, task, task, task.capitalize())
|
| 50 |
|
| 51 |
def renderTasks(node, task, packages, details):
|
| 52 |
global cdeps
|
| 53 |
|
| 54 |
node.task.content = details['Task']
|
| 55 |
node.shortdesc.content = details['ShortDesc']
|
| 56 |
node.heading.content = details['ShortDesc']
|
| 57 |
node.longdesc.content = details['LongDesc']
|
| 58 |
|
| 59 |
t = datetime.now()
|
| 60 |
node.date.content = formatdate(time.mktime(t.timetuple()))
|
| 61 |
|
| 62 |
official = cdeps.GetNamesOnlyDict(('official',))
|
| 63 |
# for deppkg in cdeps.tasks[task].dependencies['official']:
|
| 64 |
node.official_head.raw = """<h2>
|
| 65 |
<a id="official-debs" name="official-debs"></a>
|
| 66 |
Official Debian packages
|
| 67 |
</h2>"""
|
| 68 |
# HTML_Template wants a list as argument so we provide a list of indizes to address
|
| 69 |
# the list of DependantPackage instances inside renderOfficial
|
| 70 |
list_of_dependencies = cdeps.GetListOfDepsForTask(task, dependencytypes=('official',))
|
| 71 |
node.official.repeat(renderOfficial,
|
| 72 |
range(len(list_of_dependencies)))
|
| 73 |
|
| 74 |
# if task in todo:
|
| 75 |
# error = True
|
| 76 |
# else:
|
| 77 |
# error = False
|
| 78 |
|
| 79 |
unofficial = cdeps.GetNamesOnlyDict(('unofficial',))
|
| 80 |
list_of_dependencies = cdeps.GetListOfDepsForTask(task, dependencytypes=('unofficial',))
|
| 81 |
if len(list_of_dependencies) > 0:
|
| 82 |
node.unofficial_head.raw = """<h2>
|
| 83 |
<a id="unofficial-debs" name="unofficial-debs"></a>
|
| 84 |
Experimental or unofficial Debian packages
|
| 85 |
</h2>"""
|
| 86 |
node.unofficial.repeat(renderUnofficial, range(len(list_of_dependencies)))
|
| 87 |
# error = False
|
| 88 |
|
| 89 |
prospective = cdeps.GetNamesOnlyDict(('prospective',))
|
| 90 |
list_of_dependencies = cdeps.GetListOfDepsForTask(task, dependencytypes=('prospective',))
|
| 91 |
if len(list_of_dependencies) > 0:
|
| 92 |
node.unavailable_head.raw = """<h2>
|
| 93 |
<a id="debs-not-available" name="debs-not-available"></a>
|
| 94 |
Debian packages not available
|
| 95 |
</h2>"""
|
| 96 |
node.unavailable.repeat(renderProspective, range(len(list_of_dependencies)))
|
| 97 |
# error = False
|
| 98 |
|
| 99 |
# if error:
|
| 100 |
# The package probably needs a proper prospective entry in the
|
| 101 |
# task files. Write it to stdout.
|
| 102 |
# print "Error: problems with %s" % task
|
| 103 |
|
| 104 |
def renderOfficial(node, package_no):
|
| 105 |
# Here we parse just official packages
|
| 106 |
deppkg = cdeps.tasks[task].dependencies['official'][package_no]
|
| 107 |
|
| 108 |
node.shortdesc.content = deppkg.pkgShortDesc
|
| 109 |
node.project.raw = "<table class=\"project\" summary=\"%s\">" % deppkg.pkg
|
| 110 |
node.anchor.atts['name'] = deppkg.pkg
|
| 111 |
node.anchor.atts['id'] = deppkg.pkg
|
| 112 |
node.name.content = deppkg.pkg.capitalize()
|
| 113 |
node.url.atts['href'] = deppkg.homepage
|
| 114 |
if deppkg.homepage == "#":
|
| 115 |
node.url.content = "Homepage not available"
|
| 116 |
else:
|
| 117 |
node.url.content = deppkg.homepage
|
| 118 |
|
| 119 |
node.longdesc.raw = deppkg.pkgLongDesc
|
| 120 |
node.version.content = "Version: %s" % deppkg.version
|
| 121 |
if deppkg.license != None:
|
| 122 |
node.license.content = "License: %s" % deppkg.license
|
| 123 |
# In case some '&' made it up to this place
|
| 124 |
node.pkgurl.atts['href'] = deppkg.pkgURL ## .replace("&", "%26")
|
| 125 |
node.pkgurl.content = "Official Debian package"
|
| 126 |
node.deburl.atts['href'] = deppkg.filename
|
| 127 |
#~ node.deburl.content = "X" ### TODO: add a nice icon here to download the .deb package
|
| 128 |
node.deburl.raw = "<img src=\"/img/deb-icon.png\" />"
|
| 129 |
if deppkg.responsible:
|
| 130 |
node.responsible.content = deppkg.responsible
|
| 131 |
else:
|
| 132 |
node.responsible.raw = "no one"
|
| 133 |
|
| 134 |
|
| 135 |
def renderUnofficial(node, package_no):
|
| 136 |
# Here we parse just unofficial packages
|
| 137 |
deppkg = cdeps.tasks[task].dependencies['unofficial'][package_no]
|
| 138 |
|
| 139 |
node.shortdesc.content = deppkg.pkgShortDesc
|
| 140 |
node.longdesc.raw = deppkg.pkgLongDesc
|
| 141 |
node.project.raw = "<table class=\"project\" summary=\"%s\">" % deppkg.pkg
|
| 142 |
node.anchor.atts['name'] = deppkg.pkg
|
| 143 |
node.anchor.atts['id'] = deppkg.pkg
|
| 144 |
node.name.content = deppkg.pkg.capitalize()
|
| 145 |
node.url.atts['href'] = deppkg.homepage
|
| 146 |
node.url.content = deppkg.homepage
|
| 147 |
node.license.content = "License: %s" % deppkg.license
|
| 148 |
# In case some '&' made it up to this place
|
| 149 |
node.pkgurl.atts['href'] = deppkg.pkgURL ## .replace("&", "%26")
|
| 150 |
node.pkgurl.content = "Unofficial Debian package"
|
| 151 |
if deppkg.responsible:
|
| 152 |
node.responsible.content = deppkg.responsible
|
| 153 |
else:
|
| 154 |
node.responsible.raw = "no one"
|
| 155 |
|
| 156 |
# Let's try to get the version from the package name
|
| 157 |
# (following Debian standards: <name>_<ver>_<arch>.deb)
|
| 158 |
regex = ".*/%s_(?P<version>.*)_.*\.deb$" % deppkg.pkg
|
| 159 |
p = re.compile(regex)
|
| 160 |
m = p.search(deppkg.pkgURL)
|
| 161 |
if m:
|
| 162 |
node.version.content = "Version: %s" % m.group("version")
|
| 163 |
else:
|
| 164 |
node.version.content = "Version: N/A"
|
| 165 |
|
| 166 |
|
| 167 |
def renderProspective(node, package_no):
|
| 168 |
# Parsing unavailable packages :(
|
| 169 |
# PACKAGE THEM! :)
|
| 170 |
deppkg = cdeps.tasks[task].dependencies['prospective'][package_no]
|
| 171 |
|
| 172 |
if deppkg.pkgShortDesc:
|
| 173 |
node.shortdesc.content = deppkg.pkgShortDesc
|
| 174 |
else:
|
| 175 |
node.shortdesc.content = "N/A"
|
| 176 |
if deppkg.pkgLongDesc:
|
| 177 |
node.longdesc.content = deppkg.pkgLongDesc
|
| 178 |
else:
|
| 179 |
node.longdesc.content = "N/A"
|
| 180 |
node.longdesc.raw = deppkg.pkgLongDesc
|
| 181 |
node.project.raw = "<table class=\"project\" summary=\"%s\">" % deppkg.pkg
|
| 182 |
if deppkg.responsible:
|
| 183 |
node.responsible.content = deppkg.responsible
|
| 184 |
else:
|
| 185 |
node.responsible.raw = "no one"
|
| 186 |
if deppkg.wnpp:
|
| 187 |
node.wnpp.raw = " — <a href=\"http://bugs.debian.org/%s\">wnpp</a>" % deppkg.wnpp
|
| 188 |
node.anchor.atts['name'] = deppkg.pkg
|
| 189 |
node.anchor.atts['id'] = deppkg.pkg
|
| 190 |
node.name.content = deppkg.pkg.capitalize()
|
| 191 |
if deppkg.homepage:
|
| 192 |
node.url.atts['href'] = deppkg.homepage
|
| 193 |
node.url.content = deppkg.homepage
|
| 194 |
else:
|
| 195 |
node.url.atts['href'] = "#"
|
| 196 |
node.url.content = "N/A"
|
| 197 |
if deppkg.license:
|
| 198 |
node.license.raw = "<?=_('License')?>: %s" % deppkg.license
|
| 199 |
else:
|
| 200 |
node.license.raw = "<?=_('License')?>: N/A"
|
| 201 |
|
| 202 |
if len(argv) <= 1 :
|
| 203 |
print >>stderr, "Warning: No CDD name given as command line argument. Using %s." % CDD
|
| 204 |
else:
|
| 205 |
if argv[1] not in REPOS.keys():
|
| 206 |
print >>stderr, "Unknown CDD name: %s. Don't know what to do." % CDD
|
| 207 |
exit(-1)
|
| 208 |
CDD = argv[1]
|
| 209 |
|
| 210 |
cdeps=CddDependencies(CDD)
|
| 211 |
cdeps.GetAllDependencies()
|
| 212 |
|
| 213 |
base=HTMLBASE + '/' + CDD
|
| 214 |
# Let's render the Tasks Page index, first
|
| 215 |
f = open("%s/htdocs/tasks_idx.tmpl" % base)
|
| 216 |
tmpl = HTMLTemplate.Template(renderIndex, f.read(), codecs=(None,None)) ##myEncoder, myDecoder))
|
| 217 |
f.close()
|
| 218 |
f = open("%s/static/tasks/index.php" % base, "w")
|
| 219 |
|
| 220 |
tasks = cdeps.tasknames
|
| 221 |
packages = cdeps.GetNamesOnlyDict()
|
| 222 |
task_details = cdeps.GetTaskDescDict()
|
| 223 |
|
| 224 |
f.write(tmpl.render(tasks))
|
| 225 |
f.close()
|
| 226 |
|
| 227 |
# Let's render single pages now.
|
| 228 |
f = open("%s/htdocs/tasks.tmpl" % base)
|
| 229 |
tmpl = HTMLTemplate.Template(renderTasks, f.read())
|
| 230 |
f.close()
|
| 231 |
|
| 232 |
for task in tasks:
|
| 233 |
f = open("%s/static/tasks/%s.php" % (base, task), "w")
|
| 234 |
|
| 235 |
# This is to avoid useless <br>eaks before closing the cell
|
| 236 |
source = tmpl.render(task, packages[task], task_details[task])
|
| 237 |
f.write(re.sub(r"<br /><br />[ ]*</td>", "</td>", source))
|
| 238 |
|
| 239 |
f.close()
|
| 240 |
|