userland.py revision 45
45N/A#!/usr/bin/python
45N/A#
45N/A# CDDL HEADER START
45N/A#
45N/A# The contents of this file are subject to the terms of the
45N/A# Common Development and Distribution License (the "License").
45N/A# You may not use this file except in compliance with the License.
45N/A#
45N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
45N/A# or http://www.opensolaris.org/os/licensing.
45N/A# See the License for the specific language governing permissions
45N/A# and limitations under the License.
45N/A#
45N/A# When distributing Covered Code, include this CDDL HEADER in each
45N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
45N/A# If applicable, add the following below this CDDL HEADER, with the
45N/A# fields enclosed by brackets "[]" replaced with your own identifying
45N/A# information: Portions Copyright [yyyy] [name of copyright owner]
45N/A#
45N/A# CDDL HEADER END
45N/A#
45N/A
45N/A#
45N/A# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
45N/A#
45N/A
45N/A# Some userland consolidation specific lint checks
45N/A
45N/Aimport pkg.lint.base as base
45N/Aimport re
45N/Aimport os.path
45N/A
45N/Aclass UserlandActionChecker(base.ActionChecker):
45N/A """An opensolaris.org-specific class to check actions."""
45N/A
45N/A name = "userland.action"
45N/A
45N/A def __init__(self, config):
45N/A self.description = _(
45N/A "checks Userland packages for common content errors")
45N/A self.prototype = os.getenv('PROTO_DIR')
45N/A self.runpath_re = [
45N/A re.compile('^/lib/'),
45N/A re.compile('^/usr/'),
45N/A re.compile('^\$ORIGIN/')
45N/A ]
45N/A super(UserlandActionChecker, self).__init__(config)
45N/A
45N/A def startup(self, engine):
45N/A if self.prototype != None:
45N/A engine.info(_("including prototype checks: %s") % self.prototype, msgid=self.name)
45N/A
45N/A def file_exists(self, action, manifest, engine, pkglint_id="001"):
45N/A """Checks for existence in the proto area."""
45N/A
45N/A if self.prototype is None:
45N/A return
45N/A
45N/A if action.name not in ["file", "dir", "link", "hardlink"]:
45N/A return
45N/A
45N/A path = action.attrs["path"]
45N/A fullpath = self.prototype + "/" + path
45N/A if not os.path.exists(fullpath):
45N/A engine.error(
45N/A _("packaged path '%s' missing from proto area") % path,
45N/A msgid="%s%s.0" % (self.name, pkglint_id))
45N/A
45N/A file_exists.pkglint_desc = _("Paths should exist in the proto area.")
45N/A
45N/A def file_content(self, action, manifest, engine, pkglint_id="002"):
45N/A """Checks for file content issues."""
45N/A
45N/A if self.prototype is None:
45N/A return
45N/A
45N/A if action.name is not "file":
45N/A return
45N/A
45N/A import pkg.elf as elf
45N/A
45N/A path = action.attrs["path"]
45N/A fullpath = self.prototype + "/" + path
45N/A
45N/A if elf.is_elf_object(fullpath):
45N/A ed = elf.get_dynamic(fullpath)
45N/A for dir in ed.get("runpath", "").split(":"):
45N/A if dir == None or dir == '':
45N/A continue
45N/A
45N/A match = False
45N/A for expr in self.runpath_re:
45N/A if expr.match(dir):
45N/A match = True
45N/A break
45N/A
45N/A if match == False:
45N/A engine.error(
45N/A _("%s has bad RUNPATH, "
45N/A "includes: %s") % (path, dir),
45N/A msgid="%s%s.1" % (self.name, pkglint_id))
45N/A # additional checks for different content types should go here
45N/A
45N/A file_content.pkglint_desc = _("Paths should not deliver common mistakes.")
45N/A
45N/Aclass UserlandManifestChecker(base.ManifestChecker):
45N/A """An opensolaris.org-specific class to check manifests."""
45N/A
45N/A name = "userland.manifest"
45N/A
45N/A def __init__(self, config):
45N/A self.prototype = os.getenv('PROTO_DIR')
45N/A super(UserlandManifestChecker, self).__init__(config)
45N/A
45N/A def unpackaged_files(self, manifest, engine, pkglint_id="001"):
45N/A if self.prototype == None:
45N/A return
45N/A
45N/A return # skip this check for now. It needs more work
45N/A
45N/A manifest_paths = []
45N/A
45N/A for action in manifest.gen_actions():
45N/A if action.name in ["file", "dir", "link", "hardlink"]:
45N/A manifest_paths.append(action.attrs.get("path"))
45N/A
45N/A for dirname, dirnames, filenames in os.walk(self.prototype):
45N/A dir = dirname[len(self.prototype):]
45N/A for name in filenames + dirnames:
45N/A path = dir + '/' + name
45N/A if path not in manifest_paths:
45N/A engine.error(
45N/A _("unpackaged path '%s' missing from manifest") % path,
45N/A msgid="%s%s.0" % (self.name, pkglint_id))
45N/A
45N/A unpackaged_files.pkglint_dest = _(
45N/A "Prototype paths should be present.")
45N/A