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

Diff of /src/packages/gentoo.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.16.2.6

  ViewVC Help
Powered by ViewVC 1.1.20