Merge genscripts rev 130
authorfuzzyray <fuzzyray@gentoo.org>
Fri, 11 Dec 2009 17:15:35 +0000 (17:15 -0000)
committerfuzzyray <fuzzyray@gentoo.org>
Fri, 11 Dec 2009 17:15:35 +0000 (17:15 -0000)
svn path=/trunk/gentoolkit/; revision=721

18 files changed:
TODO
bin/glsa-check
man/equery.1
pym/gentoolkit/deprecated/helpers.py
pym/gentoolkit/equery/belongs.py
pym/gentoolkit/equery/changes.py
pym/gentoolkit/equery/check.py
pym/gentoolkit/equery/files.py
pym/gentoolkit/equery/list_.py
pym/gentoolkit/equery/meta.py
pym/gentoolkit/equery/size.py
pym/gentoolkit/equery/uses.py
pym/gentoolkit/equery/which.py
pym/gentoolkit/helpers.py
pym/gentoolkit/metadata.py
pym/gentoolkit/package.py
pym/gentoolkit/pprinter.py
setup.py

diff --git a/TODO b/TODO
index 3ffa6d287e786ba02eaf78632cf0061919be5e8a..859e8df5d1b06a2810c97994ff40fc9007ede67e 100644 (file)
--- a/TODO
+++ b/TODO
@@ -34,8 +34,15 @@ equery:
                +changes
                +depgraph
 
+Ebuild changes:
+       - Add:
+               src_test() {
+                       "${python}" setup.py test || die "testing returned non zero"
+               }
+       - Add:
+               DEPEND on python 2.5 (needed for 'from __future__ import with' and others)
+
 For Next Release:
-       - find all commits to main gentoolkit svn after rc7 push and merge where
-         appropriate
+       - write NEWS file
        - write a docstring for Package which details especially the change in have
          cpv as an object, not a string.
index fcd4cb05fb699410d915325780139a4fdda631fc..ab83471bd3d2a802ea36dc5c4f9551819d05bfda 100755 (executable)
@@ -6,22 +6,15 @@
 import os
 import sys
 import codecs
-try:
-       import portage
-except ImportError:
-       sys.path.insert(0, "/usr/lib/portage/pym")
-       import portage
 
-try:
-       from portage.output import *
-except ImportError:
-       from output import *
+import portage
+from portage.output import *
 
 from getopt import getopt, GetoptError
 
 __program__ = "glsa-check"
 __author__ = "Marius Mauch <genone@gentoo.org>"
-__version__ = open("/usr/share/gentoolkit/VERSION").read().strip()
+__version__ = "svn"
 
 optionmap = [
 ["-l", "--list", "list the GLSAs"],
@@ -55,12 +48,12 @@ try:
        args, params = getopt(sys.argv[1:], "".join([o[0][1] for o in optionmap]), \
                [x[2:] for x in reduce(lambda x,y: x+y, [z[1:-1] for z in optionmap])])
        args = [a for a,b in args]
-       
+
        for option in ["--nocolor", "-n"]:
                if option in args:
                        nocolor()
                        args.remove(option)
-                       
+
        verbose = False
        for option in ["--verbose", "-v"]:
                if option in args:
@@ -72,7 +65,7 @@ try:
                if option in args:
                        list_cve = True
                        args.remove(option)
-       
+
        least_change = True
        for option in ["--emergelike", "-e"]:
                if option in args:
@@ -113,7 +106,7 @@ if len(params) <= 0 and mode in ["fix", "test", "pretend", "dump", "inject", "ma
        mode = "HELP"
 elif len(params) <= 0 and mode == "list":
        params.append("affected")
-       
+
 # show help message
 if mode == "help" or mode == "HELP":
        msg = "Syntax: glsa-check <option> [glsa-list]\n\n"
@@ -176,7 +169,7 @@ if "new" in params:
        params.remove("new")
        sys.stderr.write("Warning: The 'new' glsa-list target has been removed, using 'affected'.\n")
        params.append("affected")
-       
+
 if "all" in params:
        glsalist = completelist
        params.remove("all")
@@ -298,7 +291,7 @@ if mode in ["dump", "fix", "inject", "pretend"]:
                                mergedict = {}
                                for (vuln, update) in myglsa.getAffectionTable(least_change=least_change):
                                        mergedict.setdefault(update, []).append(vuln)
-                               
+
                                # first, extract the atoms that cannot be upgraded (where key == "")
                                no_upgrades = []
                                if "" in mergedict:
@@ -348,7 +341,7 @@ if mode == "mail":
                import portage.mail as portage_mail
        except ImportError:
                import portage_mail
-               
+
        import socket
        from StringIO import StringIO
        try:
@@ -363,7 +356,7 @@ if mode == "mail":
                myrecipient = glsaconfig["PORTAGE_ELOG_MAILURI"].split()[0]
        else:
                myrecipient = "root@localhost"
-       
+
        if "PORTAGE_ELOG_MAILFROM" in glsaconfig:
                myfrom = glsaconfig["PORTAGE_ELOG_MAILFROM"]
        else:
@@ -395,9 +388,9 @@ if mode == "mail":
         if glsalist or not quiet:
                mymessage = portage_mail.create_message(myfrom, myrecipient, mysubject, summary, myattachments)
                portage_mail.send_mail(glsaconfig, mymessage)
-               
+
        sys.exit(0)
-       
+
 # something wrong here, all valid paths are covered with sys.exit()
 sys.stderr.write("nothing more to do\n")
 sys.exit(2)
index c47b8607bfb97c74c16aa361157688df44fca348..c3be6e996ce2b75e0385cdb48361d3570ed3d6c1 100644 (file)
@@ -342,8 +342,8 @@ Include all packages from the Portage tree in the search path. Use this option t
 .EX
 $ equery list binutils
  * Searching for binutils ...
- [I--] [XX] sys-devel/binutils-2.18-r1 (i686-pc-linux-gnu-2.18)
- [IP-] [ ~] sys-devel/binutils-2.19.1-r1 (i686-pc-linux-gnu-2.19.1)
+ [I--] [XX] sys-devel/binutils-2.18-r1:i686-pc-linux-gnu-2.18
+ [IP-] [ ~] sys-devel/binutils-2.19.1-r1:i686-pc-linux-gnu-2.19.1
 .EE
 .HP
 Location field (\fB[IPO-]\fP):
@@ -360,7 +360,7 @@ The third field is the full package name and version.
 .HP
 Slot:
 .br
-The fourth field, in parentheses, is the package's slot. \fB0\fP is the default slot. To find all packages with multiple slots installed, use \fB--duplicates\fP.
+The fourth field, after the colon, is the package's slot. \fB0\fP is the default slot. To find all packages with multiple slots installed, use \fB--duplicates\fP.
 .P
 \fBNote:\fP Because it takes extra processing time to determine the location, mask status and slot, you can speed up output by passing the \fB--quiet\fP global option to \fBequery\fP when you don't care about the extra information.
 
index df158f28fe30dcbeabdd1f5605b200b219581882..d0fb99318049b1bbe15450af4c6d3516b63c683b 100644 (file)
@@ -7,9 +7,6 @@
 #
 # $Header$
 
-"""The functions in this module have been deprecated and are not even
-guaranteed to work. Improved functions can be found in helpers2.py"""
-
 import warnings
 
 import portage
index e1367cfd8de572a92b106cd67d95f7ac8b97f9ad..fcf58ab8629ae7b5813228028edf7f377fdb1f24 100644 (file)
@@ -64,7 +64,7 @@ class BelongsPrinter(object):
 
        def print_verbose(self, pkg, cfile):
                "Format for full output."
-               file_str = pp.path(format_filetype(cfile, pkg.get_contents()[cfile]))
+               file_str = pp.path(format_filetype(cfile, pkg.parsed_contents()[cfile]))
                if self.name_only:
                        name = pkg.cpv.cp
                else:
index 09ccccaa26dea6ced4b47889652f0cf83c150dfb..ef35ec9d4747585a4dea5f1cbb4e6189e6d8fe68 100644 (file)
@@ -4,9 +4,7 @@
 #
 # $Header: $
 
-"""Display the Gentoo ChangeLog entry for the latest installable version of a
-given package.
-"""
+"""Displays the ChangeLog entry for the latest installable version of a package"""
 
 # Move to Imports sections when Python 2.6 is stable
 from __future__ import with_statement
@@ -175,7 +173,7 @@ def main(input_args):
                        print
 
                match = get_match(query)
-               changelog_path = os.path.join(match.get_package_path(), 'ChangeLog')
+               changelog_path = os.path.join(match.package_path(), 'ChangeLog')
                changelog = ChangeLog(changelog_path)
 
                #
index 011fd5d676f95241c0193409b0027f3ebaef83b8..6ce288c6145585a6400fa8cd743064e932d84289 100644 (file)
@@ -4,7 +4,7 @@
 #
 # $Header: $
 
-"""Check timestamps and MD5 sums for files owned by a given installed package"""
+"""Checks timestamps and MD5 sums for files owned by a given installed package"""
 
 __docformat__ = 'epytext'
 
@@ -78,7 +78,7 @@ class VerifyContents(object):
                result = {}
                for pkg in pkgs:
                        # _run_checks returns tuple(n_passed, n_checked, err)
-                       check_results = self._run_checks(pkg.get_contents())
+                       check_results = self._run_checks(pkg.parsed_contents())
                        result[pkg.cpv] = check_results
                        if self.printer_fn is not None:
                                self.printer_fn(pkg.cpv, check_results)
index 4f588bb9aa8650e421002188a9fe06203c3d2e29..400e4b1c9a98831ec73a146a749563892656c05b 100644 (file)
@@ -82,7 +82,7 @@ def print_help(with_description=True):
 def display_files(contents):
        """Display the content of an installed package.
 
-       @see: gentoolkit.package.Package.get_contents
+       @see: gentoolkit.package.Package.parsed_contents
        @type contents: dict
        @param contents: {'path': ['filetype', ...], ...}
        """
@@ -202,7 +202,7 @@ def filter_by_conf(contents):
 def filter_contents(contents):
        """Filter files by type if specified by the user.
 
-       @see: gentoolkit.package.Package.get_contents
+       @see: gentoolkit.package.Package.parsed_contents
        @type contents: dict
        @param contents: {'path': ['filetype', ...], ...}
        @rtype: dict
@@ -312,7 +312,7 @@ def main(input_args):
                        if CONFIG['verbose']:
                                print " * Contents of %s:" % pp.cpv(str(pkg.cpv))
 
-                       contents = pkg.get_contents()
+                       contents = pkg.parsed_contents()
                        display_files(filter_contents(contents))
 
                first_run = False
index c3e7f07b63cb228c7b6ecff4a5342c2fc2baecb6..c727590f679e3e77d7025f8a34cdbee3c180246f 100644 (file)
@@ -202,7 +202,7 @@ def main(input_args):
                                        # ms_int is a number representation of mask level.
                                        # Only 2 and above are "hard masked" and have reasons.
                                        continue
-                               mask_reason = pkg.get_mask_reason()
+                               mask_reason = pkg.mask_reason()
                                if not mask_reason:
                                        # Package not on system or not masked
                                        continue
index 1a8114bd68f7fea7b735b58f9659945e144786c7..763e30d9f2167283bf404d0a1f30ac2110e718ec 100644 (file)
@@ -201,30 +201,24 @@ def format_keywords(keywords):
 
        for kw in sorted(keywords):
                if kw.startswith(('~', '-')):
-                       # keyword (~) or arch (-) masked, color red
-                       kw = pp.useflag(kw, enabled=True)
-               else:
-                       # unmasked, color blue
+                       # keyword (~) or arch (-) masked
                        kw = pp.useflag(kw, enabled=False)
+               else:
+                       # unmasked
+                       kw = pp.useflag(kw, enabled=True)
                result.append(kw)
 
        return ' '.join(result)
 
 
-def format_keywords_line(pkg, fmtd_keywords):
+def format_keywords_line(pkg, fmtd_keywords, slot, verstr_len):
        """Format the entire keywords line for display."""
 
-       slot = pkg.environment('SLOT')
        ver = pkg.cpv.fullversion
-       verstr_len = len(ver) + 1 + len(slot)  # +1 for ':'
-
-       if CONFIG['verbose']:
-               result = format_line(
-                       fmtd_keywords, "%s:%s: " % (pp.cpv(ver), pp.slot(slot)),
-                       " " * (verstr_len + 2)
-               )
-       else:
-               result = "%s:%s: %s" % (ver, slot, fmtd_keywords)
+       result = "%s:%s: %s" % (ver, pp.slot(slot), fmtd_keywords)
+       if CONFIG['verbose'] and fmtd_keywords:
+               result = format_line(fmtd_keywords, "%s:%s: " % (ver, pp.slot(slot)),
+                       " " * (verstr_len + 2))
 
        return result
 
@@ -238,7 +232,7 @@ def call_format_functions(matches):
        ref_pkg = get_reference_pkg(matches)
 
        if CONFIG['verbose']:
-               repo = ref_pkg.get_repo_name()
+               repo = ref_pkg.repo_id()
                print " * %s [%s]" % (pp.cpv(ref_pkg.cpv.cp), pp.section(repo))
 
        got_opts = False
@@ -246,12 +240,8 @@ def call_format_functions(matches):
                # Specific information requested, less formatting
                got_opts = True
 
-       if not got_opts:
-               pkg_loc = ref_pkg.get_package_path()
-               print format_line(pkg_loc, "Location:    ", " " * 13)
-
        if QUERY_OPTS["herd"] or not got_opts:
-               herds = format_herds(ref_pkg.metadata.get_herds(include_email=True))
+               herds = format_herds(ref_pkg.metadata.herds(include_email=True))
                if QUERY_OPTS["herd"]:
                        print_sequence(format_list(herds))
                else:
@@ -259,7 +249,7 @@ def call_format_functions(matches):
                                print format_line(herd, "Herd:        ", " " * 13)
 
        if QUERY_OPTS["maintainer"] or not got_opts:
-               maints = format_maintainers(ref_pkg.metadata.get_maintainers())
+               maints = format_maintainers(ref_pkg.metadata.maintainers())
                if QUERY_OPTS["maintainer"]:
                        print_sequence(format_list(maints))
                else:
@@ -270,39 +260,44 @@ def call_format_functions(matches):
                                        print format_line(maint, "Maintainer:  ", " " * 13)
 
        if QUERY_OPTS["upstream"] or not got_opts:
-               upstream = format_upstream(ref_pkg.metadata.get_upstream())
+               upstream = format_upstream(ref_pkg.metadata.upstream())
                if QUERY_OPTS["upstream"]:
                        upstream = format_list(upstream)
                else:
                        upstream = format_list(upstream, "Upstream:    ", " " * 13)
                print_sequence(upstream)
 
+       if not got_opts:
+               pkg_loc = ref_pkg.package_path()
+               print format_line(pkg_loc, "Location:    ", " " * 13)
+
        if QUERY_OPTS["keywords"] or not got_opts:
                # Get {<Package 'dev-libs/glib-2.20.5'>: [u'ia64', u'm68k', ...], ...}
                keyword_map = filter_keywords(matches)
 
                for match in matches:
+                       slot = match.environment('SLOT')
+                       verstr_len = len(match.cpv.fullversion) + len(slot)
                        fmtd_keywords = format_keywords(keyword_map[match])
-                       keywords_line = format_keywords_line(match, fmtd_keywords)
+                       keywords_line = format_keywords_line(
+                               match, fmtd_keywords, slot, verstr_len
+                       )
                        if QUERY_OPTS["keywords"]:
                                print keywords_line
                        else:
-                               # FIXME: duplicate code
-                               slot = match.environment('SLOT')
-                               verstr_len = len(match.cpv.fullversion) + len(slot)
                                indent = " " * (16 + verstr_len)
                                print format_line(keywords_line, "Keywords:    ", indent)
 
        if QUERY_OPTS["description"]:
-               desc = ref_pkg.metadata.get_descriptions()
+               desc = ref_pkg.metadata.descriptions()
                print_sequence(format_list(desc))
 
        if QUERY_OPTS["useflags"]:
-               useflags = format_useflags(ref_pkg.metadata.get_useflags())
+               useflags = format_useflags(ref_pkg.metadata.use())
                print_sequence(format_list(useflags))
 
        if QUERY_OPTS["xml"]:
-               print_file(os.path.join(ref_pkg.get_package_path(), 'metadata.xml'))
+               print_file(os.path.join(ref_pkg.package_path(), 'metadata.xml'))
 
 
 def format_line(line, first="", subsequent="", force_quiet=False):
index 8570a6aa64f3d488e1c2d87595380eb18e5cef5a..f7b88882841c9d3a18c3cdc7563f830ecc550765 100644 (file)
@@ -78,7 +78,7 @@ def display_size(match_set):
        """
 
        for pkg in match_set:
-               size, files, uncounted = pkg.get_size()
+               size, files, uncounted = pkg.size()
 
                if CONFIG['verbose']:
                        print " * %s" % pp.cpv(str(pkg.cpv))
index 0529f39dec1125075c1a076e3a076b89f7b5351a..d38dfe58291c85c98a746e6576d489a90d98a884 100644 (file)
@@ -77,7 +77,9 @@ def display_useflags(output):
        twrap.subsequent_indent = " " * (maxflag_len + 8)
 
        markers = ("-", "+")
-       color = [pp.useflag, partial(pp.useflag, enabled=True)]
+       color = (
+               partial(pp.useflag, enabled=False), partial(pp.useflag, enabled=True)
+       )
        for in_makeconf, in_installed, flag, desc, restrict in output:
                if CONFIG['verbose']:
                        flag_name = ""
@@ -184,7 +186,7 @@ def get_matches(query):
 def get_output_descriptions(pkg, global_usedesc):
        """Prepare descriptions and usage information for each USE flag."""
 
-       local_usedesc = pkg.metadata.get_useflags()
+       local_usedesc = pkg.metadata.use()
        iuse = pkg.environment("IUSE")
 
        if iuse:
@@ -194,7 +196,7 @@ def get_output_descriptions(pkg, global_usedesc):
                usevar = []
 
        if pkg.is_installed():
-               used_flags = pkg.get_use_flags().split()
+               used_flags = pkg.use().split()
        else:
                used_flags = settings["USE"].split()
 
@@ -224,7 +226,7 @@ def get_output_descriptions(pkg, global_usedesc):
                except AttributeError:
                        restrict = ""
 
-               if flag in pkg.get_settings("USE").split():
+               if flag in pkg.settings("USE").split():
                        inuse = True
                if flag in used_flags:
                        inused = True
@@ -280,6 +282,7 @@ def main(input_args):
        #
 
        first_run = True
+       legend_printed = False
        for query in queries:
                if not first_run:
                        print
@@ -296,7 +299,9 @@ def main(input_args):
                        output = get_output_descriptions(pkg, global_usedesc)
                        if output:
                                if CONFIG['verbose']:
-                                       print_legend()
+                                       if not legend_printed:
+                                               print_legend()
+                                               legend_printed = True
                                        print (" * Found these USE flags for %s:" %
                                                pp.cpv(str(pkg.cpv)))
                                        print pp.emph(" U I")
index ada3fde48d9f257be5c54c0aa501003f54bd4d84..38a8c6b0b38c523b0b73905d5981710e92ac3f16 100644 (file)
@@ -89,12 +89,12 @@ def main(input_args):
                matches = find_packages(query, QUERY_OPTS['includeMasked'])
                if matches:
                        pkg = sorted(matches).pop()
-                       ebuild_path = pkg.get_ebuild_path()
+                       ebuild_path = pkg.ebuild_path()
                        if ebuild_path:
                                print os.path.normpath(ebuild_path)
                        else:
                                sys.stderr.write(
-                                       pp.warn("No ebuilds to satisfy %s" % pkg.name)
+                                       pp.warn("No ebuilds to satisfy %s" % pkg.cpv.name)
                                )
                else:
                        raise errors.GentoolkitNoMatches(query)
index 277e41fd62c5a54a51be8d8cdec75011351e9742..6956f9788ebca2a22f07fc0cca9ccf14f4ffb657 100644 (file)
@@ -91,20 +91,12 @@ class ChangeLog(object):
                # Process the ChangeLog:
                self.entries = self._split_changelog()
                self.indexed_entries = self._index_changelog()
+               self.full = self.entries
+               self.latest = self.entries[0]
 
        def __repr__(self):
                return "<%s %r>" % (self.__class__.__name__, self.changelog_path)
 
-       @property
-       def full(self):
-               """Return the output of L{self._split_changelog}."""
-               return self.entries
-
-       @property
-       def latest(self):
-               """Return the newest ChangeLog entry."""
-               return self.entries[0]
-
        def entries_matching_atom(self, atom):
                """Return entries whose header versions match atom's version.
 
@@ -280,7 +272,9 @@ class FileOwner(object):
                        # we can use re.match, else use re.search.
                        use_match = True
 
-               return self.find_owners(query_re, use_match=use_match)
+               pkgset = get_installed_cpvs()
+
+               return self.find_owners(query_re, use_match=use_match, pkgset=pkgset)
 
        def find_owners(self, query_re, use_match=False, pkgset=None):
                """Find owners and feed data to supplied output function.
@@ -302,10 +296,8 @@ class FileOwner(object):
 
                results = []
                found_match = False
-               if pkgset is None:
-                       pkgset = get_installed_cpvs()
                for pkg in sorted([Package(x) for x in pkgset]):
-                       files = pkg.get_contents()
+                       files = pkg.parsed_contents()
                        for cfile in files:
                                match = query_fn(cfile)
                                if match:
@@ -366,9 +358,8 @@ def compare_package_strings(pkg1, pkg2):
        """Similar to the builtin cmp, but for package strings. Usually called
        as: package_list.sort(compare_package_strings)
 
-       An alternative is to use the Package descriptor from gentoolkit.package
-       >>> pkgs = [Package(x) for x in package_list]
-       >>> pkgs.sort()
+       An alternative is to use the CPV descriptor from gentoolkit.cpv:
+       >>> cpvs = sorted(CPV(x) for x in package_list)
 
        @see: >>> help(cmp)
        """
index 545d4f36880d38cbc1acbaba8032bdd32caa1b0b..792e65fcac8c44b6c3585ddfa29b0751c280a283 100644 (file)
                >>> pkg_md = MetaData('/usr/portage/app-misc/gourmet/metadata.xml')
                >>> pkg_md
                <MetaData '/usr/portage/app-misc/gourmet/metadata.xml'>
-               >>> pkg_md.get_herds()
+               >>> pkg_md.herds()
                ['no-herd']
-               >>> for maint in pkg_md.get_maintainers():
+               >>> for maint in pkg_md.maintainers():
                ...     print "{0} ({1})".format(maint.email, maint.name)
                ...
                nixphoeni@gentoo.org (Joe Sapp)
-               >>> for flag in pkg_md.get_useflags():
+               >>> for flag in pkg_md.use():
                ...     print flag.name, "->", flag.description
                ...
                rtf -> Enable export to RTF
                gnome-print -> Enable printing support using gnome-print
-               >>> upstream = pkg_md.get_upstream()
+               >>> upstream = pkg_md.upstream()
                >>> upstream
                [<_Upstream {'docs': [], 'remoteid': [], 'maintainer':
                 [<_Maintainer 'Thomas_Hinkle@alumni.brown.edu'>], 'bugtracker': [],
@@ -135,24 +135,24 @@ class _Upstream(object):
 
        def __init__(self, node):
                self.node = node
-               self.maintainers = self.get_upstream_maintainers()
-               self.changelogs = self.get_upstream_changelogs()
-               self.docs = self.get_upstream_documentation()
-               self.bugtrackers = self.get_upstream_bugtrackers()
-               self.remoteids = self.get_upstream_remoteids()
+               self.maintainers = self.upstream_maintainers()
+               self.changelogs = self.upstream_changelogs()
+               self.docs = self.upstream_documentation()
+               self.bugtrackers = self.upstream_bugtrackers()
+               self.remoteids = self.upstream_remoteids()
 
        def __repr__(self):
                return "<%s %r>" % (self.__class__.__name__, self.__dict__)
 
-       def get_upstream_bugtrackers(self):
+       def upstream_bugtrackers(self):
                """Retrieve upstream bugtracker location from xml node."""
                return [e.text for e in self.node.findall('bugs-to')]
 
-       def get_upstream_changelogs(self):
+       def upstream_changelogs(self):
                """Retrieve upstream changelog location from xml node."""
                return [e.text for e in self.node.findall('changelog')]
 
-       def get_upstream_documentation(self):
+       def upstream_documentation(self):
                """Retrieve upstream documentation location from xml node."""
                result = []
                for elem in self.node.findall('doc'):
@@ -160,11 +160,11 @@ class _Upstream(object):
                        result.append((elem.text, lang))
                return result
 
-       def get_upstream_maintainers(self):
+       def upstream_maintainers(self):
                """Retrieve upstream maintainer information from xml node."""
                return [_Maintainer(m) for m in self.node.findall('maintainer')]
 
-       def get_upstream_remoteids(self):
+       def upstream_remoteids(self):
                """Retrieve upstream remote ID from xml node."""
                return [(e.text, e.get('type')) for e in self.node.findall('remote-id')]
 
@@ -215,7 +215,7 @@ class MetaData(object):
                        if node.findtext('name') == herd:
                                return node.findtext('email')
 
-       def get_herds(self, include_email=False):
+       def herds(self, include_email=False):
                """Return a list of text nodes for <herd>.
 
                @type include_email: bool
@@ -236,7 +236,7 @@ class MetaData(object):
 
                return result
 
-       def get_descriptions(self):
+       def descriptions(self):
                """Return a list of text nodes for <longdescription>.
 
                @rtype: list
@@ -251,7 +251,7 @@ class MetaData(object):
                self._descriptions = [e.text for e in long_descriptions]
                return self._descriptions
 
-       def get_maintainers(self):
+       def maintainers(self):
                """Get maintainers' name, email and description.
 
                @rtype: list
@@ -267,7 +267,7 @@ class MetaData(object):
 
                return self._maintainers
 
-       def get_useflags(self):
+       def use(self):
                """Get names and descriptions for USE flags defined in metadata.
 
                @rtype: list
@@ -283,7 +283,7 @@ class MetaData(object):
 
                return self._useflags
 
-       def get_upstream(self):
+       def upstream(self):
                """Get upstream contact information.
 
                @rtype: list
index ecde59ac5519a7d4aa4d4135117f7b1ecda01537..1759a8cebc37bcf5069df11aba5ef6592c239592 100644 (file)
@@ -7,7 +7,12 @@
 #
 # $Header$
 
-"""Provides classes for accessing Portage db information for a given package."""
+"""Provides an interface to package information stored by package managers.
+
+The package class is the heart of much of Gentoolkit. Given a CPV
+(category/package-version string),
+TODO: finish this docstring
+"""
 
 __all__ = (
        'Package',
@@ -100,7 +105,7 @@ class Package(CPV):
 
                if self._metadata is None:
                        metadata_path = os.path.join(
-                               self.get_package_path(), 'metadata.xml'
+                               self.package_path(), 'metadata.xml'
                        )
                        self._metadata = MetaData(metadata_path)
 
@@ -132,6 +137,15 @@ class Package(CPV):
        def environment(self, envvars, tree=None):
                """Returns one or more of the predefined environment variables.
 
+               Available envvars are:
+               ----------------------
+                       BINPKGMD5  COUNTER         FEATURES   LICENSE  SRC_URI
+                       CATEGORY   CXXFLAGS        HOMEPAGE   PDEPEND  USE
+                       CBUILD     DEFINED_PHASES  INHERITED  PF
+                       CFLAGS     DEPEND          IUSE       PROVIDE
+                       CHOST      DESCRIPTION     KEYWORDS   RDEPEND
+                       CONTENTS   EAPI            LDFLAGS    SLOT
+
                Example usage:
                        >>> pkg = Package('sys-apps/portage-2.1.6.13')
                        >>> pkg.environment('USE')
@@ -162,16 +176,13 @@ class Package(CPV):
                        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"""
 
                return bool(PORTDB.cpv_exists(str(self.cpv)))
 
        @staticmethod
-       def get_settings(key):
+       def settings(key):
                """Returns the value of the given key for this package (useful
                for package.* files."""
 
@@ -183,7 +194,7 @@ class Package(CPV):
                        settings.lock()
                return result
 
-       def get_mask_status(self):
+       def mask_status(self):
                """Shortcut to L{portage.getmaskingstatus}.
 
                @rtype: None or list
@@ -208,7 +219,7 @@ class Package(CPV):
 
                return result
 
-       def get_mask_reason(self):
+       def mask_reason(self):
                """Shortcut to L{portage.getmaskingreason}.
 
                @rtype: None or tuple
@@ -219,7 +230,7 @@ class Package(CPV):
                try:
                        result = portage.getmaskingreason(str(self.cpv),
                                settings=settings,
-                               PORTDB=PORTDB,
+                               portdb=PORTDB,
                                return_location=True)
                        if result is None:
                                result = tuple()
@@ -230,13 +241,13 @@ class Package(CPV):
 
                return result
 
-       def get_ebuild_path(self, in_vartree=False):
+       def ebuild_path(self, in_vartree=False):
                """Returns the complete path to the .ebuild file.
 
                Example usage:
-                       >>> pkg.get_ebuild_path()
+                       >>> pkg.ebuild_path()
                        '/usr/portage/sys-apps/portage/portage-2.1.6.13.ebuild'
-                       >>> pkg.get_ebuild_path(in_vartree=True)
+                       >>> pkg.ebuild_path(in_vartree=True)
                        '/var/db/pkg/sys-apps/portage-2.1.6.13/portage-2.1.6.13.ebuild'
                """
 
@@ -244,30 +255,30 @@ class Package(CPV):
                        return VARDB.findname(str(self.cpv))
                return PORTDB.findname(str(self.cpv))
 
-       def get_package_path(self):
+       def package_path(self):
                """Return the path to where the ebuilds and other files reside."""
 
                if self._package_path is None:
-                       path_split = self.get_ebuild_path().split(os.sep)
+                       path_split = self.ebuild_path().split(os.sep)
                        self._package_path = os.sep.join(path_split[:-1])
 
                return self._package_path
 
-       def get_repo_name(self):
-               """Using the package path, determine the repo name.
+       def repo_id(self):
+               """Using the package path, determine the repository id.
 
                @rtype: str
-               @return: /usr/<THIS>portage</THIS>/cat-egory/name/
+               @return: /usr/<THIS>portage</THIS>/category/name/
                """
 
-               return self.get_package_path().split(os.sep)[-3]
+               return self.package_path().split(os.sep)[-3]
 
-       def get_use_flags(self):
+       def use(self):
                """Returns the USE flags active at time of installation."""
 
                return self.dblink.getstring("USE")
 
-       def get_contents(self):
+       def parsed_contents(self):
                """Returns the parsed CONTENTS file.
 
                @rtype: dict
@@ -276,14 +287,14 @@ class Package(CPV):
 
                return self.dblink.getcontents()
 
-       def get_size(self):
+       def size(self):
                """Estimates the installed size of the contents of this package.
 
                @rtype: tuple
                @return: (size, number of files in total, number of uncounted files)
                """
 
-               contents = self.get_contents()
+               contents = self.parsed_contents()
                size = n_uncounted = n_files = 0
                for cfile in contents:
                        try:
@@ -354,11 +365,11 @@ class PackageFormatter(object):
        def __str__(self):
                if self.do_format:
                        maskmodes = ['  ', ' ~', ' -', 'M ', 'M~', 'M-', 'XX']
-                       return "[%(location)s] [%(mask)s] %(package)s (%(slot)s)" % {
+                       return "[%(location)s] [%(mask)s] %(package)s:%(slot)s" % {
                                'location': self.location,
                                'mask': pp.maskflag(maskmodes[self.format_mask_status()[0]]),
                                'package': pp.cpv(str(self.pkg.cpv)),
-                               'slot': self.pkg.environment("SLOT")
+                               'slot': pp.slot(self.pkg.environment("SLOT"))
                        }
                else:
                        return str(self.pkg.cpv)
@@ -409,11 +420,11 @@ class PackageFormatter(object):
                """
 
                result = 0
-               masking_status = self.pkg.get_mask_status()
+               masking_status = self.pkg.mask_status()
                if masking_status is None:
                        return (6, [])
 
-               if ("~%s keyword" % self.pkg.get_settings("ARCH")) in masking_status:
+               if ("~%s keyword" % self.pkg.settings("ARCH")) in masking_status:
                        result += 1
                if "missing keyword" in masking_status:
                        result += 2
index db8a3687037785e5a92d27214bbb0fac48fff707..8f619e3766996d2a3b470b01ea495cf19cdfb379 100644 (file)
@@ -120,9 +120,9 @@ def subsection(string):
        """Print a string as a subsection header."""
        return output.turquoise(string)
 
-def useflag(string, enabled=False):
+def useflag(string, enabled=True):
        """Print a USE flag string"""
-       return output.red(string) if enabled else output.blue(string)
+       return output.green(string) if enabled else output.blue(string)
 
 def warn(string):
        """Print a warning string to stderr."""
index fdbcaed7588fc8b7dc737b8df09d3154b58e021a..ba06995b1c58fbda63ac0d6139ccf925e8242951 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -1,5 +1,7 @@
 #!/usr/bin/env python
 
+from __future__ import with_statement
+
 import os
 import re
 import sys