src/modules/flavor/script.py
author Rich Burridge <rich.burridge@sun.com>
Mon, 30 Nov 2009 13:01:40 -0800
changeset 1516 8c950a3b4171
parent 1500 fb15a23b6915
child 1580 2763f36d0eda
permissions -rw-r--r--
10485 move pkg(5) to Python 2.6 10482 upgrade to cherrypy 3.1.2 11836 shebang line for python modules should be python version-agnostic 11950 ldtp used by pkg build process not setup to easily use Python 2.6 11989 pkg python dependency analysis tests fail
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1516
8c950a3b4171 10485 move pkg(5) to Python 2.6
Rich Burridge <rich.burridge@sun.com>
parents: 1500
diff changeset
     1
#!/usr/bin/python
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     2
#
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     3
# CDDL HEADER START
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     4
#
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     5
# The contents of this file are subject to the terms of the
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     6
# Common Development and Distribution License (the "License").
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     7
# You may not use this file except in compliance with the License.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     8
#
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    11
# See the License for the specific language governing permissions
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    12
# and limitations under the License.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    13
#
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    19
#
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    20
# CDDL HEADER END
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    21
#
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    22
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    23
#
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    24
# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    25
# Use is subject to license terms.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    26
#
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    27
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    28
import os
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    29
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    30
import pkg.flavor.base as base
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    31
import pkg.flavor.python as python
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    32
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    33
class ScriptDependency(base.SinglePathDependency):
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    34
        """Class representing the dependency created by having #! at the top
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    35
        of a file."""
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    36
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    37
        def __init__(self, *args, **kwargs):
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    38
                attrs = kwargs.get("attrs", {})
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    39
                attrs["%s.type" % self.DEPEND_DEBUG_PREFIX] = "script"
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    40
                base.SinglePathDependency.__init__(self, attrs=attrs, *args,
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    41
                    **kwargs)
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    42
        
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    43
        def __repr__(self):
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    44
                return "PBDep(%s, %s, %s, %s)" % (self.action, self.dep_path,
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    45
                    self.pkg_vars, self.dep_vars)
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    46
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    47
def process_script_deps(action, proto_dir, pkg_vars, **kwargs):
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    48
        """Given an action and a place to find the file it references, if the
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    49
        file starts with #! a list containing a ScriptDependency is returned.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    50
        Further, if the file is of a known type, it is further analyzed and
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    51
        any dependencies found are added to the list returned."""
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    52
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    53
        # localpath is path to actual file
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    54
        # path is path in installed image
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    55
        if action.name != "file":
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    56
                return []
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    57
1500
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
    58
        f = action.data()
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    59
        l = f.readline()
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    60
        f.close()
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    61
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    62
        # add #! dependency
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    63
        if l.startswith("#!"):
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    64
                # usedlist omits leading /
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    65
                p = (l[2:].split()[0]) # first part of string is path (removes
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    66
                # options)
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    67
                # we don't handle dependencies through links, so fix up the
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    68
                # common one
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    69
                p = p.strip()
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    70
                if p.startswith("/bin"):
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    71
                        p = os.path.join("/usr", p)
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    72
                deps = [ScriptDependency(action, p, pkg_vars, proto_dir)]
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    73
                elist = []
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    74
                if "python" in l:
1500
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
    75
                        ds, errs = python.process_python_dependencies(proto_dir,
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
    76
                            action, pkg_vars)
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    77
                        elist.extend(errs)
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    78
                        deps.extend(ds)
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    79
                return deps, elist
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    80
        return [], []