version.py revision 45
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
import exceptions
import re
import string
CONSTRAINT_NONE = 0
CONSTRAINT_RELEASE = 100
CONSTRAINT_RELEASE_MAJOR = 101
CONSTRAINT_RELEASE_MINOR = 102
CONSTRAINT_BRANCH = 200
CONSTRAINT_BRANCH_MAJOR = 101
CONSTRAINT_BRANCH_MINOR = 102
CONSTRAINT_SEQUENCE = 300
class DotSequence(object):
"""A DotSequence is the typical "x.y.z" string used in software
versioning. We define the "major release" value and the "minor release"
value as the first two numbers in the sequence."""
if m == None:
raise IllegalDotSequence
return True
return False
return True
return False
return True
return False
return True
return False
"""Return true if self is a "subsequence" of other, meaning that
other and self have identical components, up to the length of
self's sequence."""
return False
return False
return True
return True
return False
return False
return True
return False
"""Version format is release[,build_release]-branch:timestamp, which we
decompose into three DotSequences and the timestamp. The
release and branch DotSequences are interpreted normally, where v1 < v2
implies that v2 is a later release or branch. The build_release
DotSequence records the system on which the package binaries were
constructed. Interpretation of the build_release by the client is that,
in the case b1 < b2, a b1 package can be run on either b1 or b2
systems,while a b2 package can only be run on a b2 system."""
# XXX If illegally formatted, raise exception.
if m != None:
return
if m != None:
return
if m != None:
return
assert build_string != None
if m != None:
return
# Sequence omitted?
if m != None:
return
# Branch omitted?
if m != None:
return
raise IllegalVersion
"""target is a DotSequence for the target system."""
return True
return False
def get_short_version(self):
def get_timestamp(self):
if other == None:
return True
return False
return True
if other == None:
return False
return True
return False
return True
return False
return True
return False
return True
return False
return True
return False
return True
return False
return True
return False
return -1
return 1
return -1
return 1
return 0
"""Evaluate true if self is a successor version to other.
The loosest constraint is CONSTRAINT_NONE (None is treated
equivalently, which is a simple test for self > other. As we
proceed through the policies we get stricter, depending on the
selected constraint.
For CONSTRAINT_RELEASE, self is a successor to other if all of
the components of other's release match, and there are later
components of self's version. The branch and timestamp
components are ignored.
For CONSTRAINT_RELEASE_MAJOR and CONSTRAINT_RELEASE_MINOR, other
is effectively truncated to [other[0]] and [other[0], other[1]]
prior to being treated as for CONSTRAINT_RELEASE.
Similarly for CONSTRAINT_BRANCH, the release fields of other and
self are expected to be identical, and then the branches are
compared as releases were for the CONSTRAINT_RELEASE* policies.
"""
if constraint == CONSTRAINT_RELEASE:
if constraint == CONSTRAINT_BRANCH:
raise ValueError, "constraint has unknown value"
if __name__ == "__main__":