diff options
author | 2004-10-17 16:53:21 +0000 | |
---|---|---|
committer | 2004-10-17 16:53:21 +0000 | |
commit | 684f192b00ca62a46ef5c7df6ce8c08a54923308 (patch) | |
tree | e994615a00afc6cd604d10d20b522c4271b367bc /src/packages | |
parent | Add "Tips & Tricks" part (diff) | |
download | gentoo-684f192b00ca62a46ef5c7df6ce8c08a54923308.tar.gz gentoo-684f192b00ca62a46ef5c7df6ce8c08a54923308.tar.bz2 gentoo-684f192b00ca62a46ef5c7df6ce8c08a54923308.zip |
Various fixes & enhancements
Diffstat (limited to 'src/packages')
-rw-r--r-- | src/packages/changelogs.py | 78 | ||||
-rw-r--r-- | src/packages/daily.py | 2 | ||||
-rw-r--r-- | src/packages/ebuilddb.py | 39 | ||||
-rw-r--r-- | src/packages/genrsslist.py | 4 | ||||
-rw-r--r-- | src/packages/gentoo.py | 46 | ||||
-rw-r--r-- | src/packages/query_ebuild.py | 9 | ||||
-rw-r--r-- | src/packages/query_package.py | 12 | ||||
-rw-r--r-- | src/packages/search.py | 9 |
8 files changed, 136 insertions, 63 deletions
diff --git a/src/packages/changelogs.py b/src/packages/changelogs.py index 53335c760b..606572429e 100644 --- a/src/packages/changelogs.py +++ b/src/packages/changelogs.py @@ -4,49 +4,49 @@ import mstring import re -BUG_REGEX = re.compile(r'#[0-9]+|bug [0-9]+',re.I) +BUG_REGEX = re.compile(r'\b#[0-9]+|\bbug [0-9]+',re.I) BUG_URL = 'http://bugs.gentoo.org/show_bug.cgi?id=' def bugs_to_html(s): - index = 1 - while 1: - match = BUG_REGEX.search(s,index) - if not match: - break - start = match.start() - end = match.end() - substring = s[start:end] - if substring[0] == '#': # this of the form "#1234" - bugid = substring[1:] - else: # this is of the form "bug 1234" - bugid = substring[4:] - url = '<a href="%s%s">%s</a>' % (BUG_URL,bugid,substring) - (s,index) = mstring.replace_sub(s,url,start,end-1) - return s + index = 1 + while 1: + match = BUG_REGEX.search(s,index) + if not match: + break + start = match.start() + end = match.end() + substring = s[start:end] + if substring[0] == '#': # this of the form "#1234" + bugid = substring[1:] + else: # this is of the form "bug 1234" + bugid = substring[4:] + url = '<a href="%s%s">%s</a>' % (BUG_URL,bugid,substring) + (s,index) = mstring.replace_sub(s,url,start,end-1) + return s def changelog(filename): - try: - #print filename - fp = open(filename,'r') - except IOError: - return "" + try: + #print filename + fp = open(filename,'r') + except IOError: + return "" - s = "" - # find first line that isn't blank or a comment - while True: - line = fp.readline() - if not line: break - #print line - if line[0] not in ['#','','\n']: - s = s + line - break - - # append next strings until you reach next "*" - while True: - line = fp.readline() - #print repr(line) - if not line or line[0] == '*': break - else: s= s + line - - return s + s = "" + # find first line that isn't blank or a comment + while True: + line = fp.readline() + if not line: break + #print line + if line[0] not in ['#','','\n']: + s = s + line + break + + # append next strings until you reach next "*" + while True: + line = fp.readline() + #print repr(line) + if not line or line[0] == '*': break + else: s= s + line + + return s diff --git a/src/packages/daily.py b/src/packages/daily.py index c1746edaae..482dd0bcd3 100644 --- a/src/packages/daily.py +++ b/src/packages/daily.py @@ -18,7 +18,7 @@ def error(): '<tr><td class="fields">Error in request</td></tr><br>\n' '<tr><td class="item"><img src="%s/?category=generic" align="right" alt="">' '<p>An error was encountered processing your request. Request a ' - 'different page or check the <a href="%s">fresh ebuilds main page</a>.' + 'different page or check the <a href="%s">packages.gentoo.org main page</a>.' '</p></td></tr>' '</table>' '</div>') % (config.ICONS,config.FEHOME) diff --git a/src/packages/ebuilddb.py b/src/packages/ebuilddb.py index c6d0453de0..3d1040c362 100644 --- a/src/packages/ebuilddb.py +++ b/src/packages/ebuilddb.py @@ -8,7 +8,15 @@ import re import changelogs import MySQLdb -FINDVER = re.compile('-[0-9]') +# import portage, but temporarily redirect stderr +if 'portage' not in dir(): + null = open('/dev/null', 'w') + tmp = sys.stderr + sys.stderr = null + sys.path = ["/usr/lib/portage/pym"]+sys.path + import portage + sys.stderr = tmp + sys.path = sys.path[1:] def db_connect(): return MySQLdb.connect(host = config.HOST, @@ -31,9 +39,14 @@ def parse_ebuild(s): s=s.split('/') parsed['category'] = s[-3] package = s[-1].split('.ebuild')[0] - pos=FINDVER.search(package).start() - parsed['name'] = package[:pos] - parsed['version'] = package[pos+1:] + pieces = portage.pkgsplit(package) + if not pieces: + return None + parsed['name'] = pieces[0] + if pieces[2] == 'r0': + parsed['version'] = pieces[1] + else: + parsed['version'] = '-'.join(pieces[1:]) return parsed @@ -66,6 +79,10 @@ def create_ebuild_record(db,ebinfo): def update_ebuild_record(db,ebinfo): c = db.cursor() escaped = dict([(x,MySQLdb.escape_string(y)) for (x,y) in ebinfo.items()]) + query="""REPLACE INTO package VALUES ("%(category)s","%(name)s",\ + "%(homepage)s","%(description)s","%(license)s");""" % escaped + c.execute(query) + query = ('UPDATE ebuild ' 'SET when_found="%(time)s",' 'arch="%(archs)s",' @@ -74,7 +91,13 @@ def update_ebuild_record(db,ebinfo): 'WHERE category="%(category)s" ' 'AND name="%(name)s" ' 'AND version="%(version)s" ' % escaped) - c.execute(query) + try: + c.execute(query) + except MySQLdb.MySQLError, data: + print 'error occurred: ' + print 'query: %s' % query + print 'error: %s' % data + def get_extended_info(ebuild): filename = os.path.join(config.PORTAGE_DIR,'metadata/cache', @@ -116,9 +139,8 @@ def main(): db = db_connect() for s in ebuilds: - try: - fields = parse_ebuild(s) - except: + fields = parse_ebuild(s) + if not fields: continue result = get_ebuild_record(db,fields) fields = get_extended_info(fields) @@ -134,7 +156,6 @@ def main(): # keywords change, update db fields['prevarch'] = result[4] update_ebuild_record(db,fields) - if __name__ == '__main__': main() diff --git a/src/packages/genrsslist.py b/src/packages/genrsslist.py index 8bd05978f4..2f7aacc3ea 100644 --- a/src/packages/genrsslist.py +++ b/src/packages/genrsslist.py @@ -3,8 +3,8 @@ import config FEHOME = config.FEHOME -print """<div class="centerpage"><H3>Fresh Ebuilds RSS Feeds</H3> -<p>Fresh Ebuilds provides the following RSS feeds. Note that some +print """<div class="centerpage"><H3>packages.gentoo.org RSS Feeds</H3> +<p>packages.gentoo.org provides the following RSS feeds. Note that some feed readers may have problems with the embedded HTML feeds.</p> </div> <br> diff --git a/src/packages/gentoo.py b/src/packages/gentoo.py index c97fa6a48a..ae8a403e7d 100644 --- a/src/packages/gentoo.py +++ b/src/packages/gentoo.py @@ -2,12 +2,13 @@ """These functions mainly take ebuild info (grabbed from the database and convert it to HTML. See the "main" function at the bottom.""" -__revision__ = "$Revision: 1.6 $" +__revision__ = "$Revision: 1.7 $" # $Source: /var/cvsroot/gentoo/src/packages/gentoo.py,v $ import config import os import time +import string import sys import ebuilddb import bugs @@ -96,6 +97,7 @@ def package_to_html(pkginfo, db): #bug_string = ('<br><h3>Related bugs:</h3>\n%s' # % bugs_to_html(pkginfo['name'])) general = '<tr><td>%s</td></tr>' % general_info_to_html(pkginfo) + similar = '<tr><td>%s</td></tr>' % create_similar_pkgs_link(pkginfo) table_end = '</table>' rows = '\n\t'.join([name, description, releases, general]) return '\n\t'.join([table_begin, rows, table_end]) @@ -105,10 +107,12 @@ def archs_to_html(ebuilds, heading = None): heading = heading or ' ' table_begin = '<table class="releases">' header_row = ''.join(['<tr><td><b>%s</b></td>' % heading] + - ['<th class="arch">%s</th>' % i for i in config.ARCHLIST] + + ['<th class="arch">%s</th>' % i.replace('-',' ') for i in config.ARCHLIST] + ['</tr>'] ) rows = [] + ebuilds.sort(cmp_ebuilds) + ebuilds.reverse() for ebuild in ebuilds: masked = is_masked(ebuild) archs = ebuild['arch'].split() @@ -197,7 +201,9 @@ def general_info_to_html(pkg): license = ('<td class="license">%s</td>' % license_to_html(pkg['license'])) changelog = ('<td class="changelog" rowspan="2">' - '<a href="%s">ChangeLog</a><td>' % changelogurl) + '<a href="%s">ChangeLog</a></td>' % changelogurl) + similar = ('<td class="similar" rowspan="2">' + '%s</td>' % create_similar_pkgs_link(pkg)) return '\n\t'.join(['<table class="general_info">', '<tr>', @@ -205,6 +211,7 @@ def general_info_to_html(pkg): homepage, license_header, changelog, + similar, '</tr>', '<tr>', category, @@ -212,6 +219,29 @@ def general_info_to_html(pkg): '</tr>', '</table>']) +def create_similar_pkgs_link(pkg): + """Create a link to similar packages""" + + def strip_chars(mystring): + newstring = '' + for char in mystring: + if char not in string.punctuation: + newstring = newstring + char + else: + newstring = newstring + ' ' + return newstring + + description = strip_chars(pkg['description'].lower()) + + words = [word for word in description.split() + if word and len(word)>2 and word not in config.EXCLUDED_FROM_SIMILAR] + words = words[:config.SIMILAR_MAX_WORDS] + [pkg['name']] + #query = ['[[:<:]]%s[[:>:]].*' % word for word in words] + query = ['[[:<:]]%s.*' % word for word in words] + query = '(%s){%s,}' % ('|'.join(query), config.SIMILAR_MIN_MATCHES) + url = '%ssearch/?sstring=%s' % (config.FEHOME, escape(query)) + return '<a href="%s">Similar Packages</a>' % url + def bugs_to_html(package): """Given package name (no version #s), return html text of bugs as reported by bugzilla""" @@ -280,13 +310,19 @@ def get_recent_releases(pkg, db, max=config.MAX_RECENT_RELEASES): results = c.fetchall() #print results return [ query_to_dict(i) for i in results ] - + +def cmp_ebuilds(a, b): + """Compare two ebuilds""" + fields_a = portage.pkgsplit('%s-%s' % (a['name'], a['version'])) + fields_b = portage.pkgsplit('%s-%s' % (b['name'], b['version'])) + return portage.pkgcmp(fields_a, fields_b) + def ebuilds_to_rss(fp, ebuilds, simple=False, subtitle=""): """write out ebuild info to RSS file (fp)""" fp.write("""<?xml version="1.0" encoding="iso-8859-1"?> <rss version="0.92"> <channel> - <title>Fresh ebuilds %s</title> + <title>packages.gentoo.org [ %s ]</title> <link>%s</link> <description>Latest ebuilds from the Gentoo Linux portage tree</description> <![CDATA[<link rel="stylesheet" href="%s" type="text/css" title="styled" />]]> diff --git a/src/packages/query_ebuild.py b/src/packages/query_ebuild.py index b64681bfbc..e6fb46785d 100644 --- a/src/packages/query_ebuild.py +++ b/src/packages/query_ebuild.py @@ -22,9 +22,12 @@ if 0: else: # let's try the database # connect - pos=ebuilddb.FINDVER.search(ebuild).start() - name = ebuild[:pos] - version = ebuild[pos+1:] + pieces = gentoo.portage.pkgsplit(ebuild) + name = pieces[0] + if pieces[2] == 'r0': + version = pieces[1] + else: + version = '-'.join(pieces[1:]) db = ebuilddb.db_connect() # query query = ('SELECT ebuild.category,ebuild.name,version,when_found,' diff --git a/src/packages/query_package.py b/src/packages/query_package.py index f78af3d940..c30f175cdc 100644 --- a/src/packages/query_package.py +++ b/src/packages/query_package.py @@ -11,6 +11,16 @@ from MySQLdb import escape_string sys.stdout.write('Content-type: text/html; charset=iso-8859-1\n\n') +def cmp_results(a, b): + """Compare results a and b""" + category_a = a[0] + category_b = b[0] + + order = cmp(category_a, category_b) + if order != 0: + return order + + def query_to_dict(q): pkginfo = {} keys = ('category','name','homepage','description','license') @@ -75,5 +85,5 @@ else: 'align="right" alt=""> <p>Information on the package you requested' ' could not be found. Be sure to check the' ' <a HREF="%s">' - 'fresh ebuilds main page</a>.</p></td></tr></table>\n' + 'packages.gentoo.org main page</a>.</p></td></tr></table>\n' '</div>' % (config.ICONS,config.FEHOME)) diff --git a/src/packages/search.py b/src/packages/search.py index 267c56741b..bc118ca12f 100644 --- a/src/packages/search.py +++ b/src/packages/search.py @@ -32,7 +32,10 @@ def query_to_dict(q): return pkginfo def write_to_cache(s): - open(cachefile,'w').write(s) + try: + open(cachefile,'w').write(s) + except IOError: + pass def sort_by_weight(a, b): """Right now we just sort based on whether the sstring is in the name""" @@ -59,7 +62,7 @@ if os.path.exists(cachefile): escaped = escape_string(sstring) query = ('SELECT category,name,homepage,description,license ' 'FROM package WHERE name REGEXP "%s" or description REGEXP "%s" ' - 'LIMIT %s,%s' + 'ORDER BY category LIMIT %s,%s' % (escaped,escaped,offset,config.MAXPERPAGE)) import ebuilddb @@ -82,7 +85,7 @@ if not results: 'align="right" alt=""> <p>I could not find any ebuild that match' ' your query. Try a different query or check the' ' <a HREF="%s">' - 'fresh ebuilds main page</a>.</p></td></tr></table>\n' + 'packages.gentoo.org main page</a>.</p></td></tr></table>\n' '</div>\n' % (config.ICONS,config.FEHOME)) sys.stdout.write(s) write_to_cache(s) |