src/modules/dependency.py
author Shawn Walker <swalker@opensolaris.org>
Sat, 28 Jun 2008 18:54:10 -0500
changeset 409 713e20963dc2
parent 48 03abcbec50dc
child 1516 8c950a3b4171
permissions -rw-r--r--
2314 shebang lines should use minimum python version
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
409
713e20963dc2 2314 shebang lines should use minimum python version
Shawn Walker <swalker@opensolaris.org>
parents: 48
diff changeset
     1
#!/usr/bin/python2.4
14
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     2
#
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     3
# CDDL HEADER START
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     4
#
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     5
# The contents of this file are subject to the terms of the
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     6
# Common Development and Distribution License (the "License").
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     7
# You may not use this file except in compliance with the License.
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     8
#
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    11
# See the License for the specific language governing permissions
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    12
# and limitations under the License.
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    13
#
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    19
#
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    20
# CDDL HEADER END
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    21
#
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    22
20
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
    23
#
409
713e20963dc2 2314 shebang lines should use minimum python version
Shawn Walker <swalker@opensolaris.org>
parents: 48
diff changeset
    24
# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
14
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    25
# Use is subject to license terms.
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    26
#
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    27
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    28
REQUIRE = 0
48
03abcbec50dc outline install transaction; poke at dependencies in manifests
Stephen Hahn <sch@sun.com>
parents: 33
diff changeset
    29
OPTIONAL = 1
03abcbec50dc outline install transaction; poke at dependencies in manifests
Stephen Hahn <sch@sun.com>
parents: 33
diff changeset
    30
INCORPORATE = 10
14
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    31
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    32
class Dependency(object):
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    33
        """A Dependency object is a relationship between one Package and
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    34
        another.  It is a bidirectional expression.
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    35
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    36
        A package may require a minimum version of another package."""
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    37
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    38
        def __init__(self, host_pkg_fmri, req_pkg_fmri, type = REQUIRE):
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    39
                self.host_pkg_fmri = host_pkg_fmri
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    40
                self.req_pkg_fmri = req_pkg_fmri
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    41
48
03abcbec50dc outline install transaction; poke at dependencies in manifests
Stephen Hahn <sch@sun.com>
parents: 33
diff changeset
    42
                assert type == REQUIRE \
03abcbec50dc outline install transaction; poke at dependencies in manifests
Stephen Hahn <sch@sun.com>
parents: 33
diff changeset
    43
                    or type == INCORPORATE \
03abcbec50dc outline install transaction; poke at dependencies in manifests
Stephen Hahn <sch@sun.com>
parents: 33
diff changeset
    44
                    or type == OPTIONAL
03abcbec50dc outline install transaction; poke at dependencies in manifests
Stephen Hahn <sch@sun.com>
parents: 33
diff changeset
    45
14
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    46
                self.type = type
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    47
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    48
        def satisfied(self, pkg_fmri):
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    49
                # compare pkg_fmri to req_pkg_fmri
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    50
                # compare versions
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    51
                return False
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    52
20
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
    53
	def __repr__(self):
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
    54
		if self.type == REQUIRE:
48
03abcbec50dc outline install transaction; poke at dependencies in manifests
Stephen Hahn <sch@sun.com>
parents: 33
diff changeset
    55
			return "%s => %s" % \
03abcbec50dc outline install transaction; poke at dependencies in manifests
Stephen Hahn <sch@sun.com>
parents: 33
diff changeset
    56
				(self.host_pkg_fmri, self.req_pkg_fmri)
03abcbec50dc outline install transaction; poke at dependencies in manifests
Stephen Hahn <sch@sun.com>
parents: 33
diff changeset
    57
		elif self.type == OPTIONAL:
03abcbec50dc outline install transaction; poke at dependencies in manifests
Stephen Hahn <sch@sun.com>
parents: 33
diff changeset
    58
			return "%s o> %s" % \
20
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
    59
				(self.host_pkg_fmri, self.req_pkg_fmri)
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
    60
		elif self.type == INCORPORATE:
48
03abcbec50dc outline install transaction; poke at dependencies in manifests
Stephen Hahn <sch@sun.com>
parents: 33
diff changeset
    61
			return "%s >> %s" % \
20
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
    62
				(self.host_pkg_fmri, self.req_pkg_fmri)