facet.py revision 3158
941N/A# The contents of this file are subject to the terms of the 941N/A# Common Development and Distribution License (the "License"). 941N/A# You may not use this file except in compliance with the License. 941N/A# See the License for the specific language governing permissions 941N/A# and limitations under the License. 941N/A# When distributing Covered Code, include this CDDL HEADER in each 941N/A# If applicable, add the following below this CDDL HEADER, with the 941N/A# fields enclosed by brackets "[]" replaced with your own identifying 941N/A# information: Portions Copyright [yyyy] [name of copyright owner] 941N/A# Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved. 1230N/A # store information on facets; subclass dict 941N/A # and maintain ordered list of keys sorted 941N/A # subclass __getitem__ so that queries w/ 941N/A # actual facets find match 941N/A # For image planning purposes and to be able to compare facet objects 941N/A # deterministically, facets must be sorted. They are first sorted by 1286N/A # source (more details below), then by length, then lexically. 941N/A # Facets can come from three different sources. 941N/A # SYSTEM facets are facets whose values are assigned by the system. 941N/A # These are usually facets defined in packages which are not set in an 1715N/A # image, and the value assigned by the system is always true. These 941N/A # facets will usually never be found in a Facets dictionary. (Facets 941N/A # dictionaries only contain facets which are explicitly set.) 941N/A # LOCAL facets are facets which have been set locally in an image 941N/A # using pkg(1) or the pkg api. Explicitly set LOCAL facets are stored 1516N/A # in Facets.__local. Facets which are not explicitly set but match an 1715N/A # explicitly set LOCAL facet glob pattern are also considered to be 1682N/A # PARENT facets are facets which are inherited from a parent image. 941N/A # they are managed internally by the packaging subsystem. Explicitly 941N/A # inherited facets are stored in Facets.__inherited. Facets which are 1682N/A # not explicitly set but match an explicitly set PARENT facet glob 941N/A # pattern are also considered to be PARENT. 941N/A # When evaluating facets, all PARENT facets are evaluated before LOCAL 941N/A # facets. This is done by ensuring that all PARENT facets come before 941N/A # any LOCAL facets in __keylist. This is done because PARENT facets 941N/A # exist to propagate faceted dependencies between linked images, which 941N/A # is needed to ensure the solver can run successfully. ie, if a 1715N/A # parent image relaxes dependencies via facet version-locks, then the 941N/A # child needs to inherit those facets since otherwise it is more 941N/A # constrained in possible solutions than it's parent and likely won't 1843N/A # be able to plan an update that keeps it in sync with it's parent. 1843N/A # Sine PARENT facets take priority over LOCAL facets, it's possible to 1843N/A # have conflicts between the two. In the case where a facet is both 1843N/A # inherited and set locally, both values are preserved, but the 1843N/A # inherited value masks the local value. Users can list and update 1843N/A # local values while they are masked using pkg(1), but as long as the 1843N/A # values are masked they will not affect image planning operations. 1843N/A # Once an inherited facet that masks a local facet is removed, the 1843N/A # local facet will be restored. 941N/A """Returns the serialized state of this object in a format 941N/A that that can be easily stored using JSON, pickle, etc.""" 941N/A """Update the state of this object using previously serialized 941N/A state obtained via getstate().""" 1127N/A """Compare the facet match priority of two Facets objects. 1127N/A Since the match priority of a Facets object is dependent upon 1127N/A facet sources (local vs parent) and names, we're essentially 1127N/A ensuring that both objects have the same set of facet sources 1127N/A """Compare the facet values of two Facets objects. This 1127N/A comparison ignores any masked values.""" 1661N/A """Compare all the facet values of two Facets objects. This 1661N/A comparison takes masked values into account.""" 2185N/A """Compare two Facets objects. This comparison takes masked 2185N/A # check if we're getting compared against something other than 1431N/A # Check for effective facet value changes that could affect 1431N/A # Check for facet priority changes that could affect solver 941N/A # computations. (Priority changes can occur when local or 1715N/A # inherited facets are added or removed.) 1360N/A # There are no outwardly visible facet priority or value 1360N/A # changes that could affect solver computations, but it's 941N/A # still possible that we're changing the set of local or 941N/A # inherited facets in a way that doesn't affect solver 941N/A # computations. For example: we could be adding a local 941N/A # facet with a value that is masked by an inherited facet, or 941N/A # having a facet transition from being inherited to being 1516N/A # local without a priority or value change. Check if this is 941N/A """redefine in terms of __cmp__()""" 1127N/A """redefine in terms of __cmp__()""" 1682N/A """redefine in terms of __cmp__()""" 941N/A """redefine in terms of __cmp__()""" 1127N/A """redefine in terms of __cmp__()""" 1682N/A """redefine in terms of __cmp__()""" 941N/A """Update __keysort, which is used to determine facet matching 941N/A order. Inherited facets always take priority over local 1682N/A facets so make sure all inherited facets come before local 941N/A facets in __keylist. All facets from a given source are 941N/A sorted by length, and facets of equal length are sorted 1431N/A # save the facet in the local or inherited dictionary 941N/A # clear the corresponding read-only dictionary 1325N/A # Inherited facets always take priority over local facets. 1115N/A """__setitem__ only operates on local facets.""" 1115N/A """Implement facet lookup algorithm here 941N/A Note that _allow_facet bypasses __getitem__ for performance 941N/A reasons; if __getitem__ changes, _allow_facet in _varcet.c 1115N/A We return a tuple of the form (<key>, <value>) where key is 1115N/A the explicitly set facet name (which may be a glob pattern) 1115N/A that matched the caller specific facet name.""" 1127N/A # The trailing '.' is to encourage namespace usage. 1127N/A # check for an attempt to delete an invalid facet 1127N/A # check for an attempt to delete an invalid local facet 941N/A # we should never try to delete an invalid inherited facet 1715N/A # the inherited value was overriding a local value 941N/A # that should now be exposed 941N/A # delete item from the local or inherited dictionary 941N/A # clear the corresponding read-only dictionary 941N/A """__delitem__ only operates on local facets.""" 941N/A # allow_action is provided as a native function (see end of class 1715N/A """Set an inherited facet.""" 941N/A """Clear all inherited facet.""" 941N/A facets present on an action.""" 941N/A # find all the facets present in the current action 1146N/A # we found a matching facet. 1146N/A # we found a matching facet. 1127N/A """pop() only operates on local facets.""" 1127N/A # check if the user specified a default value 1127N/A """popitem() only operates on local facets.""" 1728N/A # preserve inherited facets. 1354N/A """A facet may be set via multiple sources and hence have 1354N/A multiple values. If there are multiple values for a facet, 1354N/A all but one of those values will be masked. So for a given 1354N/A facet, return a list of tuples of the form (<value>, <src>, 1354N/A <masked>) which represent all currently set values for this 941N/A """Report the source of a facet value if we were to attempt to 941N/A look it up in the current Facets object dictionary.""" 941N/A # For convenience, provide callers with direct access to local and 2028N/A # parent facets via cached read-only dictionaries.