From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoopm:master commit in: gentoopm/basepm/
Date: Mon, 11 Jul 2011 09:39:29 +0000 (UTC) [thread overview]
Message-ID: <a15d5b2ad120d17a92df2da61300f1da6faa7e6b.mgorny@gentoo> (raw)
commit: a15d5b2ad120d17a92df2da61300f1da6faa7e6b
Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Mon Jul 11 09:40:06 2011 +0000
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Mon Jul 11 09:40:06 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoopm.git;a=commit;h=a15d5b2a
Support forking a BashParser out of PMPackageEnvironment.
---
gentoopm/basepm/environ.py | 64 +++++++++++++++++++++++++++++++++++++++++--
1 files changed, 61 insertions(+), 3 deletions(-)
diff --git a/gentoopm/basepm/environ.py b/gentoopm/basepm/environ.py
index 86ee5f5..8e1c469 100644
--- a/gentoopm/basepm/environ.py
+++ b/gentoopm/basepm/environ.py
@@ -7,6 +7,21 @@ import bz2
from gentoopm.bash import get_any_bashparser
+def _load_bp(bp, path, open_func):
+ """
+ Load a file onto a bash parser.
+
+ @param bp: the bash parser instance
+ @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 = open_func(path)
+ bp.load_file(f)
+ f.close()
+
class LazyBashParser(object):
"""
Lazily-initialized, shared bash parser wrapper.
@@ -15,14 +30,21 @@ class LazyBashParser(object):
_parser = None
def set_file(self, path, open_func):
+ """
+ Switch the currently used environment file, if necessary.
+
+ @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)
+ """
+
if self._curr_path == path:
return
self._curr_path = path
- f = open_func(path)
if self._parser is None:
self._parser = get_any_bashparser()
- self._parser.load_file(f)
- f.close()
+ _load_bp(self._parser, path, open_func)
def __getitem__(self, k):
return self._parser[k]
@@ -41,13 +63,49 @@ class PMPackageEnvironment(object):
"""
def __init__(self, path, bzipped2 = False):
+ """
+ Instantiate L{PMPackageEnvironment} accessor.
+
+ @param path: path to the environment file
+ @type path: string
+ @param bzipped2: whether to bunzip2 the file
+ @type bzipped2: bool
+ """
self._path = path
self._open_func = bz2.BZ2File if bzipped2 else open
def __getitem__(self, k):
+ """
+ Get the value of an environment key by name.
+
+ @param k: the key to access
+ @type k: string
+ @return: the environment variable value
+ @rtype: string
+ """
_bp.set_file(self._path, self._open_func)
return _bp[k]
def copy(self, *keys):
+ """
+ Get a number of environment keys as a dict.
+
+ @param keys: keys to access
+ @type keys: strings
+ @return: a dict of copied environment keys
+ @rtype: dict(string -> string)
+ """
_bp.set_file(self._path, self._open_func)
return _bp.copy(*keys)
+
+ def fork(self):
+ """
+ Fork the bash parser. In other words, return a completely separate
+ instance with the environment file loaded.
+
+ @return: forked L{BashParser} instance
+ @rtype: L{BashParser}
+ """
+ bp = get_any_bashparser()
+ _load_bp(bp, self._path, self._open_func)
+ return bp
next reply other threads:[~2011-07-11 9:39 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-11 9:39 Michał Górny [this message]
-- strict thread matches above, loose matches on Subject: below --
2015-08-07 9:18 [gentoo-commits] proj/gentoopm:master commit in: gentoopm/basepm/ Michał Górny
2013-08-05 16:04 Michał Górny
2011-12-24 9:18 Michał Górny
2011-09-10 8:28 Michał Górny
2011-08-15 8:48 Michał Górny
2011-08-15 8:48 Michał Górny
2011-08-15 7:57 Michał Górny
2011-08-13 9:17 Michał Górny
2011-08-12 20:38 Michał Górny
2011-08-12 17:43 Michał Górny
2011-07-28 16:24 Michał Górny
2011-07-26 20:10 Michał Górny
2011-07-26 20:10 Michał Górny
2011-07-26 16:36 Michał Górny
2011-07-26 7:24 Michał Górny
2011-07-25 17:33 Michał Górny
2011-07-25 17:33 Michał Górny
2011-07-25 17:06 Michał Górny
2011-07-24 20:05 Michał Górny
2011-07-23 9:27 Michał Górny
2011-07-23 9:27 Michał Górny
2011-07-21 8:47 Michał Górny
2011-07-20 9:41 Michał Górny
2011-07-17 22:39 Michał Górny
2011-07-17 22:10 Michał Górny
2011-07-17 22:10 Michał Górny
2011-07-17 22:10 Michał Górny
2011-07-17 9:09 Michał Górny
2011-07-15 23:56 Michał Górny
2011-07-15 23:56 Michał Górny
2011-07-15 22:24 Michał Górny
2011-07-15 22:24 Michał Górny
2011-07-15 22:24 Michał Górny
2011-07-15 13:32 Michał Górny
2011-07-15 12:34 Michał Górny
2011-07-15 12:34 Michał Górny
2011-07-15 12:34 Michał Górny
2011-07-15 9:52 Michał Górny
2011-07-15 9:52 Michał Górny
2011-07-14 22:51 Michał Górny
2011-07-14 13:31 Michał Górny
2011-07-14 13:31 Michał Górny
2011-07-14 13:31 Michał Górny
2011-07-13 16:30 Michał Górny
2011-07-13 16:09 Michał Górny
2011-07-11 9:39 Michał Górny
2011-07-10 12:34 Michał Górny
2011-07-08 12:49 Michał Górny
2011-07-08 12:49 Michał Górny
2011-07-07 12:52 Michał Górny
2011-07-07 12:52 Michał Górny
2011-07-07 12:52 Michał Górny
2011-07-07 9:51 Michał Górny
2011-07-06 20:54 Michał Górny
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a15d5b2ad120d17a92df2da61300f1da6faa7e6b.mgorny@gentoo \
--to=mgorny@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox