diff options
author | 2007-07-22 03:18:22 +0000 | |
---|---|---|
committer | 2007-07-22 03:18:22 +0000 | |
commit | 856bef319c417fd6e06c3bf49ac15f8b6402ac37 (patch) | |
tree | 92db1b48e8e2b495275129ccd0e8ad3d1e0392aa | |
parent | Fever as sent by Michal (diff) | |
download | misc-856bef319c417fd6e06c3bf49ac15f8b6402ac37.tar.gz misc-856bef319c417fd6e06c3bf49ac15f8b6402ac37.tar.bz2 misc-856bef319c417fd6e06c3bf49ac15f8b6402ac37.zip |
Proof of concept for ebuilds
svn path=/fever/; revision=5
-rw-r--r-- | fever/commons.py | 7 | ||||
-rw-r--r-- | fever/ebuildversion.py | 35 | ||||
-rw-r--r-- | fever/fev.py | 30 | ||||
-rw-r--r-- | fever/fever.py | 95 |
4 files changed, 107 insertions, 60 deletions
diff --git a/fever/commons.py b/fever/commons.py index c44fcc2..7901acf 100644 --- a/fever/commons.py +++ b/fever/commons.py @@ -17,10 +17,10 @@ import urllib def unit(number): """Changes bytes unit to more legible one""" mp=1024 - prefixes="","k","M","G","T" # probably we don't need more ones :-) + prefixes="","Ki","Mi","Gi","Ti","Pi" # probably we don't need more ones :-) for (p, i) in zip(prefixes, map(lambda x: mp**x, xrange(len(prefixes)))): x=float(number)/i - if x < mp: + if x < mp or p == "Pi": return "%0.2f %sB" % (x,p) def download(url,verbose=False): @@ -75,6 +75,7 @@ def rpmvercmp(a, b): if compare != 0: return compare return cmp(len(a),len(b)) + def vercmpsort(List): """Sorting based on an rpmvercmp algorithm""" for indexes in range(len(List)-1, 0, -1): @@ -82,4 +83,4 @@ def vercmpsort(List): if rpmvercmp(List[index],List[index+1]) == 1: List[index],List[index+1]=List[index+1],List[index] List.reverse() - return List
\ No newline at end of file + return List diff --git a/fever/ebuildversion.py b/fever/ebuildversion.py new file mode 100644 index 0000000..41e8498 --- /dev/null +++ b/fever/ebuildversion.py @@ -0,0 +1,35 @@ +#!/usr/bin/python +# -*- coding: utf8 -*- + +from pkgcore.config import load_config +from pkgcore.util import repo_utils, packages as pkgutils +from pkgcore.restrictions import values, packages +from pkgcore.ebuild import atom_restricts as atom + +config = load_config() + +domain = config.get_default('domain') + +repos = repo_utils.get_raw_repos(domain.repos) + +def compareVersionsFor(package_name, latest_version): + name_restr = values.StrExactMatch(str(package_name)) + pkg_restr = packages.PackageRestriction("package",name_restr) + best_atom = None + + for repo in repos: + for pkgs in pkgutils.groupby_pkg( + repo.itermatch(pkg_restr, sorter=sorted)): + pkgs = list(pkgs) + package = max(pkgs) + best_atom = package.versioned_atom + + if best_atom: + version_matcher = atom.VersionMatch('>=', str(latest_version)) + is_latest = version_matcher.match(best_atom) + return {'best_version' : best_atom.version, + 'best_full' : best_atom.fullver, + 'is_latest' : is_latest} + else: + return {} + diff --git a/fever/fev.py b/fever/fev.py index 94b79a0..f9b3537 100644 --- a/fever/fev.py +++ b/fever/fev.py @@ -30,18 +30,18 @@ for elem in x: print notuptodate -server=xmlrpclib.Server(url) -fevbugs=server.bugzilla.runQuery({'emailreporter2': 1, 'email2': username, 'bug_status': statuses}) -descriptions=[elem['short_short_desc'] for elem in fevbugs['bugs']] -for (name, uptodate, aversion, rversion) in notuptodate: - summary=Summary % (name,aversion) - if summary in descriptions: - print "New version of %s has been already submitted" % name - continue - comment=Comment % (name, aversion, rversion) - res = server.bugzilla.createBug({"comment": comment, "short_desc": summary, - 'product': 'Fedora', 'component': name, - 'rep_platform':'All', 'bug_severity': "medium", - 'version': 'devel','op_sys':'Linux', - 'priority': 'normal', 'bug_file_loc': 'http://fedoraproject.org/wiki/Micha%C5%82Bentkowski/FEver' }, username, password) - print "Bug %s created!" % res[0] +#server=xmlrpclib.Server(url) +#fevbugs=server.bugzilla.runQuery({'emailreporter2': 1, 'email2': username, 'bug_status': statuses}) +#descriptions=[elem['short_short_desc'] for elem in fevbugs['bugs']] +#for (name, uptodate, aversion, rversion) in notuptodate: + #summary=Summary % (name,aversion) + #if summary in descriptions: + #print "New version of %s has been already submitted" % name + #continue + #comment=Comment % (name, aversion, rversion) + #res = server.bugzilla.createBug({"comment": comment, "short_desc": summary, + #'product': 'Fedora', 'component': name, + #'rep_platform':'All', 'bug_severity': "medium", + #'version': 'devel','op_sys':'Linux', + #'priority': 'normal', 'bug_file_loc': 'http://fedoraproject.org/wiki/Micha%C5%82Bentkowski/FEver' }, username, password) + #print "Bug %s created!" % res[0] diff --git a/fever/fever.py b/fever/fever.py index 5fdd690..900c390 100644 --- a/fever/fever.py +++ b/fever/fever.py @@ -4,13 +4,12 @@ # Fever - by Michał Bentkowski 2007 # licensed under GPL -# first, let's do some koji things -import koji -session=koji.ClientSession("http://koji.fedoraproject.org/kojihub") +# Adapted to Gentoo by Robert Buchholz <rbu@gentoo.org> # now, import the other things we need -from commons import download, rpmvercmp, vercmpsort +from commons import download, vercmpsort +import ebuildversion import re from xml.sax.saxutils import unescape @@ -21,43 +20,40 @@ socket.setdefaulttimeout(45) import sys class Fever: - def __init__(self, debug=0, - listformat="\* (?P<name>.*?) (?P<regex>.*) (?P<url>.*?)\n", - listlocation="http://fedoraproject.org/wiki/PackageMaintainers/FEver"): + def __init__(self, debug = 0, + listformat = "\* (?P<name>.*?) (?P<regex>.*) (?P<url>.*?)\n", + listlocation = "http://fedoraproject.org/wiki/PackageMaintainers/FEver"): + if debug >= 1: + print "Starting download of Package list" self.debug=debug - #self.listformat=listformat - #self.lislocation=listlocation - # it's sane to download a site with a list of packages at once - site=download(listlocation, debug) + # it's sane to download the site with a list of packages at once + site = download(listlocation, debug) # and let's parse it! - self.pkglist={} # this var will keep all info of packages + self.pkglist = {} # this var will keep all info of packages for package in re.finditer(listformat, site): - dict=package.groupdict() #retrieve dictionary with name regex and url - name=dict['name'] - del dict['name'] # we don't need name in dict anymore - # sometimes there are escaped chars like < in regex + #retrieve dictionary with name regex and url + dict = package.groupdict() + name = dict['name'] + # we don't need name in dict anymore + del dict['name'] + # sometimes there are escaped chars like < in regex # so we need to unescape them first - dict['regex']=unescape(dict['regex']) - self.pkglist[name]=dict - self.pkglist[name]['checked']=False + dict['regex'] = unescape(dict['regex']) + self.pkglist[name] = dict + self.pkglist[name]['checked'] = False if debug >= 2: print "%s parsed. Data: %s" % (name,dict) + if debug >= 1: + print "Finished building package list" - def getPkgSiteVersion(self,pkgname): + def getPkgSiteVersion(self, pkgname): # download a proper site and get a package version - site=download(self.pkglist[pkgname]['url'], self.debug) - regex=self.pkglist[pkgname]['regex'] - versions=vercmpsort( re.findall(regex, site) ) # find all versions and sort'em - return versions[0] # we need only the newest one - - def getPkgKojiVersion(self, pkgname): - # first, we need koji's package id - pkgid=session.getPackageID(pkgname) - # now, list all builds - builds=session.listBuilds(pkgid) - # extract all versions and sort'em - versions=vercmpsort( [x['version'] for x in session.listBuilds(pkgid)]) - return versions[0] # return the newest one + site = download(self.pkglist[pkgname]['url'], self.debug) + regex = self.pkglist[pkgname]['regex'] + # find all versions and sort'em + versions = vercmpsort(re.findall(regex, site)) + # we need only the newest one + return versions[0] def getPkgList(self): return self.pkglist @@ -72,23 +68,38 @@ class Fever: # (it may happen if there's something wrong with regex) and 1 if a package's # owner need to update his package, -1 - if error. if self.debug >= 1: - print 'Checking %s...' % pkgname + print 'Checking %s ...' % pkgname try: - sitever=self.getPkgSiteVersion(pkgname) - kojiver=self.getPkgKojiVersion(pkgname) + sitever = self.getPkgSiteVersion(pkgname) + if self.debug >= 2: + print 'Latest on site: %s' % str(sitever) + comparison_result = ebuildversion.compareVersionsFor(pkgname, sitever) + kojiver = comparison_result['best_version'] + if self.debug >= 2: + print 'Latest ebuild: %s' % str(kojiver) + is_latest = comparison_result['is_latest'] + if self.debug >= 2: + if is_latest: + print 'Is latest' + else: + print 'Needs update' + except KeyError: + if self.debug >= 1: + print "%s was not found in Gentoo." % (pkgname) + self.pkglist[pkgname]['checked']=False + return -1 except: # if no version were found, we don't need this package anymore if self.debug >= 1: - print "%s won't be checked. Error. %s" % (pkgname, str(sys.exc_info())) + print "%s won't be checked. Error. %s" % (pkgname, str(sys.exc_info()[0])) self.pkglist[pkgname]['checked']=False return -1 - if self.debug >= 2: - print '%s: koji: %s; site: %s' % (pkgname, kojiver, sitever) - compare=rpmvercmp(kojiver, sitever) self.pkglist[pkgname]['kojiver']=kojiver self.pkglist[pkgname]['sitever']=sitever self.pkglist[pkgname]['checked']=True - if compare == -1: #if a newer version's available + if self.debug >= 2: + print "" + if not is_latest: #if a newer version's available self.pkglist[pkgname]['uptodate']=False return 1 else: # if isn't @@ -100,7 +111,7 @@ class Fever: for package in self.pkglist.keys(): result=self.checkPackage(package) - def isPackageUpToDate(self,pkgname): + def isPackageUpToDate(self, pkgname): # just check if a given package is up to date return self.pkglist[pkgname]['uptodate'] |