39N/A# The contents of this file are subject to the terms of the 39N/A# Common Development and Distribution License (the "License"). 39N/A# You may not use this file except in compliance with the License. 39N/A# See the License for the specific language governing permissions 39N/A# and limitations under the License. 39N/A# When distributing Covered Code, include this CDDL HEADER in each 39N/A# If applicable, add the following below this CDDL HEADER, with the 39N/A# fields enclosed by brackets "[]" replaced with your own identifying 39N/A# information: Portions Copyright [yyyy] [name of copyright owner] 3312N/A# Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved. 3041N/A """Private helper function that returns a compiled version of a 3041N/A dictionary of fnmatch patterns.""" 3041N/A """Private helper function: given an action, return True if any of its 3041N/A attributes' values matches the pattern for the same attribute in the 3041N/A attr_match dictionary, and False otherwise. Note that the patterns must 3041N/A be pre-comiled using re.compile() or _compile_fnpats.""" 2690N/A """Returns the serialized state of this object in a format 2690N/A that that can be easily stored using JSON, pickle, etc.""" 2690N/A """Allocate a new object using previously serialized state 2690N/A obtained via getstate().""" 2690N/A # decode serialized state into python objects 39N/A """A Manifest is the representation of the actions composing a specific 39N/A package version on both the client and the repository. Both purposes 39N/A utilize the same storage format. 205N/A The serialized structure of a manifest is an unordered list of actions. 205N/A The special action, "set", represents a package attribute. 39N/A The reserved attribute, "fmri", represents the package and version 39N/A described by this manifest. It is available as a string via the 39N/A attributes dictionary, and as an FMRI object from the fmri member. 39N/A The list of manifest-wide reserved attributes is 39N/A base_directory Default base directory, for non-user images. 39N/A isa Package is intended for a list of ISAs. 39N/A platform Package is intended for a list of platforms. 39N/A relocatable Suitable for User Image. 39N/A All non-prefixed attributes are reserved to the framework. Third 39N/A parties may prefix their attributes with a reversed domain name, domain 39N/A name, or stock symbol. An example might be 39N/A com.example,supported 39N/A as an indicator that a specific package version is supported by the 39N/A vendor, example.com. 48N/A manifest.null is provided as the null manifest. Differences against the 48N/A null manifest result in the complete set of attributes and actions of 48N/A the non-null manifest, meaning that all operations can be viewed as 48N/A tranitions between the manifest being installed and the manifest already 48N/A present in the image (which may be the null manifest). 1352N/A """A generator function that returns the unsorted manifest 1352N/A contents as lines of text.""" 203N/A """Return three lists of action pairs representing origin and 203N/A destination actions. The first list contains the pairs 203N/A representing additions, the second list contains the pairs 203N/A representing updates, and the third list contains the pairs 1045N/A representing removals. All three lists are in the order in 1045N/A which they should be executed.""" 72N/A # XXX Do we need to find some way to assert that the keys are 1045N/A # No origin was provided, so nothing has been changed or 1045N/A # removed; only added. In addition, this doesn't need 1045N/A # to be sorted since the caller likely already does 2084N/A """handle key values that may be lists""" 2842N/A # Transform list of actions into a dictionary keyed by 2842N/A # action key attribute, key attribute and mediator, or 2842N/A # id if there is no key attribute. 72N/A # XXX Do changed actions need to be sorted at all? This is 72N/A # likely to be the largest list, so we might save significant 72N/A # time by not sorting. Should we sort above? Insert into a 72N/A # singlesort = lambda x: x[0] or x[1] 838N/A """Like the unix utility comm, except that this function 838N/A takes an arbitrary number of manifests and compares them, 838N/A returning a tuple consisting of each manifest's actions 926N/A that are not the same for all manifests, followed by a 3402N/A list of actions that are the same in each manifest. 3402N/A Content hashes for action payloads may be present in 3402N/A both signature-included and signature-excluded 3445N/A variants. In most cases (cmp_policy=None), we only 3402N/A want to compare the signature-included variants. When 3402N/A no-signature-included comparison is requested, simply 2240N/A # Must specify at least one manifest. 838N/A # construct list of dictionaries of actions in each 2240N/A # manifest, indexed by unique key and variant combination 2240N/A # The unique key for each action is based on its 2240N/A # type, key attribute, and unique variants set 3212N/A for v
in (
"mediator-version",
3212N/A "mediator-implementation"):
2240N/A # If there is no key attribute for the 2240N/A # action, then fallback to the object 2240N/A # id for the action as its identifier. 2284N/A # catch duplicate actions here... 838N/A # construct list of key sets in each dict 838N/A # determine which common_keys have common actions 203N/A """Where difference() returns three lists, combined_difference() 315N/A returns a single list of the concatenation of the three.""" 48N/A """Output expects that self is newer than other. Use of sets 48N/A requires that we convert the action objects into some marshalled 48N/A form, otherwise set member identities are derived from the 48N/A object pointers, rather than the contents.""" 2453N/A """Generate contents of dircache file containing all dirctories 2453N/A referenced explicitly or implicitly from self.actions. Include 2453N/A variants as values; collapse variants where possible.""" 2453N/A """Generate contents of mediatorcache file containing all 2453N/A mediators referenced explicitly or implicitly from self.actions. 2453N/A Include variants as values; collapse variants where possible.""" 2453N/A a =
"set name=pkg.mediator " \
2910N/A """Generate set action supplemental data containing all facets 2910N/A and variants from self.actions and size information. Each 2910N/A returned line must be newline-terminated.""" 2910N/A # Package already has these attributes. 2910N/A # List of possible variants and possible values for them. 2910N/A # Seed with declared set of variants as actions may be common to 2910N/A # both and so will not be tagged with variant. 2910N/A # List of possible facets and under what variant combinations 2910N/A # Unique (facet, value) (variant, value) combinations. 2910N/A # Facet applicable to this particular variant 2910N/A # This *must* be sorted to ensure reproducible set 2910N/A # action generation for sizes and to ensure each 2910N/A # combination is actually unique. 2910N/A # Unnecessary if we can guarantee all variants will be 2910N/A # declared at package level. Omit the "variant." prefix 2910N/A # from attribute values since that's implicit and can be 2910N/A # added back when the action is parsed. 2910N/A # Emit a set action for every variant used with possible values 2910N/A # if one does not already exist. 2910N/A # merge_facets needs the variant values sorted and this 2910N/A # is desirable when generating the variant attr anyway. 2910N/A # Get unvarianted facet set. 2910N/A # For each variant combination, remove unvarianted 2910N/A # facets since they are common to all variants. 2910N/A # No facets unique to this combo; 2910N/A # If all possible variant combinations supported by the 2910N/A # package have at least one facet, then the intersection 2910N/A # of facets for all variants can be merged with the 2910N/A # Determine unique set of variant combinations 2910N/A # seen for faceted actions. 2910N/A # For each unique variant combination, determine 2910N/A # if the cartesian product of all variant values 2910N/A # supported by the package for the combination 2910N/A # has been seen. In other words, if the 2910N/A # combination is ((variant.arch,)) and the 2910N/A # package supports (i386, sparc), then both 2910N/A # (variant.arch, i386) and (variant.arch, sparc) 2910N/A # must exist. This code assumes variant values 2910N/A # for each variant are already sorted. 2910N/A # If any combination the package 2910N/A # supports has not been seen for 2910N/A # one or more facets, then some 2910N/A # facets are unique to one or 2910N/A # Merge the facets common to all variants if safe; 2910N/A # if we always merged them, then facets only 2910N/A # used by a single variant (think i386-only or 2910N/A # sparc-only content) would be seen unvarianted 2910N/A # At least one facet is shared between 2910N/A # all variant combinations; move the 2910N/A # common ones to the unvarianted set. 2910N/A # Remove facets common to all combos. 2910N/A # Omit the "facet." prefix from attribute values since 2910N/A # that's implicit and can be added back when the action 2910N/A # If we don't do this, action stringify will 2910N/A # emit this as "set name=pkg.facet" which is 2910N/A # then transformed to "set name=name 2910N/A # value=pkg.facet". Not what we wanted, but is 2910N/A # expected for historical reasons. 2910N/A # Always emit an action enumerating the list of facets 2910N/A # common to all variants, even if there aren't any. 2910N/A # That way if there are also no variant-specific facets, 2910N/A # package operations will know that no facets are used 2910N/A # by the package instead of having to scan the whole 2910N/A # Now emit a pkg.facet action for each variant 2910N/A # combination containing the list of facets unique to 2910N/A # A unique key for each combination is needed, 2910N/A # and using a hash obfuscates that interface 2910N/A # while giving us a reliable way to generate 2910N/A # a reproducible, unique identifier. The key 2910N/A # string below looks like this before hashing: 2910N/A # variant.archi386variant.debug.osnetTrue... 2910N/A # Omit the "facet." prefix from attribute values 2910N/A # since that's implicit and can be added back 2910N/A # when the action is parsed. 2910N/A # Tag action with variants. 2910N/A # Emit pkg.[c]size attribute for [compressed] size of package 2910N/A # running total so a single [c]size action can 2910N/A # Only emit if > 0; actions may be 2910N/A # A unique key for each combination is needed, 2910N/A # and using a hash obfuscates that interface 2910N/A # while giving us a reliable way to generate 2910N/A # a reproducible, unique identifier. The key 2910N/A # string below looks like this before hashing: 2910N/A # facet.docTruevariant.archi386... 2910N/A # The sizes are abbreviated in the name of byte 2453N/A """create dictionary of all actions referenced explicitly or 2453N/A implicitly from self.actions... include variants as values; 2453N/A collapse variants where possible""" 2910N/A # build a dictionary containing all actions tagged w/ 2453N/A # remove any tags if any entries are always delivered (NULL) 2453N/A # could collapse refs where all variants are present 2453N/A # (the current logic only collapses them if at least 2453N/A # one reference is delivered without a facet or 2339N/A """ return a list of directories implicitly or 2339N/A explicitly referenced by this object""" 2339N/A # generate actions that contain directories 2910N/A """A generator function that returns the supported facet 2910N/A attributes (strings) for this package based on the specified (or 2910N/A current) excludes that also match at least one of the patterns 2910N/A provided. Facets must be true or false so a list of possible 2910N/A facet values is not returned.""" 2910N/A # No excludes? Then use the pre-determined set of 2910N/A # If different excludes were specified, then look for pkg.facet 2910N/A # actions containing the list of facets. 2910N/A # Either a pkg.facet.common action or a 2910N/A # pkg.facet.X variant-specific action. 2910N/A # possible a given facet may be 2910N/A # valid for more than one unique 2910N/A # variant combination that's 2910N/A # allowed by current excludes. 2910N/A # Fallback to sifting actions to yield possible. 2910N/A """A generator function that yields a list of tuples of the form 2910N/A (variant, [values]). Where 'variant' is the variant attribute 2910N/A name (e.g. 'variant.arch') and '[values]' is a list of the 2910N/A variant values supported by this package. Variants returned are 2910N/A those allowed by the specified (or current) excludes that also 2910N/A match at least one of the patterns provided.""" 2910N/A # No excludes? Then use the pre-determined set of 2910N/A # If different excludes were specified, then look for 2910N/A # pkg.variant action containing the list of variants. 2910N/A # Ensure variant entries exist (debug 2910N/A # variants may not) via defaultdict. 2910N/A # Fallback to sifting actions to get possible. 2453N/A """A generator function that yields tuples of the form (mediator, 2453N/A mediations) expressing the set of possible mediations for this 2453N/A package, where 'mediations' is a set() of possible mediations for 2453N/A the mediator. Each mediation is a tuple of the form (priority, 2453N/A # generate actions that contain mediators 2453N/A # Consider this mediation unavailable 2453N/A # if it can't be parsed for whatever 838N/A """Generate actions in manifest through ordered callable list""" 3041N/A # These conditions are split by performance. 838N/A """Generate actions in the manifest of type "type" 838N/A through ordered callable list""" 3041N/A # These conditions are split by performance. 2453N/A """Generate actions in the manifest of types "atypes" 2453N/A through ordered callable list.""" 2843N/A """Generate the value of the key attribute for each action 615N/A of type "type" in the manifest.""" 111N/A """Find actions in the manifest which are duplicates (i.e., 111N/A represent the same object) but which are not identical (i.e., 111N/A have all the same attributes).""" 111N/A """Return a key on which actions can be sorted.""" 3312N/A """Parse manifest content, stripping line-continuation 3312N/A characters from the input as it is read; this results in actions 3312N/A with values across multiple lines being passed to the 3312N/A action parsing code whitespace-separated instead. 3312N/A set name=pkg.description value="foo " \ 3312N/A ...will each be passed to action parsing as: 3312N/A set name=pkg.summary value="foo" 3312N/A set name=pkg.description value="foo " "bar baz" 2073N/A # Get an iterable for the string. 1636N/A if not l
or l[
0] ==
"#":
# ignore blank lines & comments 1970N/A # Accumulate errors and continue so that as 1970N/A # much of the action data as possible can be 1713N/A """Populate the manifest with actions. 2073N/A 'content' is an optional value containing either the text 2073N/A representation of the manifest or an iterable of 2608N/A 'excludes' is optional. If provided it must be a length two 2608N/A list with the variants to be excluded as the first element and 2613N/A the facets to be excluded as the second element. 2073N/A 'pathname' is an optional filename containing the location of 2073N/A 'signatures' is an optional boolean value that indicates whether 2073N/A a manifest signature should be generated. This is only possible 2073N/A when 'content' is a string or 'pathname' is provided. 1500N/A # sdict and odict in difference() above, and have that be our 1500N/A # main datastore, rather than the simple list we have now. If 1500N/A # we do that here, we can even assert that the "same" action 1500N/A # can't be in a manifest twice. (The problem of having the same 1500N/A # action more than once in packages that can be installed 1500N/A # together has to be solved somewhere else, though.) 2073N/A # Generate manifest signature based upon 2073N/A # input content, but only if signatures 2962N/A # were requested. In order to interoperate with 2962N/A # older clients, we must use sha-1 here. 2608N/A # Make sure that either no excludes were provided or that both 3110N/A # variants and facet excludes were or that variant, facet and 2026N/A """Remove any actions from the manifest which should be 1500N/A """Performs any needed transformations on the action then adds 1500N/A The "action" parameter is the action object that should be 1500N/A The "excludes" parameter is the variants to exclude from the 2639N/A # XXX handle legacy transition issues; not needed once support 2639N/A # for upgrading images from older releases (< build 151) has 1500N/A # Translate old action to new. 1500N/A # add any set actions to attributes 956N/A """Fill attribute array w/ set action contents.""" 2910N/A # To reduce manifest bloat, size and csize 2910N/A # are set on a single action so need splitting 2910N/A # into separate attributes. 2910N/A # ignore broken set actions 2910N/A # Ensure facet and variant attributes are always lists. 2910N/A # Possible facets list is spread over multiple actions. 2910N/A # Prevent duplicates; it's possible a 2910N/A # given facet may be valid for more than 2910N/A # one unique variant combination that's 2910N/A # allowed by current excludes. 2910N/A # Ancient manifest compatibility. 1007N/A """Produces the search dictionary for a specific manifest. 1007N/A A dictionary is constructed which maps a tuple of token, 1007N/A action type, key, and the value that matched the token to 1007N/A the byte offset into the manifest file. file_path is the 1007N/A path to the manifest file. excludes is the variants which 1007N/A should be allowed in this image. return_line is a debugging 1007N/A flag which makes the function map the information to the 1007N/A string of the line, rather than the byte offset to allow 1100N/A """Translates what actions.generate_indices produces 1100N/A into a dictionary mapping token, action_name, key, and 1100N/A the value that should be displayed for matching that 1100N/A token to byte offsets into the manifest file. 1100N/A The "lst" parameter is the data to be converted. 1100N/A The "cp" parameter is the byte offset into the file 1100N/A for the action which produced lst.""" 1472N/A """This method takes a string representing the on-disk 1472N/A manifest content, and returns a hash value.""" 2962N/A # This must be an SHA-1 hash in order to interoperate with 1890N/A # Byte stream expected, so pass encoded. 1352N/A """Verifies whether the signatures for the contents of 1352N/A the manifest match the specified signature data. Raises 1352N/A the 'BadManifestSignatures' exception on failure.""" 429N/A """Store the manifest contents to disk.""" 315N/A # We specifically avoid sorting manifests before writing 315N/A # them to disk-- there's really no point in doing so, since 315N/A # we'll sort actions globally during packaging operations. 1231N/A """Return a dictionary mapping variant tags to their values.""" 1461N/A """Returns the boolean of the value of the attribute 'key'.""" 2910N/A """Returns an integer tuple of the form (size, csize), where 2910N/A 'size' represents the total uncompressed size, in bytes, of the 2910N/A Manifest's data payload, and 'csize' represents the compressed 2910N/A 'excludes' is a list of a list of variants and facets which 2910N/A should be allowed when calculating the total.""" 2910N/A # If specified excludes match loaded excludes, then use 2910N/A # cached attributes; this is safe as manifest attributes 2910N/A # are reset or updated every time exclude_content, 2910N/A # set_content, or add_action is called. 2910N/A # Facet filtering should never be applied when excluding 2910N/A # actions; only variant filtering. This is ugly, but 2910N/A # allow you to be selective and various bits in 2910N/A # pkg.manifest assume you always filter on both so we 2910N/A # have to fake up a filter for facets. 3110N/A # Excludes list must always have zero or 2+ items; so 2639N/A # append any variants and facets to manifest dict 2910N/A # While variants are package level (you 2910N/A # can't install a package without 2910N/A # setting the variant first), facets 2910N/A # from the current action should only be 2910N/A # included if the action is not 2639N/A # Lists can't be set elements. 838N/A """Return the value for the package attribute 'key'.""" 296N/A """Set the value for the package attribute 'key' to 'value'.""" 2054N/A """This class serves as a wrapper for the Manifest class for callers 2054N/A that need efficient access to package data on a per-action type basis. 2054N/A It achieves this by partitioning the manifest into multiple files (one 2054N/A per action type) and then storing an on-disk cache of the directories 2054N/A explictly and implicitly referenced by the manifest each tagged with 2073N/A """Raises KeyError exception if factored manifest is not present 2073N/A and contents are None; delays reading of manifest until required 2073N/A 'fmri' is a PkgFmri object representing the identity of the 2073N/A 'cache_root' is the pathname of the directory where the manifest 2073N/A and cache files should be stored or loaded from. 2073N/A 'contents' is an optional string to use as the contents of the 2073N/A manifest if a cached copy does not already exist. 2608N/A 'excludes' is optional. If provided it must be a length two 2608N/A list with the variants to be excluded as the first element and 2608N/A the facets to be exclduded as the second element. 2073N/A 'pathname' is an optional string containing the pathname of a 2073N/A manifest. If not provided, it is assumed that the manifest is 2073N/A stored in a file named 'manifest' in the directory indicated by 2144N/A 'cache_root'. If provided, and contents is also provided, then 2144N/A 'contents' will be stored in 'pathname' if it does not already 3110N/A # Make sure that either no excludes were provided or 2+ excludes 956N/A # Do we have a cached copy? 956N/A # we have no cached copy; save one 956N/A # don't specify excludes so on-disk copy has 956N/A # we have a cached copy of the manifest 956N/A # have we computed the dircache? 956N/A """Load all manifest contents from on-disk copy of manifest""" 967N/A """Unload manifest; used to reduce peak memory comsumption 967N/A when downloading new manifests""" 1507N/A """Finish loading.... this part of initialization is common 956N/A to multiple code paths""" 956N/A """ store the current action set; also create per-type 967N/A caches. Return True if data was saved, False if not""" 956N/A # this allows us to try to cache new manifests 1672N/A # when non-root w/o failures. 956N/A """ create manifest.<typename> files to accelerate partial 1507N/A parsing of manifests. Separate from __storeback code to 956N/A allow upgrade to reuse existing on disk manifests""" 2144N/A # Ensure target cache directory and intermediates exist. 2910N/A # create per-action type cache; use rename to avoid corrupt 2910N/A # files if ^C'd in the middle. All action types are considered 2910N/A # so that empty cache files are created if no action of that 2910N/A # type exists for the package (avoids full manifest loads 2910N/A # Add supplemental action data; yes this 2910N/A # does mean the cache is not the same as 2910N/A # retrieved manifest, but that's ok. 2910N/A # Signature verification is done using 2073N/A """Remove all manifest cache files found in the given directory 3034N/A (excluding the manifest itself) and the cache_root if it is 3034N/A # Ensure cache dir is removed if the last cache file is 3034N/A # removed; we don't care if it fails. 2475N/A # Only raise error if failure wasn't due to 2475N/A # cache directory not existing. 2453N/A """Private helper function for loading arbitrary cached manifest 2876N/A # we have cached copy on disk; use it 2876N/A # Cache file is malformed; hopefully due to bugs 2876N/A # that have been resolved (as opposed to actual 2876N/A # corruption). Assume we should just ignore the 2876N/A # cache and load action data. 2876N/A # Ignore errors encountered during cache 2876N/A # dump for this specific case. 2453N/A """ return a list of directories implicitly or explicitly 956N/A """ generate actions of the specified type; 956N/A use already in-memory stuff if already loaded, 956N/A otherwise use per-action types files""" 956N/A # invoke subclass method to generate action by action 2613N/A # This checks if we've already written out the factored 2205N/A # manifest files. If so, we'll use it, and if not, then 2205N/A # we'll load the full manifest. 956N/A # get manifest from disk 956N/A # invoke subclass method to generate action by action 2910N/A # No such action in the manifest; must be done *after* 2910N/A # asserting excludes are correct to avoid hiding 2910N/A # Assume a cached copy exists; if not, tag the action type to 2910N/A # avoid pointless I/O later. 3041N/A # These conditions are split by 2910N/A return # no such action in this manifest 2910N/A """A generator function that returns the supported facet 2910N/A attributes (strings) for this package based on the specified (or 2910N/A current) excludes that also match at least one of the patterns 2910N/A provided. Facets must be true or false so a list of possible 2910N/A facet values is not returned.""" 2910N/A """A generator function that yields a list of tuples of the form 2910N/A (variant, [values]). Where 'variant' is the variant attribute 2910N/A name (e.g. 'variant.arch') and '[values]' is a list of the 2910N/A variant values supported by this package. Variants returned are 2910N/A those allowed by the specified (or current) excludes that also 2910N/A match at least one of the patterns provided.""" 2453N/A """A generator function that yields set actions expressing the 2453N/A set of possible mediations for this package. 956N/A """Load attributes dictionary from cached set actions; 956N/A this speeds up pkg info a lot""" 2910N/A """Returns an integer tuple of the form (size, csize), where 2910N/A 'size' represents the total uncompressed size, in bytes, of the 2910N/A Manifest's data payload, and 'csize' represents the compressed 2910N/A 'excludes' is a list of a list of variants and facets which 2910N/A should be allowed when calculating the total.""" 2054N/A """No assignments to factored manifests allowed.""" 2054N/A assert "FactoredManifests are not dicts" 2928N/A """Store the manifest contents to disk.""" 2073N/A """The absolute pathname of the file containing the manifest.""" 964N/A """Special class for pkgplan's need for a empty manifest; 964N/A the regular null manifest doesn't support get_directories 2054N/A and making the factored manifest code handle this case is 1045N/A """Return three lists of action pairs representing origin and 1045N/A destination actions. The first list contains the pairs 1045N/A representing additions, the second list contains the pairs 1045N/A representing updates, and the third list contains the pairs 1045N/A representing removals. All three lists are in the order in 1045N/A which they should be executed.""" 1045N/A # The difference for this case is simply everything in the 1045N/A # origin has been removed. This is an optimization for 2608N/A # This method is overridden so that self.excludes is never set 2608N/A # on the singleton NullFactoredManifest. 2284N/A """Simple Exception class to handle manifest specific errors"""