From d0c6e156e471287ae0aa33150b01bba60362db57 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Thu, 9 Dec 2010 23:22:27 -0200 Subject: fixed a bunch of tests --- g_octave/checksum.py | 6 +++++- g_octave/description_tree.py | 34 +++++++++++++--------------------- g_octave/ebuild.py | 23 ++++++++--------------- g_octave/log.py | 2 +- g_octave/overlay.py | 23 ++++++++++------------- 5 files changed, 37 insertions(+), 51 deletions(-) (limited to 'g_octave') diff --git a/g_octave/checksum.py b/g_octave/checksum.py index 7a55499..22e47d2 100644 --- a/g_octave/checksum.py +++ b/g_octave/checksum.py @@ -24,12 +24,16 @@ import json import os from .config import Config +from .compat import py3k config = Config() def sha1_compute(filename): with open(filename) as fp: - return sha1(fp.read()).hexdigest() + content = fp.read() + if py3k: + content = bytes(content, 'utf-8') + return sha1(content).hexdigest() def sha1_check(db, p): description = db[p] diff --git a/g_octave/description_tree.py b/g_octave/description_tree.py index b719a5a..e65f8b0 100644 --- a/g_octave/description_tree.py +++ b/g_octave/description_tree.py @@ -27,6 +27,8 @@ 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' @@ -49,25 +51,20 @@ def cmp_to_key(mycmp): class DescriptionTree(object): - def __init__(self, conf=None, parse_sysreq=True): + def __init__(self, parse_sysreq=True): log.info('Parsing the package database.') self._parse_sysreq = parse_sysreq self.pkg_list = {} - - if conf is None: - conf = Config() - self._config = conf - - self._db_path = os.path.join(conf.db, 'octave-forge') + 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 conf.categories.split(',')]: + 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] = [] @@ -78,14 +75,13 @@ class DescriptionTree(object): pkg_p = desc_file[:-len('.DESCRIPTION')] mypkg = re_pkg_atom.match(pkg_p) if mypkg is None: - log.error('Invalid Atom: %s' % mypkg) - raise DescriptionTreeException('Invalid Atom: %s' % mypkg) - if not parse_sysreq: - self.categories[mypkg.group(1)] = cat - self.pkg_list[cat].append({ - 'name': mypkg.group(1), - 'version': mypkg.group(2), - }) + 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): @@ -106,11 +102,7 @@ class DescriptionTree(object): pkg['name'], '%s-%s.DESCRIPTION' % (pkg['name'], pkg['version']), ) - return Description( - pkgfile, - conf = self._config, - parse_sysreq = self._parse_sysreq - ) + return Description(pkgfile, parse_sysreq=self._parse_sysreq) return None diff --git a/g_octave/ebuild.py b/g_octave/ebuild.py index f6eacef..0c5a780 100644 --- a/g_octave/ebuild.py +++ b/g_octave/ebuild.py @@ -33,6 +33,7 @@ import subprocess from portage.versions import vercmp +config = Config() out = portage.output.EOutput() # validating keywords (based on the keywords from the sci-mathematics/octave package) @@ -40,19 +41,12 @@ re_keywords = re.compile(r'(~)?(alpha|amd64|hppa|ppc64|ppc|sparc|x86)') class Ebuild: - def __init__(self, pkg_atom, force=False, scm=False, conf=None, pkg_manager=None): + def __init__(self, pkg_atom, force=False, scm=False, pkg_manager=None): self.__scm = scm self.__force = force - self.__conf = conf self.__pkg_manager = pkg_manager - - if conf is None: - conf = Config() - - self._config = conf - - self.__dbtree = DescriptionTree(conf = self._config) + self.__dbtree = DescriptionTree() atom = re_pkg_atom.match(pkg_atom) if atom == None: @@ -84,7 +78,7 @@ class Ebuild: def create(self, display_info=True, accept_keywords=None, manifest=True, nodeps=False): my_ebuild = os.path.join( - self._config.overlay, + config.overlay, 'g-octave', '%s' % self.pkgname, '%s-%s.ebuild' % (self.pkgname, self.version) @@ -115,7 +109,7 @@ class Ebuild: def __create(self, accept_keywords=None, manifest=True): - ebuild_path = os.path.join(self._config.overlay, 'g-octave', self.pkgname) + ebuild_path = os.path.join(config.overlay, 'g-octave', self.pkgname) ebuild_file = os.path.join(ebuild_path, '%s-%s.ebuild' % (self.pkgname, self.version)) metadata_file = os.path.join(ebuild_path, 'metadata.xml') @@ -193,8 +187,8 @@ RDEPEND="${DEPEND} # WOW, we have patches :( - patchesdir = os.path.join(self._config.db, 'patches') - filesdir = os.path.join(self._config.overlay, 'g-octave', self.pkgname, 'files') + patchesdir = os.path.join(config.db, 'patches') + filesdir = os.path.join(config.overlay, 'g-octave', self.pkgname, 'files') if not os.path.exists(filesdir): os.makedirs(filesdir, 0o755) @@ -270,7 +264,7 @@ RDEPEND="${DEPEND} def __search_patches(self): - patches_dir = os.path.join(self._config.db, 'patches') + patches_dir = os.path.join(config.db, 'patches') if not os.path.exists(patches_dir): return [] @@ -317,7 +311,6 @@ RDEPEND="${DEPEND} Ebuild( ebuild, force = self.__force, - conf = self.__conf, pkg_manager = self.__pkg_manager, scm = self.__scm ).create() diff --git a/g_octave/log.py b/g_octave/log.py index b0c3010..2473bc0 100644 --- a/g_octave/log.py +++ b/g_octave/log.py @@ -4,7 +4,7 @@ log.py ~~~~~~ - a simple Python module to deal with g-octave logging stuff. + A simple Python module to deal with g-octave logging stuff. :copyright: (c) 2010 by Rafael Goncalves Martins :license: GPL-2, see LICENSE for more details. diff --git a/g_octave/overlay.py b/g_octave/overlay.py index 6433f2f..49984f3 100644 --- a/g_octave/overlay.py +++ b/g_octave/overlay.py @@ -23,33 +23,30 @@ import portage.output from .config import Config, ConfigException from .compat import open +config = Config() out = portage.output.EOutput() -def create_overlay(force=False, conf=None, quiet=False): +def create_overlay(force=False, quiet=False): - # the function parameter conf is used by the tests - if conf is None: - conf = Config() + if force and os.path.exists(config.overlay): + shutil.rmtree(config.overlay) - if force and os.path.exists(conf.overlay): - shutil.rmtree(conf.overlay) - - if not os.path.exists(os.path.join(conf.overlay, 'profiles', 'repo_name')): + if not os.path.exists(os.path.join(config.overlay, 'profiles', 'repo_name')): if not quiet: - out.ebegin('Creating overlay: %s' % conf.overlay) + out.ebegin('Creating overlay: %s' % config.overlay) try: # creating dirs for _dir in ['profiles', 'eclass']: - dir = os.path.join(conf.overlay, _dir) + dir = os.path.join(config.overlay, _dir) if not os.path.exists(dir) or force: os.makedirs(dir, 0o755) # creating files files = { - os.path.join(conf.overlay, 'profiles', 'repo_name'): 'g-octave', - os.path.join(conf.overlay, 'profiles', 'categories'): 'g-octave', + os.path.join(config.overlay, 'profiles', 'repo_name'): 'g-octave', + os.path.join(config.overlay, 'profiles', 'categories'): 'g-octave', } # symlinking g-octave eclass @@ -58,7 +55,7 @@ def create_overlay(force=False, conf=None, quiet=False): '..', 'share', 'g-octave.eclass' ) global_eclass = os.path.join(sys.prefix, 'share', 'g-octave', 'g-octave.eclass') - overlay_eclass = os.path.join(conf.overlay, 'eclass', 'g-octave.eclass') + overlay_eclass = os.path.join(config.overlay, 'eclass', 'g-octave.eclass') if os.path.exists(local_eclass): os.symlink(local_eclass, overlay_eclass) elif os.path.exists(global_eclass): -- cgit v1.2.3-65-gdbad