aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Harring <ferringb@gmail.com>2007-04-29 07:36:24 -0700
committerBrian Harring <ferringb@gmail.com>2007-04-29 07:36:24 -0700
commit5af9ac83e27226f5f3d465c9b2a1b60779c00707 (patch)
tree33aff28410f052b9f9c8b91de6c89846f2d945f6 /examples
parentset of quick gross hacks to depends blocker handling to continue the normal '... (diff)
downloadpkgcore-5af9ac83e27226f5f3d465c9b2a1b60779c00707.tar.gz
pkgcore-5af9ac83e27226f5f3d465c9b2a1b60779c00707.tar.bz2
pkgcore-5af9ac83e27226f5f3d465c9b2a1b60779c00707.zip
big ass merge of charlies work, digest/manifest, misc cleanup
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/changed_use.py16
-rw-r--r--examples/pclean.py89
-rwxr-xr-xexamples/pkg_info.py52
3 files changed, 154 insertions, 3 deletions
diff --git a/examples/changed_use.py b/examples/changed_use.py
index cc41e3881..8317242d7 100755
--- a/examples/changed_use.py
+++ b/examples/changed_use.py
@@ -3,6 +3,7 @@
# Copyright 2007 Charlie Shepherd
import sys
+from operator import attrgetter
try:
from pkgcore.util import commandline
@@ -33,6 +34,14 @@ class OptionParser(commandline.OptionParser):
help='print packages that have not changed too')
self.add_option('--quiet', '-q', action='store_true', default=False,
help="don't print changed useflags")
+ self.add_option('--print_type', '-t',
+ type="choice",
+ choices=("slotted_atom", "versioned_atom", "cpvstr"),
+ default="cpvstr",
+ help='''type of atom to output:
+ 'versioned_atom' : a valid versioned atom,
+ 'slotted_atom' : a valid slotted atom,
+ 'cpvstr' : the cpv of the package''')
def check_values(self, values, args):
values, args = commandline.OptionParser.check_values(
@@ -44,6 +53,7 @@ class OptionParser(commandline.OptionParser):
values.repo = domain.repos[1]
values.restrict = OrRestriction(*commandline.convert_to_restrict(args))
+ values.outputter = attrgetter(values.print_type)
return values, ()
def main(options, out, err):
@@ -54,10 +64,10 @@ def main(options, out, err):
current = current[0]
oldflags = built.iuse & built.use
newflags = current.iuse & current.use
- if newflags != oldflags:
- changed_flags = oldflags ^ newflags
+ if (newflags != oldflags) or (current.iuse ^ built.iuse):
+ changed_flags = (oldflags ^ newflags) | (current.iuse ^ built.iuse)
if options.quiet:
- out.write(current.cpvstr)
+ out.write(options.outputter(current))
else:
out.write("for package %s, %d flags have changed:\n\t%s" %
(current.cpvstr, len(changed_flags), ' '.join(changed_flags)))
diff --git a/examples/pclean.py b/examples/pclean.py
new file mode 100644
index 000000000..4e3a4c2f3
--- /dev/null
+++ b/examples/pclean.py
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+
+# Copyright 2007 Charlie Shepherd <masterdriverz@gentoo.org>
+# License: GPL-2
+
+import sys
+from os.path import basename
+
+from snakeoil.osutils import listdir_files, pjoin
+from snakeoil.lists import iflatten_instance
+from snakeoil.currying import partial
+
+
+try:
+ from pkgcore.util import commandline
+ from pkgcore.restrictions import packages
+ from pkgcore.restrictions.boolean import OrRestriction
+ from pkgcore.repository.multiplex import tree as multiplex_tree
+ from pkgcore.fetch import fetchable as fetchable_kls
+ from pkgcore.chksum.errors import ParseChksumError
+ from pkgcore.util.repo_utils import get_virtual_repos
+except ImportError:
+ print >> sys.stderr, 'Cannot import pkgcore!'
+ print >> sys.stderr, 'Verify it is properly installed and/or ' \
+ 'PYTHONPATH is set correctly.'
+ if '--debug' not in sys.argv:
+ print >> sys.stderr, 'Add --debug to the commandline for a traceback.'
+ else:
+ raise
+ sys.exit(1)
+
+class OptionParser(commandline.OptionParser):
+ def __init__(self, **kwargs):
+ commandline.OptionParser.__init__(self, description=__doc__, **kwargs)
+ self.add_option("--exclude", "-e", action='append', dest='excludes')
+ self.add_option("--exclude-file", "-E", action='callback', dest='excludes',
+ callback=commandline.read_file_callback, type="string",
+ help='path to the exclusion file')
+ self.add_option("--ignore-failures", "-i", action="store_true",
+ default=False, help="ignore checksum parsing errors")
+
+ def check_values(self, values, args):
+ values, args = commandline.OptionParser.check_values(
+ self, values, args)
+
+ if args:
+ self.error("This script takes no arguments")
+ domain = values.config.get_default('domain')
+ values.vdb = domain.vdb
+ values.repo = multiplex_tree(*get_virtual_repos(domain.repos, False))
+ values.destdir = domain.settings['fetcher'].distdir
+ values.restrict = OrRestriction(negate=True,
+ *commandline.convert_to_restrict(values.excludes, default=())) \
+ or packages.AlwaysTrue
+
+ return values, ()
+
+def main(options, out, err):
+
+ if options.debug:
+ out.write('starting scanning distdir %s...' % options.distdir)
+ files = set(basename(file) for file in listdir_files(options.distdir))
+
+ if options.debug:
+ out.write('scanning repo...')
+
+ for pkg in options.repo.itermatch(options.restrict, sorter=sorted):
+ try:
+ pfiles = set(fetchable.filename for fetchable in
+ iflatten_instance(pkg.fetchables, fetchable_kls))
+ except ParseChksumError, e:
+ err.write("got corruption error %s with package %s " %
+ (e, pkg.cpvstr), autoline=False)
+ if options.ignorefailures:
+ err.write("skipping...")
+ else:
+ err.write("aborting...")
+ return 1
+ except Exception, e:
+ err.write("got error %s, parsing package %s in repo %s" %
+ (e, pkg.cpvstr, pkg.repo))
+ raise
+
+ # Do it this way to minimise getattr calls
+ out.write(*map(partial(pjoin, options.distdir), (files - pfiles)))
+
+
+if __name__ == '__main__':
+ commandline.main({None: (OptionParser, main)})
diff --git a/examples/pkg_info.py b/examples/pkg_info.py
new file mode 100755
index 000000000..cd865f5de
--- /dev/null
+++ b/examples/pkg_info.py
@@ -0,0 +1,52 @@
+#! /usr/bin/env python
+
+import sys, itertools
+
+try:
+ from pkgcore.util import commandline, parserestrict
+ from pkgcore.restrictions.packages import AlwaysTrue
+ from pkgcore.restrictions.boolean import OrRestriction
+except ImportError:
+ print >> sys.stderr, 'Cannot import pkgcore!'
+ print >> sys.stderr, 'Verify it is properly installed and/or ' \
+ 'PYTHONPATH is set correctly.'
+ if '--debug' not in sys.argv:
+ print >> sys.stderr, 'Add --debug to the commandline for a traceback.'
+ else:
+ raise
+ sys.exit(1)
+
+class OptionParser(commandline.OptionParser):
+ def __init__(self, **kwargs):
+ commandline.OptionParser.__init__(
+ self, description=__doc__, usage='%prog <atom>',
+ **kwargs)
+ def check_values(self, values, args):
+ values, args = commandline.OptionParser.check_values(
+ self, values, args)
+ values.repo = values.config.get_default('domain').repos[1]
+ values.restrict = OrRestriction(*commandline.convert_to_restrict(args))
+ return values, ()
+
+def getter(pkg):
+ return (pkg.key, getattr(pkg, "maintainers", None),
+ getattr(pkg, "herds", None))
+
+def main(options, out, err):
+ for t, pkgs in itertools.groupby(
+ options.repo.itermatch(options.restrict, sorter=sorted), getter):
+ out.write(t[0])
+ out.first_prefix = " "
+ for pkg in pkgs:
+ out.write(pkg.cpvstr)
+ out.first_prefix = ""
+ out.write()
+ for item, values in zip(("maintainer", "herd"), t[1:]):
+ if values:
+ out.write("%s(s): %s" %
+ (item.title(), ', '.join((unicode(x) for x in values))))
+ out.write()
+ out.write()
+
+if __name__ == '__main__':
+ commandline.main({None: (OptionParser, main)})