aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'g_octave')
-rw-r--r--g_octave/checksum.py10
-rw-r--r--g_octave/description.py11
-rw-r--r--g_octave/description_tree.py153
-rw-r--r--g_octave/ebuild.py10
4 files changed, 59 insertions, 125 deletions
diff --git a/g_octave/checksum.py b/g_octave/checksum.py
index 1925da9..9954129 100644
--- a/g_octave/checksum.py
+++ b/g_octave/checksum.py
@@ -34,7 +34,7 @@ def sha1_compute(filename):
def sha1_check(db, p):
'''Checks if the SHA1 checksum of the package is OK.'''
- description = db[p]
+ description = db.get(p)
manifest = {}
with open(os.path.join(config.db, 'manifest.json')) as fp:
manifest = json.load(fp)
@@ -44,9 +44,7 @@ def sha1_check(db, p):
def sha1_check_db(db):
'''Checks if the SHA1 checksums of the package database are OK.'''
- for cat in db.pkg_list:
- for pkg in db.pkg_list[cat]:
- p = pkg['name']+'-'+pkg['version']
- if not sha1_check(db, p):
- return False
+ for pkg in db:
+ if not sha1_check(db, pkg.P):
+ return False
return True
diff --git a/g_octave/description.py b/g_octave/description.py
index bb9a867..a242592 100644
--- a/g_octave/description.py
+++ b/g_octave/description.py
@@ -20,7 +20,8 @@ __all__ = [
'Description',
'SvnDescription',
're_depends',
- 're_pkg_atom'
+ 're_pkg_atom',
+ 're_desc_file',
]
import os
@@ -50,7 +51,11 @@ conf = Config()
re_depends = re.compile(r'^([a-zA-Z0-9-]+) *(\( *([><=]?=?) *([0-9.]+) *\))?')
# we'll use atoms like 'control-1.0.11' for g-octave packages
-re_pkg_atom = re.compile(r'^((.+)-([0-9.]+))\.DESCRIPTION$')
+re_pkg_atom = re.compile(r'^(.+)-([0-9.]+)$')
+
+# pattern for DESCRIPTION filenames
+re_desc_file = re.compile(r'^((.+)-([0-9.]+))\.DESCRIPTION$')
+
class Description(object):
@@ -73,7 +78,7 @@ class Description(object):
self._file = file
self._info = Info(os.path.join(conf.db, 'info.json'))
- my_atom = re_pkg_atom.match(os.path.basename(self._file))
+ my_atom = re_desc_file.match(os.path.basename(self._file))
if my_atom is not None:
self.P = my_atom.group(1)
self.PN = my_atom.group(2)
diff --git a/g_octave/description_tree.py b/g_octave/description_tree.py
index 7b27b35..299ffe1 100644
--- a/g_octave/description_tree.py
+++ b/g_octave/description_tree.py
@@ -16,22 +16,23 @@ from __future__ import absolute_import
__all__ = ['DescriptionTree']
+import glob
import os
import re
+from .config import Config
+from .description import Description
+from .log import Log
from portage.versions import vercmp
-from .config import Config, ConfigException
-from .description import *
-from .exception import DescriptionTreeException
-from .log import Log
log = Log('g_octave.description_tree')
-
config = Config()
+
# from http://wiki.python.org/moin/HowTo/Sorting/
def cmp_to_key(mycmp):
'Convert a cmp= function into a key= function'
+
class K(object):
def __init__(self, obj, *args):
self.obj = obj
@@ -47,132 +48,64 @@ def cmp_to_key(mycmp):
return mycmp(self.obj, other.obj) >= 0
def __ne__(self, other):
return mycmp(self.obj, other.obj) != 0
+
return K
-class DescriptionTree(object):
+
+class DescriptionTree(list):
def __init__(self, parse_sysreq=True):
-
log.info('Parsing the package database.')
-
- self._parse_sysreq = parse_sysreq
- self.pkg_list = {}
- self._db_path = os.path.join(config.db, 'octave-forge')
-
- if not os.path.isdir(self._db_path):
- log.error('Invalid db: %s' % self._db_path)
- raise DescriptionTreeException('Invalid db: %s' % self._db_path)
-
- self.categories = {}
- for cat in [i.strip() for i in config.categories.split(',')]:
- catdir = os.path.join(self._db_path, cat)
- if os.path.isdir(catdir):
- self.pkg_list[cat] = []
- pkgs = os.listdir(catdir)
- for pkg in pkgs:
- pkgdir = os.path.join(catdir, pkg)
- for desc_file in os.listdir(pkgdir):
- pkg_p = desc_file[:-len('.DESCRIPTION')]
- mypkg = re_pkg_atom.match(pkg_p)
- if mypkg is None:
- log.error('Invalid Atom: %s' % pkg_p)
- raise DescriptionTreeException('Invalid Atom: %s' % pkg_p)
- self.categories[mypkg.group(1)] = cat
- self.pkg_list[cat].append({
- 'name': mypkg.group(1),
- 'version': mypkg.group(2),
- })
-
-
- def __getitem__(self, key):
-
- mykey = re_pkg_atom.match(key)
- if mykey == None:
- return None
-
- name = mykey.group(1)
- version = mykey.group(2)
-
- for cat in self.pkg_list:
- for pkg in self.pkg_list[cat]:
- if pkg['name'] == name and pkg['version'] == version:
- pkgfile = os.path.join(
- self._db_path,
- cat,
- pkg['name'],
- '%s-%s.DESCRIPTION' % (pkg['name'], pkg['version']),
- )
- return Description(pkgfile, parse_sysreq=self._parse_sysreq)
-
- return None
-
+ list.__init__(self)
+ self._categories = [i.strip() for i in config.categories.split(',')]
+ for my_file in glob.glob(os.path.join(config.db, 'octave-forge', \
+ '**', '**', '*.DESCRIPTION')):
+ description = Description(my_file, parse_sysreq=parse_sysreq)
+ if description.CAT in self._categories:
+ self.append(description)
- def package_versions(self, pkgname):
-
+ def package_versions(self, pn):
tmp = []
-
- for cat in self.pkg_list:
- for pkg in self.pkg_list[cat]:
- if pkg['name'] == pkgname:
- tmp.append(pkg['version'])
-
+ for pkg in self:
+ if pkg.PN == pn:
+ tmp.append(pkg.PV)
tmp.sort(key=cmp_to_key(vercmp))
return tmp
-
- def latest_version(self, pkgname):
-
- tmp = self.package_versions(pkgname)
+ def latest_version(self, pn):
+ tmp = self.package_versions(pn)
return (len(tmp) > 0) and tmp[-1] or None
-
- def version_compare(self, versions):
-
- tmp = list(versions[:])
+ def latest_version_from_list(self, pv_list):
+ tmp = pv_list[:]
tmp.sort(key=cmp_to_key(vercmp))
return (len(tmp) > 0) and tmp[-1] or None
-
-
- def packages(self):
-
- packages = []
-
- for cat in self.pkg_list:
- for pkg in self.pkg_list[cat]:
- packages.append(pkg['name'] + '-' + pkg['version'])
-
- packages.sort()
- return packages
-
def search(self, term):
-
# term can be a regular expression
re_term = re.compile(r'%s' % term)
packages = {}
-
- for cat in self.pkg_list:
- for pkg in self.pkg_list[cat]:
- if re_term.search(pkg['name']) is not None:
- if pkg['name'] not in packages:
- packages[pkg['name']] = [pkg['version'], '9999']
- else:
- packages[pkg['name']].insert(-1, pkg['version'])
- packages[pkg['name']].sort(key=cmp_to_key(vercmp))
-
+ for pkg in self:
+ if re_term.search(pkg.PN) is not None:
+ if pkg.PN not in packages:
+ packages[pkg.PN] = []
+ packages[pkg.PN].append(pkg.PV)
+ packages[pkg.PN].sort(key=cmp_to_key(vercmp))
return packages
def list(self):
-
packages = {}
-
- for cat in self.pkg_list:
- packages[cat] = {}
- for pkg in self.pkg_list[cat]:
- if pkg['name'] not in packages[cat]:
- packages[cat][pkg['name']] = [pkg['version'], '9999']
- else:
- packages[cat][pkg['name']].insert(-1, pkg['version'])
- packages[cat][pkg['name']].sort(key=cmp_to_key(vercmp))
-
+ for category in self._categories:
+ packages[category] = {}
+ for pkg in self:
+ if pkg.PN not in packages[pkg.CAT]:
+ packages[pkg.CAT][pkg.PN] = []
+ packages[pkg.CAT][pkg.PN].append(pkg.PV)
+ packages[pkg.CAT][pkg.PN].sort(key=cmp_to_key(vercmp))
return packages
+
+ def get(self, p):
+ for pkg in self:
+ if pkg.P == p:
+ return pkg
+ return None
diff --git a/g_octave/ebuild.py b/g_octave/ebuild.py
index 4906ce2..edacc2d 100644
--- a/g_octave/ebuild.py
+++ b/g_octave/ebuild.py
@@ -56,15 +56,13 @@ class Ebuild:
self.pkgname = atom.group(1)
self.version = atom.group(2)
+ self.__desc = self.__dbtree.get('%s-%s' % (self.pkgname, self.version))
if self.__scm:
self.version = '9999'
- category = self.__dbtree.categories.get(self.pkgname, None)
- if category is not None:
- self.__desc = SvnDescription(category, self.pkgname)
+ if self.__desc is not None:
+ self.__desc = SvnDescription(self.__desc.CAT, self.pkgname)
else:
raise EbuildException('Failed to find the octave-forge category of this package.')
- else:
- self.__desc = self.__dbtree['%s-%s' % (self.pkgname, self.version)]
if self.__desc == None:
raise EbuildException('Package not found: %s' % pkg_atom)
@@ -160,7 +158,7 @@ RDEPEND="${DEPEND}
if accept_keywords is None:
accept_keywords = portage.settings['ACCEPT_KEYWORDS']
- category = self.__dbtree.categories.get(self.pkgname, '')
+ category = self.__desc.CAT
vars = {
'eutils': '',