Merge genscripts rev 123, this unifies the get_env_var/get_env_vars methods as one...
authorfuzzyray <fuzzyray@gentoo.org>
Fri, 11 Dec 2009 03:02:15 +0000 (03:02 -0000)
committerfuzzyray <fuzzyray@gentoo.org>
Fri, 11 Dec 2009 03:02:15 +0000 (03:02 -0000)
svn path=/trunk/gentoolkit/; revision=719

TODO
pym/gentoolkit/dependencies.py
pym/gentoolkit/equery/hasuse.py
pym/gentoolkit/equery/meta.py
pym/gentoolkit/equery/uses.py
pym/gentoolkit/package.py

diff --git a/TODO b/TODO
index 04cfbf3363f4a49f7436c717b3e8229c3bf249e3..3ffa6d287e786ba02eaf78632cf0061919be5e8a 100644 (file)
--- a/TODO
+++ b/TODO
@@ -35,7 +35,7 @@ equery:
                +depgraph
 
 For Next Release:
-       - allow passing VERSION='123' in front of setup.py sdist and do version
-         mangling at dist creation time.
        - find all commits to main gentoolkit svn after rc7 push and merge where
          appropriate
+       - write a docstring for Package which details especially the change in have
+         cpv as an object, not a string.
index 4321e66ff9772584636321be1a265073e7ad58c6..ccc241e3365f60ffe7b53bf3b283f1b0debce4c5 100644 (file)
@@ -68,7 +68,7 @@ class Dependencies(CPV):
        def __repr__(self):
                return "<%s %r>" % (self.__class__.__name__, self.atom)
 
-       def get_env_vars(self, envvars):
+       def environment(self, envvars):
                """Returns predefined env vars DEPEND, SRC_URI, etc."""
 
                # Try to use the Portage tree first, since emerge only uses the tree
@@ -83,7 +83,7 @@ class Dependencies(CPV):
                """Get the contents of DEPEND and parse it with self.parser."""
 
                try:
-                       return self.parser(self.get_env_vars(('DEPEND',))[0])
+                       return self.parser(self.environment(('DEPEND',))[0])
                except portage.exception.InvalidPackageName, err:
                        raise errors.GentoolkitInvalidCPV(err)
 
@@ -91,7 +91,7 @@ class Dependencies(CPV):
                """Get the contents of PDEPEND and parse it with self.parser."""
 
                try:
-                       return self.parser(self.get_env_vars(('PDEPEND',))[0])
+                       return self.parser(self.environment(('PDEPEND',))[0])
                except portage.exception.InvalidPackageName, err:
                        raise errors.GentoolkitInvalidCPV(err)
 
@@ -99,7 +99,7 @@ class Dependencies(CPV):
                """Get the contents of RDEPEND and parse it with self.parser."""
 
                try:
-                       return self.parser(self.get_env_vars(('RDEPEND',))[0])
+                       return self.parser(self.environment(('RDEPEND',))[0])
                except portage.exception.InvalidPackageName, err:
                        raise errors.GentoolkitInvalidCPV(err)
 
@@ -108,7 +108,7 @@ class Dependencies(CPV):
 
                env_vars = ('DEPEND', 'PDEPEND', 'RDEPEND')
                try:
-                       return self.parser(' '.join(self.get_env_vars(env_vars)))
+                       return self.parser(' '.join(self.environment(env_vars)))
                except portage.exception.InvalidPackageName, err:
                        raise errors.GentoolkitInvalidCPV(err)
 
index 82b2e296950f8438f5447bd1eca34cd60812b610..bc4bb6386020ebafbfc8cf3a8e0aa87bb55751f0 100644 (file)
@@ -65,7 +65,7 @@ def display_useflags(query, pkg):
        """Display USE flag information for a given package."""
 
        try:
-               useflags = [x.lstrip("+-") for x in pkg.get_env_var("IUSE").split()]
+               useflags = [x.lstrip("+-") for x in pkg.environment("IUSE").split()]
        except errors.GentoolkitFatalError:
                # aux_get KeyError or other unexpected result
                return
index 480441cfa39137abf864097b9002a318b50f57d6..1a8114bd68f7fea7b735b58f9659945e144786c7 100644 (file)
@@ -94,7 +94,7 @@ def filter_keywords(matches):
        # Start from the newest
        rev_matches = reversed(matches)
        for pkg in rev_matches:
-               keywords_str, slot = pkg.get_env_vars(('KEYWORDS', 'SLOT'))
+               keywords_str, slot = pkg.environment(('KEYWORDS', 'SLOT'))
                keywords = keywords_str.split()
                result[pkg] = [x for x in keywords if x not in slot_map.get(slot, [])]
                try:
@@ -214,7 +214,7 @@ def format_keywords(keywords):
 def format_keywords_line(pkg, fmtd_keywords):
        """Format the entire keywords line for display."""
 
-       slot = pkg.get_env_var('SLOT')
+       slot = pkg.environment('SLOT')
        ver = pkg.cpv.fullversion
        verstr_len = len(ver) + 1 + len(slot)  # +1 for ':'
 
@@ -288,7 +288,7 @@ def call_format_functions(matches):
                                print keywords_line
                        else:
                                # FIXME: duplicate code
-                               slot = match.get_env_var('SLOT')
+                               slot = match.environment('SLOT')
                                verstr_len = len(match.cpv.fullversion) + len(slot)
                                indent = " " * (16 + verstr_len)
                                print format_line(keywords_line, "Keywords:    ", indent)
index 88a7a879cb4436c86c1e177bacaa184e7a928753..0529f39dec1125075c1a076e3a076b89f7b5351a 100644 (file)
@@ -185,7 +185,7 @@ def get_output_descriptions(pkg, global_usedesc):
        """Prepare descriptions and usage information for each USE flag."""
 
        local_usedesc = pkg.metadata.get_useflags()
-       iuse = pkg.get_env_var("IUSE")
+       iuse = pkg.environment("IUSE")
 
        if iuse:
                usevar = uniqify([x.lstrip('+-') for x in iuse.split()])
index 59d50bfbf9c09429b0bc2e93d06ec8855a1c530e..ecde59ac5519a7d4aa4d4135117f7b1ecda01537 100644 (file)
@@ -129,6 +129,42 @@ class Package(CPV):
 
                return self._deps
 
+       def environment(self, envvars, tree=None):
+               """Returns one or more of the predefined environment variables.
+
+               Example usage:
+                       >>> pkg = Package('sys-apps/portage-2.1.6.13')
+                       >>> pkg.environment('USE')
+                       'elibc_glibc kernel_linux userland_GNU x86'
+                       >>> pkg.environment(('USE', 'IUSE'))
+                       ['elibc_glibc kernel_linux userland_GNU x86',
+                               'build doc epydoc selinux linguas_pl']
+
+               @type envvars: str or array
+               @param envvars: one or more of (DEPEND, SRC_URI, etc.)
+               @rtype: str or list
+               @return: str if envvars is str, list if envvars is array
+               """
+
+               if tree is None:
+                       tree = self._get_trees()[0]
+               got_string = False
+               if isinstance(envvars, basestring):
+                       got_string = True
+                       envvars = (envvars,)
+               try:
+                       result = tree.aux_get(str(self.cpv), envvars)
+               except (KeyError, errors.GentoolkitFatalError):
+                       err = "aux_get returned unexpected results"
+                       raise errors.GentoolkitFatalError(err)
+
+               if got_string:
+                       return result[0]
+               return result
+
+       # Namespace compatibility 2009, djanderson
+       get_env_var = environment
+
        def exists(self):
                """Return True if package exists in the Portage tree, else False"""
 
@@ -226,26 +262,6 @@ class Package(CPV):
 
                return self.get_package_path().split(os.sep)[-3]
 
-       def get_env_vars(self, envvars, tree=None):
-               """Returns one or more of the predefined environment variables.
-
-               @type envvars: array
-               @param envvars: one or more of (DEPEND, SRC_URI, etc.)"""
-
-               if tree is None:
-                       tree = self._get_trees()[0]
-               try:
-                       result = tree.aux_get(str(self.cpv), envvars)
-               except (KeyError, errors.GentoolkitFatalError):
-                       err = "aux_get returned unexpected results"
-                       raise errors.GentoolkitFatalError(err)
-               return result
-
-       def get_env_var(self, *args, **kwargs):
-               """Returns one of the predefined environment variables."""
-
-               return self.get_env_vars(args, **kwargs)[0]
-
        def get_use_flags(self):
                """Returns the USE flags active at time of installation."""
 
@@ -342,7 +358,7 @@ class PackageFormatter(object):
                                'location': self.location,
                                'mask': pp.maskflag(maskmodes[self.format_mask_status()[0]]),
                                'package': pp.cpv(str(self.pkg.cpv)),
-                               'slot': self.pkg.get_env_var("SLOT")
+                               'slot': self.pkg.environment("SLOT")
                        }
                else:
                        return str(self.pkg.cpv)