diff options
author | Michał Górny <mgorny@gentoo.org> | 2012-04-09 16:30:38 +0200 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2012-04-09 17:11:14 +0200 |
commit | a2b368da3c260edb3196a3a9c8dd3cc92d36b1b4 (patch) | |
tree | ff5473cf244813b221f34f24cbc97cbe2f3b4c7d /scripts | |
parent | sys-process/ts: Execute tests more portably thanks to mgorny. (diff) | |
download | sunrise-reviewed-a2b368da3c260edb3196a3a9c8dd3cc92d36b1b4.tar.gz sunrise-reviewed-a2b368da3c260edb3196a3a9c8dd3cc92d36b1b4.tar.bz2 sunrise-reviewed-a2b368da3c260edb3196a3a9c8dd3cc92d36b1b4.zip |
Use egencache instead of custom use.local.desc gen.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/review | 5 | ||||
-rwxr-xr-x | scripts/use_desc_gen.py | 205 | ||||
-rw-r--r-- | scripts/use_desc_gen.sh | 56 |
3 files changed, 4 insertions, 262 deletions
diff --git a/scripts/review b/scripts/review index 03e8743e5..f0256c39a 100755 --- a/scripts/review +++ b/scripts/review @@ -89,7 +89,10 @@ if [[ $(git diff profiles/categories) ]]; then exit ;; esac fi -LC_ALL="C" sh scripts/use_desc_gen.sh . || exit $? + +egencache --ignore-default-opts --portdir-overlay=. \ + --repo=sunrise --update-use-local-desc || exit $? + if [[ $(git diff profiles/use.local.desc) ]]; then git diff profiles/use.local.desc | if [[ "$opt_quiet" == "0" ]] ; then less; else cat; fi echo -n "${BOLD}Commit changes?${NORMAL} [${GREEN}Yes${NORMAL}/${RED}No${NORMAL}] " diff --git a/scripts/use_desc_gen.py b/scripts/use_desc_gen.py deleted file mode 100755 index 40d792915..000000000 --- a/scripts/use_desc_gen.py +++ /dev/null @@ -1,205 +0,0 @@ -#!/usr/bin/env python2 -# Written by Alec Warner for the Gentoo Foundation 2008 -# This code is hereby placed into the public domain. - -"""Craws an ebuild repository for local use flags and generates documentation. - -This module attempts to read metadata.xml files in an ebuild repository and -uses the <flag> xml tags to generate a set of documentation for local USE -flags. - -It is a non-goal of this script to validate XML contents. - -CAVEATS: -TEXT, <pkg>, <pkg>, TEXT. is difficult to parse into text and requires icky -rules; see _GetTextFromNode for the nasty details. -""" - -__author__ = "Alec Warner <antarus@gentoo.org>" - -import errno -import logging -import optparse -import os -import re -import sys - -from xml.dom import minidom -from xml.parsers import expat - -METADATA_XML = 'metadata.xml' - - -class RepositoryError(Exception): - """Basic Exception for repository problems.""" - pass - - -def FindMetadataFiles(repo_path, category_path, output=sys.stdout): - """Locate metadata files in repo_path. - - Args: - repo_path: path to repository. - category_path: path to a category file (None is ok). - output: file-like object to write output to. - Returns: - Nothing. - Raises; RepositoryError. - """ - - profile_path = os.path.join(repo_path, 'profiles') - logging.info('path to profile is: %s' % profile_path) - categories = GetCategories(profile_path, category_path) - packages = [] - for cat in categories: - cat_path = os.path.join(repo_path, cat) - logging.debug('path to category %s is %s' % (cat, cat_path)) - try: - tmp_pkgs = GetPackages(cat_path) - except OSError, e: - if e.errno == errno.ENOENT: - logging.error('skipping %s because it was not in %s' % (cat, - repo_path)) - pkg_paths = [os.path.join(cat_path, pkg) for pkg in tmp_pkgs] - packages.extend(pkg_paths) - - total = len(packages) - for num, pkg_path in enumerate(packages): - metadata_path = os.path.join(pkg_path, METADATA_XML) - logging.info('processing %s (%s/%s)' % (metadata_path, num, total)) - try: - f = open(metadata_path, 'rb') - except IOError, e: - if e.errno == errno.ENOENT: - logging.error('Time to shoot the maintainer: %s does not contain a metadata.xml!' % (pkg_path)) - continue - else: - # remember to re-raise if it's not a missing file - raise e - metadata = GetLocalFlagInfoFromMetadataXml(f) - pkg_split = pkg_path.split('/') - for k, v in metadata.iteritems(): - try: - output.write('%s/%s:%s - %s\n' % (pkg_split[-2] ,pkg_split[-1], k, v)) - except UnicodeEncodeError, e: - logging.error('Unicode found in %s, not generating to output' % (pkg_path)) - continue - -def _GetTextFromNode(node): - """Given an XML node, try to turn all it's children into text. - - Args: - node: a Node instance. - Returns: - some text. - - This function has a few tweaks 'children' and 'base_children' which attempt - to aid the parser in determining where to insert spaces. Nodes that have - no children are 'raw text' nodes that do not need spaces. Nodes that have - children are 'complex' nodes (often <pkg> nodes) that usually require a - trailing space to ensure sane output. - - NOTE: The above comment is now bullocks as the regex handles spacing; I may - remove the 'children' crap in a future release but it works for now. - - Strip out \n and \t as they are not valid in use.local.desc. - """ - - if node.nodeValue: - children = 0 - data = node.nodeValue - - whitespace = re.compile('\s+') - data = whitespace.sub(' ', data) - return (data, children) - else: - desc = '' - base_children = 1 - for child in node.childNodes: - child_desc, children = _GetTextFromNode(child) - desc += child_desc - return (desc, base_children) - - -def GetLocalFlagInfoFromMetadataXml(metadata_file): - """Determine use.local.desc information from metadata files. - - Args: - metadata_file: a file-like object holding metadata.xml - """ - - d = {} - - try: - dom_tree = minidom.parseString(metadata_file.read()) - except expat.ExpatError, e: - logging.error('%s (in file: %s)' % (e, metadata_file)) - return d - - flag_tags = dom_tree.getElementsByTagName('flag') - for flag in flag_tags: - use_flag = flag.getAttribute('name') - desc, unused_children = _GetTextFromNode(flag) - desc.strip() - d[use_flag] = desc - - return d - - -def GetPackages(cat_path): - """Return a list of packages for a given category.""" - - files = os.listdir(cat_path) - func = lambda f: f != METADATA_XML and f != 'CVS' and f != '.svn' - files = filter(func, files) - - return files - -def GetCategories(profile_path, categories_path): - """Return a set of categories for a given repository. - - Args: - profile_path: path to profiles/ dir of a repository. - Returns: - a list of categories. - Raises: RepositoryError. - """ - - if not categories_path: - categories_path = os.path.join(profile_path, 'categories') - try: - f = open(categories_path, 'rb') - except (IOError, OSError), e: - raise RepositoryError('Problem while opening %s: %s' % ( - categories_path, e)) - categories = [cat.strip() for cat in f.readlines()] - return categories - - -def GetOpts(): - """Simple Option Parsing.""" - - parser = optparse.OptionParser() - parser.add_option('-r', '--repo_path', help=('path to repository from ' - 'which the documentation will be generated.')) - parser.add_option('-c', '--category_file', help=('path to a category', - 'file if repo_path lacks a profile/category file')) - - opts, unused_args = parser.parse_args() - - if not opts.repo_path: - parser.error('--repo_path is a required option') - - logging.debug('REPO_PATH is %s' % opts.repo_path) - - return (opts, unused_args) - - -def Main(): - """Main.""" - opts, unused_args = GetOpts() - FindMetadataFiles(opts.repo_path, opts.category_file) - - -if __name__ == '__main__': - Main() diff --git a/scripts/use_desc_gen.sh b/scripts/use_desc_gen.sh deleted file mode 100644 index 54f4dc148..000000000 --- a/scripts/use_desc_gen.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/sh -# Written by Douglas Goldstein <cardoe@gentoo.org> -# This code is hereby placed into the public domain -# -# $Id: use_desc_gen.sh,v 1.6 2008/08/23 21:28:28 robbat2 Exp $ - -usage() { - echo "$(basename "$1") /path/to/portage/tree" - exit 1; -} - -if [ $# -ne 1 ]; then - usage "$0"; -fi - -if [ "x${1}" = "x-h" -o "x${1}" = "x--help" ]; then - usage "$0"; -fi - -if [ ! -f "${1}/profiles/use.local.desc" ]; then - usage "$0"; -fi - -pid=$(echo $$) - -# make list of categories that we want to remove from current use.local.desc -#cat "${1}/profiles/use.local.desc" | sed '1,/# The following categories/d;/# End of metadata categories/,$d;s/^../^/' > /tmp/${pid}.grep - -# we also want to remove comments and blank lines -#echo "^#" >> /tmp/${pid}.grep -#echo "^$" >> /tmp/${pid}.grep - -# make list of categories to process with use_desc_gen (same as above without grep rule) -#cat "${1}/profiles/use.local.desc" | sed '1,/# The following categories/d;/# End of metadata categories/,$d;s/^..//' > /tmp/${pid}.categories - -# take comments from existing use.local.desc -grep '^#' "${1}/profiles/use.local.desc" > /tmp/${pid}.use.local.desc || exit 2 -echo "" >> /tmp/${pid}.use.local.desc || exit 2 - -# use list from step #1 to filter current use.local.desc and add un-converted categories to new use.local.desc -#grep -v -f /tmp/${pid}.grep "${1}/profiles/use.local.desc" > /tmp/${pid}.new.use - -# the secret sauce, append to new use.local.desc -python2 scripts/use_desc_gen.py --repo_path "${1}" > /tmp/${pid}.new.use || exit 2 - -# let's keep it sorted: use major category, minor category, and package name -# as primary, secondary, and tertiary sort keys, respectively -sort -t: -k1,1 -k2 /tmp/${pid}.new.use | sort -s -t/ -k1,1 \ - >> /tmp/${pid}.use.local.desc || exit 2 - -# clean up -#rm -rf /tmp/${pid}.categories -#rm -rf /tmp/${pid}.grep -rm -rf /tmp/${pid}.new.use - -mv /tmp/${pid}.use.local.desc profiles/use.local.desc |