/[gentoo]/src/packages/gentoo.py
Gentoo

Contents of /src/packages/gentoo.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download) (as text)
Sat Jun 19 15:44:52 2004 UTC (10 years, 6 months ago) by marduk
Branch: MAIN
Changes since 1.3: +3 -3 lines
File MIME type: text/x-python
Changed charset from utf-8 to iso-8859-1. This fixes #53912

1 #!/usr/bin/python -OO
2 """These functions mainly take ebuild info (grabbed from the database and
3 convert it to HTML. See the "main" function at the bottom."""
4
5 __revision__ = "$Revision: 1.3 $"
6 # $Source: /var/cvsroot/gentoo/src/packages/gentoo.py,v $
7
8 import config
9 import os
10 import time
11 import sys
12 import ebuilddb
13 import bugs
14 import changelogs
15 from cgi import escape
16 from urllib import quote
17
18 # import portage, but temporarily redirect stderr
19 if 'portage' not in dir():
20 null = open('/dev/null', 'w')
21 tmp = sys.stderr
22 sys.stderr = null
23 sys.path = ["/usr/lib/portage/pym"]+sys.path
24 import portage
25 sys.stderr = tmp
26 sys.path = sys.path[1:]
27
28 tree = portage.portdbapi('/usr/portage')
29
30 def is_masked(ebuild):
31 """Return true if ebuild is masked"""
32
33 return (not tree.visible(['%(category)s/%(name)s-%(version)s' % ebuild]))
34
35 def is_new(db, ebuild):
36 """Check for newness. An ebuild is considered new if it is the
37 only ebuild with that category/name in ebuild and it has no prevarch"""
38
39 c = db.cursor()
40 query = ('SELECT prevarch FROM ebuild WHERE category="%s" AND name="%s"'
41 % (ebuild['category'], ebuild['name']))
42 c.execute(query)
43 results = c.fetchall()
44 if len(results) == 1 and results[0][0] is None:
45 return 1
46 return 0
47
48 def changelog_to_html(changelog):
49 """HTML-ize a changelog entry"""
50 html = ""
51 for char in changelog:
52 if char == '\n':
53 html = "%s<br>" % html
54 else:
55 html = "%s%s" % (html, escape(char))
56 html = changelogs.bugs_to_html(html)
57 return html
58
59 def homepage_to_html(homepage):
60 """convert HOMEPAGE entry to HTML"""
61 if not homepage.strip():
62 return "?"
63 homepage = homepage.replace('|',' ')
64 pieces = homepage.split()
65 count = len(pieces)
66 if count == 1:
67 return ('<a class="homepage" href="%s">'
68 'Homepage</a>' % pieces[0])
69
70 html = ['[<a href="%s">%s</a>]' % (page, index + 1) for index,
71 page in enumerate(pieces)]
72 return " ".join(['<span class="homepage">Homepages'] + html +
73 ['</span>'])
74
75 def license_to_html(license):
76 """Create link to license[s]"""
77 if not license.strip(): return "?"
78 license = license.replace('|',' ')
79 pieces = license.split()
80 html = ['<a href="http://www.gentoo.org/cgi-bin/viewcvs.cgi/*checkout*/'
81 'licenses/%s">%s</a>' % (piece, piece) for piece in pieces]
82 return '<br>\n'.join(html)
83
84 def package_to_html(pkginfo, db):
85 """This function needs a database (db) connection because it performs a
86 query_to_dict on the package"""
87
88 table_begin = '<table class="ebuild">'
89 name = '<tr><td class="fields">%s</td></tr>' % pkginfo['name']
90 description = ('<tr><td class="item">'
91 '<img align="right" alt="" src="%s/%s.png">'
92 '<b>Description: </b>%s</td></tr>' % (config.ICONS,
93 pkginfo['category'], escape(pkginfo['description'])))
94 ebuilds = get_recent_releases(pkginfo, db)
95 releases = '<tr><td>%s</td></tr>' % archs_to_html(ebuilds, 'Releases')
96 #bug_string = ('<br><h3>Related bugs:</h3>\n%s'
97 # % bugs_to_html(pkginfo['name']))
98 general = '<tr><td>%s</td></tr>' % general_info_to_html(pkginfo)
99 table_end = '</table>'
100 rows = '\n\t'.join([name, description, releases, general])
101 return '\n\t'.join([table_begin, rows, table_end])
102
103 def archs_to_html(ebuilds, heading = None):
104 """Create table for availability on each architecture"""
105 heading = heading or '&nbsp;'
106 table_begin = '<table class="releases">'
107 header_row = ''.join(['<tr><td><b>%s</b></td>' % heading] +
108 ['<th class="arch">%s</th>' % i for i in config.ARCHLIST] +
109 ['</tr>']
110 )
111 rows = []
112 for ebuild in ebuilds:
113 masked = is_masked(ebuild)
114 archs = ebuild['arch'].split()
115 row_start = ('<tr>\n\t<th class="releases"><a href="%sebuilds/?%s-%s"'
116 ' title="%s">%s</a></th>\n' % (config.FEHOME,
117 ebuild['name'], ebuild['version'], ebuild['time'],
118 ebuild['version']))
119 row_data = []
120 for arch in config.ARCHLIST:
121 if arch in archs:
122 arch_string = '+'
123 elif '~%s' % arch in archs:
124 arch_string = '~'
125 else:
126 arch_string = '-'
127 if arch_string != '-' and masked:
128 arch_string = 'M' + arch_string
129 row_data.append('\t<td class="archcell" arch="%s">%s</td>'
130 % (arch_string, arch_string))
131 row_end = '</tr>'
132 rows.append('\n\t'.join([row_start] + row_data + [row_end]))
133 table_end = '</table>'
134 return '\n\t'.join([table_begin] + [header_row] + rows + [table_end])
135
136 def ebuild_to_html(ebinfo, new=0, show_bugs=0):
137 """Convert ebuild (dict) to html, if new, print out a "this is new" notice
138 if show_bugs, show bugs for this particular ebuild (requires access to
139 bugzilla"""
140 if new:
141 new_string = """ &nbsp;&nbsp;<span class="new">new!</span> """
142 else:
143 new_string = ""
144
145 table_begin = '<table class="ebuild">'
146 name_and_date = ('<tr><td class="fields">'
147 '<a href="%spackages/?category=%s;name=%s">%s</a> %s%s<br>'
148 '<span class="time">%s</span>'
149 '</td></tr>' % (config.FEHOME, quote(ebinfo['category']),
150 quote(ebinfo['name']),
151 ebinfo['name'],
152 ebinfo['version'],
153 new_string,
154 ebinfo['time'].localtime().strftime("%c %Z")))
155
156 desc_and_changes = ('<tr><td class="item" valign="top">'
157 '<img alt="" align="right" src="%simages/%s.png">'
158 '<p><b>Description:</b> %s</p>'
159 '<p><b>Changes:</b><br>'
160 '%s</p></td></tr>' % (
161 config.FEHOME,
162 ebinfo['category'],
163 escape(ebinfo['description']),
164 changelog_to_html(ebinfo['changelog'])))
165
166 archs = '<tr><td>%s</td></tr>' % archs_to_html([ebinfo])
167 general = '<tr><td>%s</td></tr>' % general_info_to_html(ebinfo)
168 table_end = '</table>'
169
170 if 1 == 1:
171 bug_string = ''
172 else:
173 bug_string = '<br><h3>Related bugs:</h3>%s' \
174 % bugs_to_html(ebinfo['name'])
175
176 return '\n\t'.join([table_begin,
177 name_and_date,
178 desc_and_changes,
179 archs,
180 general,
181 table_end,
182 bug_string])
183
184 def general_info_to_html(pkg):
185 """This actually will (should) take either a package or ebuild dict
186 as an argument"""
187
188 changelogurl = ('http://www.gentoo.org/cgi-bin/viewcvs.cgi/*checkout*/'
189 '%s/%s/ChangeLog' % (pkg['category'],pkg['name']))
190 cat_header = '<th class="category">Category</th>'
191 license_header = '<th class="license">License</th>'
192 category = ('<td class="category">'
193 '<a href="%spackages/?category=%s">%s</a></td>' % (config.FEHOME,
194 pkg['category'], pkg['category']))
195 homepage = ('<td class="homepage" rowspan="2">%s</td>'
196 % homepage_to_html(pkg['homepage']))
197 license = ('<td class="license">%s</td>'
198 % license_to_html(pkg['license']))
199 changelog = ('<td class="changelog" rowspan="2">'
200 '<a href="%s">ChangeLog</a><td>' % changelogurl)
201
202 return '\n\t'.join(['<table class="general_info">',
203 '<tr>',
204 cat_header,
205 homepage,
206 license_header,
207 changelog,
208 '</tr>',
209 '<tr>',
210 category,
211 license,
212 '</tr>',
213 '</table>'])
214
215 def bugs_to_html(package):
216 """Given package name (no version #s), return html text of bugs as
217 reported by bugzilla"""
218 # Right now we have an issue with the bugzilla site. New interface
219 # needs to be written, Bail out.
220 return ""
221 import urllib2
222 url = ('http://bugs.gentoo.org/buglist.cgi?query_format='
223 '&short_desc_type=allwords&short_desc=%s'
224 '&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED'
225 '&bug_status=REOPENED'
226 '&ctype=csv' % package)
227 fp = urllib2.urlopen(url)
228 factory = bugs.BugFactory()
229 package_bugs = factory.fromCSV(fp)
230 if package_bugs:
231 writer = bugs.HTMLWriter(package_bugs, 'bugs.gentoo.org')
232 return str(writer)
233 else:
234 return "None"
235
236 def get_most_recent(db, max=config.MAXPERPAGE, arch="", branch=""):
237 c = db.cursor()
238 extra = ''
239 if arch:
240 stable_extra = ('ebuild.arch REGEXP "^%s| %s" '
241 ' AND ebuild.prevarch NOT REGEXP"^%s| %s"'
242 % (arch,arch,arch,arch))
243 testing_extra = ('ebuild.arch REGEXP "^~%s| ~%s" '
244 ' AND ebuild.prevarch NOT REGEXP "^~%s| ~%s"'
245 % (arch,arch,arch,arch))
246 if branch == 'stable':
247 extra = ' AND (%s) ' % stable_extra
248 elif branch == 'testing':
249 extra = ' AND (%s) ' % testing_extra
250 else:
251 extra = ' AND ((%s) OR (%s)) ' % (stable_extra, testing_extra)
252 query = """SELECT ebuild.category,ebuild.name,version,when_found,description,
253 changelog,arch,homepage,license FROM ebuild,package WHERE ebuild.name=\
254 package.name AND ebuild.category=package.category %s ORDER by when_found DESC \
255 LIMIT %s""" % (extra,max)
256 c.execute(query)
257 results = c.fetchall()
258 return results
259
260 def query_to_dict(d):
261 """Convert a SQL query to a dict"""
262 einfo = {}
263 keys = ('category', 'name', 'version', 'time', 'description', 'changelog',
264 'arch', 'homepage', 'license')
265 for i in range(len(keys)):
266 try:
267 einfo[keys[i]] = d[i]
268 except IndexError:
269 continue
270 return einfo
271
272 def get_recent_releases(pkg, db, max=config.MAX_RECENT_RELEASES):
273 """Return MAX_RECENT_RELEASES most recent releases for pkg. Returns and
274 ebuild-type dict"""
275 c = db.cursor()
276 query = ('SELECT category,name,version,when_found,NULL,changelog,arch ,'
277 'NULL,NULL FROM ebuild WHERE name="%s" AND category="%s" ORDER BY '
278 'version DESC LIMIT %s' % (pkg['name'],pkg['category'],max))
279 c.execute(query)
280 results = c.fetchall()
281 #print results
282 return [ query_to_dict(i) for i in results ]
283
284 def ebuilds_to_rss(fp, ebuilds, simple=False, subtitle=""):
285 """write out ebuild info to RSS file (fp)"""
286 fp.write("""<?xml version="1.0" encoding="iso-8859-1"?>
287 <rss version="0.92">
288 <channel>
289 <title>Fresh ebuilds %s</title>
290 <link>%s</link>
291 <description>Latest ebuilds from the Gentoo Linux portage tree</description>
292 <![CDATA[<link rel="stylesheet" href="%s" type="text/css" title="styled" />]]>
293 <webMaster>www@gentoo.org</webMaster>
294 <managingEditor>marduk@gentoo.org</managingEditor>
295 <pubDate>%s</pubDate>""" % (subtitle,config.FEHOME, config.STYLESHEET,
296 time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())))
297
298 for ebuild in ebuilds:
299 if simple:
300 description = escape(ebuild['description'])
301 else:
302 description = '\n<![CDATA[\n%s\n]]>' % ebuild_to_html(ebuild)
303
304 fp.write("""<item>
305 <title>%s %s</title>
306 <link>%sebuilds/?%s-%s</link>
307 <description>
308 %s
309 </description>
310 <pubDate>%s</pubDate>
311 </item>
312 """ % (ebuild['name'],
313 ebuild['version'],
314 config.FEHOME,
315 ebuild['name'],
316 ebuild['version'],
317 description,
318 ebuild['time'].gmtime().strftime("%a, %d %b %Y %H:%M:%S +0000"))
319 )
320
321 fp.write("</channel>\n</rss>\n")
322
323 if __name__ == '__main__':
324 try:
325 if sys.argv[1] == '-g':
326 ebuilddb.main()
327 except IndexError:
328 pass
329
330 db = ebuilddb.db_connect()
331 branches = ('', 'stable', 'testing')
332 for arch in [''] + config.ARCHLIST:
333 for branch in branches:
334 fullpath = os.path.join(config.LOCALHOME, "archs", arch, branch,
335 config.INDEX)
336 index = open(fullpath,'w')
337 if arch:
338 sarch = arch
339 else:
340 sarch = 'all'
341 if branch:
342 sbranch = branch
343 else:
344 sbranch = 'all'
345
346 index.write("""<table border="0" cellpadding="0" cellspacing="5"
347 width="100%">\n""")
348 index.write("""<tr><td valign="top">\n""")
349 index.write('<!--#include file="archnav.html" -->\n\n</td></tr>\n'
350 '<tr><td>')
351 results = get_most_recent(db, arch=arch, branch=branch)
352 ebuilds = [ query_to_dict(i) for i in results ]
353 for ebuild in ebuilds:
354 new = is_new(db, ebuild)
355 pkgfilename = "%s/%s-%s.html" % (
356 config.EBUILD_FILES,ebuild['name'],ebuild['version'])
357 ebuild_html = ebuild_to_html(ebuild, new)
358 if arch == '' and branch == '':
359 pkgfile = open(pkgfilename,'w')
360 pkgfile.write(ebuild_html)
361 pkgfile.close()
362 ebuildfilename = "%s/%s/%s/%s-%s.ebuild" \
363 % (ebuilddb.config.PORTAGE_DIR,
364 ebuild['category'],ebuild['name'],ebuild['name'],
365 ebuild['version'])
366 os.system('touch -r %s %s || touch -d "today -1 year" %s'
367 % (ebuildfilename,pkgfilename,pkgfilename))
368
369 try:
370 index.write('%s\n\n' % (ebuild_html))
371 except IOError:
372 continue
373 index.write("""</table>\n""")
374 index.close()
375
376 subtitle = ' %s %s' % (arch, branch)
377 rss = open(os.path.join(config.LOCALHOME, "archs", arch, branch,
378 config.RSS), 'w')
379 ebuilds_to_rss(rss, ebuilds, simple=False, subtitle=subtitle)
380 rss.close()
381
382 rss2 = open(os.path.join(config.LOCALHOME, "archs", arch, branch,
383 config.RSS2), 'w')
384 ebuilds_to_rss(rss2, ebuilds, simple=True, subtitle=subtitle)
385 rss.close()

  ViewVC Help
Powered by ViewVC 1.1.20