From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1QiZXh-0004VW-LF for garchives@archives.gentoo.org; Sun, 17 Jul 2011 22:10:29 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 5B14B21C2C3; Sun, 17 Jul 2011 22:10:07 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 1C31121C2C3 for ; Sun, 17 Jul 2011 22:10:07 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 7C1081B4009 for ; Sun, 17 Jul 2011 22:10:06 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id CBD9F8003D for ; Sun, 17 Jul 2011 22:10:05 +0000 (UTC) From: "Michał Górny" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Michał Górny" Message-ID: Subject: [gentoo-commits] proj/gentoopm:master commit in: gentoopm/basepm/ X-VCS-Repository: proj/gentoopm X-VCS-Files: gentoopm/basepm/environ.py gentoopm/basepm/pkg.py X-VCS-Directories: gentoopm/basepm/ X-VCS-Committer: mgorny X-VCS-Committer-Name: Michał Górny X-VCS-Revision: f37b0cad6628be0b0c48001036e2aa042333d193 Date: Sun, 17 Jul 2011 22:10:05 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 1973666eb5218296b436160dc0432618 commit: f37b0cad6628be0b0c48001036e2aa042333d193 Author: Micha=C5=82 G=C3=B3rny gentoo org> AuthorDate: Sun Jul 17 21:46:43 2011 +0000 Commit: Micha=C5=82 G=C3=B3rny gentoo org> CommitDate: Sun Jul 17 21:46:43 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/gentoopm.git;= a=3Dcommit;h=3Df37b0cad Autodetect bzip2 when loading an environment file. --- gentoopm/basepm/environ.py | 36 +++++++++++++++++++----------------- gentoopm/basepm/pkg.py | 4 +--- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/gentoopm/basepm/environ.py b/gentoopm/basepm/environ.py index 3e27148..7ba5450 100644 --- a/gentoopm/basepm/environ.py +++ b/gentoopm/basepm/environ.py @@ -7,7 +7,7 @@ import bz2 =20 from gentoopm.bash import get_any_bashparser =20 -def _load_bp(bp, path, open_func): +def _load_bp(bp, path): """ Load a file onto a bash parser. =20 @@ -15,12 +15,19 @@ def _load_bp(bp, path, open_func): @type bp: L{BashParser} @param path: path to the environment file @type path: string - @param open_func: open function for the file - @type open_func: func(path, mode) """ - f =3D open_func(path) - bp.load_file(f) - f.close() + + def _try_file(t): + f =3D t(path, 'r') + try: + bp.load_file(f) + finally: + f.close() + + try: + _try_file(bz2.BZ2File) + except IOError: + _try_file(open) =20 class LazyBashParser(object): """ @@ -29,14 +36,12 @@ class LazyBashParser(object): _curr_path =3D None _parser =3D None =20 - def set_file(self, path, open_func): + def set_file(self, path): """ Switch the currently used environment file, if necessary. =20 @param path: path to the new environment file @type path: string - @param open_func: open functions for the new file - @type open_func: func(path, mode) """ =20 if self._curr_path =3D=3D path: @@ -44,7 +49,7 @@ class LazyBashParser(object): self._curr_path =3D path if self._parser is None: self._parser =3D get_any_bashparser() - _load_bp(self._parser, path, open_func) + _load_bp(self._parser, path) =20 def __getitem__(self, k): return self._parser[k] @@ -59,17 +64,14 @@ class PMPackageEnvironment(object): Package environment accessor class. """ =20 - def __init__(self, path, bzipped2 =3D False): + def __init__(self, path): """ Instantiate L{PMPackageEnvironment} accessor. =20 @param path: path to the environment file @type path: string - @param bzipped2: whether to bunzip2 the file - @type bzipped2: bool """ self._path =3D path - self._open_func =3D bz2.BZ2File if bzipped2 else open =20 def __getitem__(self, k): """ @@ -80,7 +82,7 @@ class PMPackageEnvironment(object): @return: the environment variable value @rtype: string """ - _bp.set_file(self._path, self._open_func) + _bp.set_file(self._path) return _bp[k] =20 def copy(self, *keys): @@ -92,7 +94,7 @@ class PMPackageEnvironment(object): @return: a dict of copied environment keys @rtype: dict(string -> string) """ - _bp.set_file(self._path, self._open_func) + _bp.set_file(self._path) return _bp.copy(*keys) =20 def fork(self): @@ -104,5 +106,5 @@ class PMPackageEnvironment(object): @rtype: L{BashParser} """ bp =3D get_any_bashparser() - _load_bp(bp, self._path, self._open_func) + _load_bp(bp, self._path) return bp diff --git a/gentoopm/basepm/pkg.py b/gentoopm/basepm/pkg.py index 067808f..853cad1 100644 --- a/gentoopm/basepm/pkg.py +++ b/gentoopm/basepm/pkg.py @@ -109,12 +109,10 @@ class PMPackage(ABCObject): @type: L{PMPackageEnvironment} """ p =3D self.path - bz2 =3D False if os.path.isdir(p): # XXX: look for .bz2 and plain, take the newer one p =3D os.path.join(p, 'environment.bz2') - bz2 =3D True - return PMPackageEnvironment(p, bzipped2 =3D bz2) + return PMPackageEnvironment(p) =20 def __eq__(self, other): if not isinstance(other, self.__class__):