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

Contents of /src/packages/gentoo.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download) (as text)
Thu Feb 19 01:49:53 2004 UTC (10 years, 5 months ago) by marduk
Branch: MAIN
Branch point for: packages_g_o
File MIME type: text/x-python
Initial revision

1 #!/usr/bin/python -OO
2
3 import config
4 import os
5 import time
6 import sys
7 import MySQLdb
8 import ebuilddb
9 import changelogs
10 from cgi import escape
11 from urllib import quote
12
13 def is_new(db,ebuild):
14 """Check for newness. An ebuild is considered new if it is the
15 only ebuild with that category/name in ebuild and it has no prevarch"""
16
17 c = db.cursor()
18 query = """SELECT prevarch FROM ebuild WHERE category="%s" AND name="%s" """ \
19 % (ebuild['category'], ebuild['name'])
20 c.execute(query)
21 results = c.fetchall()
22 if len(results) == 1 and results[0][0] is None:
23 return 1
24 return 0
25
26 def changelog_to_html(s):
27 n = ""
28 for c in s:
29 if c == '\n':
30 n = "%s<br>" % n
31 else:
32 n = "%s%s" % (n,escape(c))
33 n = changelogs.bugs_to_html(n)
34 return n
35
36 def homepage_to_html(s):
37 if not s.strip(): return "?"
38 t = s.replace('|',' ')
39 if ' ' in t:
40 pieces = t.split()
41 return ' '.join([ homepage_to_html(piece) for piece in pieces ])
42 return ("""<a href="%s"><img border="0" src="%s/home.png" width="24" height="20" alt="Home Page" title="Home Page"></a>""" % (s, config.ICONS))
43
44 def license_to_html(s):
45 if not s.strip(): return "?"
46 t = s.replace('|',' ')
47 if ' ' in t:
48 pieces = t.split()
49 return "<br>".join([ license_to_html(piece) for piece in pieces ])
50 return """<a href="http://www.gentoo.org/cgi-bin/viewcvs.cgi/*checkout*/licenses/%s">%s</a>""" % (s,s)
51
52 def package_to_html(pkginfo,db):
53 """This function needs a database (db) connection because it performs a query_to_dict
54 on the package"""
55 #colspan = len(config.ARCHLIST) + 1
56 s = """<table class="ebuild">
57 <tr><td class="fields" colspan="4">%s</td></tr>
58 <tr><td class="item" colspan="4"><p><img align="right" alt="" src="%s/%s.png">
59 <b>Description: </b>%s</p>
60 """ % (pkginfo['name'],config.ICONS,pkginfo['category'],escape(pkginfo['description']))
61 ebuilds = get_recent_releases(pkginfo,db)
62 if ebuilds:
63 s = """%s<p><b>Releases:</b></p>
64 <table class="releases"><tr><td>&nbsp;</td>""" % s
65 for i in config.ARCHLIST:
66 s = """%s<th class="arch">%s</th>""" % (s,i)
67 s = "%s</tr>\n" % s
68 for ebuild in ebuilds:
69 archs = ebuild['arch'].split()
70 s = """%s<tr><th class="releases"><a href="%sebuilds/?%s-%s" title="%s">%s</a></th>
71 """ % (s,config.FEHOME,ebuild['name'],ebuild['version'],ebuild['time'],ebuild['version'])
72 for arch in config.ARCHLIST:
73 if arch in config.ARCHLIST:
74 if arch in archs:
75 arch_string = '+'
76 title = 'marked stable for %s' % arch
77 elif '~%s' % arch in archs:
78 arch_string = '~'
79 title = 'undergoing testing for %s' % arch
80 else:
81 arch_string = '-'
82 title = 'not available for %s' % arch
83 s = """%s<td class="archcell" arch="%s" title="%s">%s</td>
84 """ % (s,arch_string,title,arch_string)
85 s = "%s</tr>" % s
86 s = "%s</table>\n" % s
87
88 s = "%s\n%s</table>" % (s,general_info_to_html(pkginfo))
89 return s
90
91 def archs_to_html(archs):
92 arch_string= '|'
93 for arch in config.ARCHLIST:
94 if arch in archs:
95 arch_icon = 'check.gif'
96 alt = ": yes"
97 title = 'marked stable for %s' % arch
98 elif '~%s' % arch in archs:
99 arch_icon = 'bug.gif'
100 alt = ': testing'
101 title = 'undergoing testing for %s' % arch
102 else:
103 arch_icon = 'no.gif'
104 alt = ': no'
105 title = 'not available for %s' % arch
106
107 arch_string = (' %s %s <img src="%simages/archs/%s" '
108 'alt="%s" title="%s"> |' % (
109 arch_string,
110 arch,
111 config.FEHOME,
112 arch_icon,
113 alt,
114 title))
115
116 return arch_string
117
118 def ebuild_to_html(ebinfo,new=0):
119 try:
120 archs = ebinfo['arch'].split()
121 except KeyError:
122 archs = ()
123 arch_string = archs_to_html(archs)
124 changelogurl = ('http://www.gentoo.org/cgi-bin/viewcvs.cgi/*checkout*/'
125 '%s/%s/ChangeLog' % (ebinfo['category'],ebinfo['name']))
126
127 if new:
128 new_string = """ &nbsp;&nbsp;<span class="new">new!</span> """
129 else:
130 new_string = ""
131
132 return ('<table class="ebuild">\n'
133 '<tr><td colspan="4" class="fields">'
134 '<a href="%spackages/?category=%s;name=%s">%s</a> %s%s<br>'
135 '<span class="time">%s</span><br>\n'
136 '</td></tr>\n'
137 '<tr><td class="item" align="center" colspan="1">'
138 '<img alt="" src="%simages/%s.png">'
139 '<td class="item" valign="top" colspan="3">'
140 '<p><b>Description:</b> %s</p>\n'
141 '<p><b>Changes:</b><br>\n'
142 '%s</p></td></tr>\n'
143 '<tr><td colspan="4" class="item"><p class="archs">%s</p>\n'
144 '</td></tr>\n'
145 '%s</table>\n'
146 '<br>\n' % (config.FEHOME,
147 quote(ebinfo['category']),
148 quote(ebinfo['name']),
149 ebinfo['name'],
150 ebinfo['version'],
151 new_string,
152 ebinfo['time'].localtime().strftime("%c %Z"),
153 config.FEHOME,
154 ebinfo['category'],
155 escape(ebinfo['description']),
156 changelog_to_html(ebinfo['changelog']),
157 arch_string,
158 general_info_to_html(ebinfo)))
159
160 def general_info_to_html(pkg):
161 """This actually will (should) take either a package or ebuild dict
162 as an argument"""
163
164 changelogurl = ('http://www.gentoo.org/cgi-bin/viewcvs.cgi/*checkout*/'
165 '%s/%s/ChangeLog' % (pkg['category'],pkg['name']))
166 return ('<tr><th class="category">Category</th>'
167 '<td class="homepage" rowspan="2">%s</td>'
168 #'<td class="homepage" rowspan="2"><a href="%s">Home Page</a></td>'
169 '<th class="license">License</th>'
170 '<td class="changelog" rowspan="2"><a href="%s">ChangeLog</a><td>\n'
171 '<tr><td class="category"><a href="%spackages/?category=%s">'
172 '%s</a></td>'
173 #'<td class="homepage"><a href="%s">Home Page</a></td>'
174 '<td class="license">%s</td></tr>\n'
175 % ( homepage_to_html(pkg['homepage']),
176 changelogurl,
177 config.FEHOME,
178 pkg['category'],
179 pkg['category'],
180 #pkg['homepage'],
181 license_to_html(pkg['license'])))
182
183 def get_most_recent(db,max=config.MAXPERPAGE,arch="",branch=""):
184 c = db.cursor()
185 extra = ''
186 if arch:
187 stable_extra = ('ebuild.arch REGEXP "^%s| %s" '
188 ' AND ebuild.prevarch NOT REGEXP"^%s| %s"'
189 % (arch,arch,arch,arch))
190 testing_extra = ('ebuild.arch REGEXP "^~%s| ~%s" '
191 ' AND ebuild.prevarch NOT REGEXP "^~%s| ~%s"'
192 % (arch,arch,arch,arch))
193 if branch == 'stable':
194 extra = ' AND (%s) ' % stable_extra
195 elif branch == 'testing':
196 extra = ' AND (%s) ' % testing_extra
197 else:
198 extra = ' AND ((%s) OR (%s)) ' % (stable_extra, testing_extra)
199 query = """SELECT ebuild.category,ebuild.name,version,when_found,description,
200 changelog,arch,homepage,license FROM ebuild,package WHERE ebuild.name=\
201 package.name AND ebuild.category=package.category %s ORDER by when_found DESC \
202 LIMIT %s""" % (extra,max)
203 c.execute(query)
204 results = c.fetchall()
205 return results
206
207 def query_to_dict(d):
208 einfo = {}
209 keys = ('category','name','version','time','description','changelog',
210 'arch','homepage','license')
211 for i in range(len(keys)):
212 try:
213 einfo[keys[i]] = d[i]
214 except IndexError:
215 continue
216 return einfo
217
218 def get_recent_releases(pkg,db,max=config.MAX_RECENT_RELEASES):
219 """Return MAX_RECENT_RELEASES most recent releases for pkg. Returns and
220 ebuild-type dict"""
221 c = db.cursor()
222 query = """SELECT category,name,version,when_found,NULL,changelog,arch ,NULL,NULL
223 FROM ebuild WHERE name="%s" AND
224 category="%s" ORDER BY when_found DESC LIMIT %s
225 """ % (pkg['name'],pkg['category'],max)
226 c.execute(query)
227 results = c.fetchall()
228 #print results
229 return [ query_to_dict(i) for i in results ]
230
231 def ebuilds_to_rss(fp,ebuilds,simple=False,subtitle=""):
232 """write out ebuild info to RSS file (fp)"""
233 fp.write("""<?xml version="1.0" encoding="utf-8"?>
234 <rss version="0.92">
235 <channel>
236 <title>Fresh ebuilds %s</title>
237 <link>%s</link>
238 <description>Latest ebuilds from the Gentoo Linux portage tree</description>
239 <webMaster>www@gentoo.org</webMaster>
240 <managingEditor>marduk@gentoo.org</managingEditor>
241 <pubDate>%s</pubDate>""" % (subtitle,config.FEHOME,
242 time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())))
243
244 for ebuild in ebuilds:
245 if simple:
246 description = escape(ebuild['description'])
247 else:
248 description = '\n<![CDATA[\n%s\n]]>' % ebuild_to_html(ebuild)
249
250 fp.write("""<item>
251 <title>%s %s</title>
252 <link>%sebuilds/?%s-%s</link>
253 <description>
254 %s
255 </description>
256 <pubDate>%s</pubDate>
257 </item>
258 """ % (ebuild['name'],
259 ebuild['version'],
260 config.FEHOME,
261 ebuild['name'],
262 ebuild['version'],
263 description,
264 ebuild['time'].gmtime().strftime("%a, %d %b %Y %H:%M:%S +0000"))
265 )
266
267 fp.write("</channel>\n</rss>\n")
268
269 if __name__ == '__main__':
270 try:
271 if sys.argv[1] == '-g':
272 ebuilddb.main()
273 except IndexError:
274 pass
275
276 db = ebuilddb.db_connect()
277 branches = ('','stable','testing')
278 for arch in [''] + config.ARCHLIST:
279 for branch in branches:
280 fullpath = os.path.join(config.LOCALHOME,"archs",arch,branch,config.INDEX)
281 index = open(fullpath,'w')
282 if arch:
283 sarch = arch
284 else:
285 sarch = 'all'
286 if branch:
287 sbranch = branch
288 else:
289 sbranch = 'all'
290
291 index.write("""<table border="0" cellpadding="0" cellspacing="5"
292 width="100%">\n""")
293 index.write("""<tr><td valign="top">\n""")
294 index.write('<!--#include file="archnav.html" -->\n\n</td></tr>\n<tr><td>')
295 results = get_most_recent(db,arch=arch,branch=branch)
296 ebuilds = [ query_to_dict(i) for i in results ]
297 for ebuild in ebuilds:
298 new = is_new(db,ebuild)
299 pkgfilename = "%s/%s-%s.html" % (
300 config.EBUILD_FILES,ebuild['name'],ebuild['version'])
301 ebuild_html = ebuild_to_html(ebuild,new)
302 if arch == '' and branch == '': # and not os.path.exists(pkgfilename):
303 pkgfile = open(pkgfilename,'w')
304 pkgfile.write(ebuild_html)
305 pkgfile.close()
306 ebuildfilename = "%s/%s/%s/%s-%s.ebuild" % (ebuilddb.config.PORTAGE_DIR,
307 ebuild['category'],ebuild['name'],ebuild['name'],
308 ebuild['version'])
309 os.system('touch -r %s %s || touch -d "today -1 year" %s' % (ebuildfilename,pkgfilename,pkgfilename))
310
311 try:
312 index.write('%s<br>\n\n\n' % (ebuild_html))
313 except IOError:
314 pass
315 #index.write('<!--#include virtual="%s/ebuilds/%s-%s.html" --><br>\n\n\n'
316 # % (config.WEBBASE,ebuild['name'],ebuild['version']))
317 #index.write("""<hr class="seperator">\n""")
318
319 index.write("""</table>\n""")
320 index.close()
321
322 subtitle = ' %s %s' % (arch,branch)
323 rss = open(os.path.join(config.LOCALHOME,"archs",arch,branch,config.RSS),'w')
324 ebuilds_to_rss(rss,ebuilds,simple=False,subtitle=subtitle)
325 rss.close()
326
327 rss2 = open(os.path.join(config.LOCALHOME,"archs",arch,branch,config.RSS2),'w')
328 ebuilds_to_rss(rss2,ebuilds,simple=True,subtitle=subtitle)
329 rss.close()

  ViewVC Help
Powered by ViewVC 1.1.20