#
# 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
#
#
#
import os
"""Reads the pkg(7) publisher JSON formatted data at 'location'
or from the provided file-like object 'fileobj' and returns a
list of tuples of the format (publisher object, pkg_names).
pkg_names is a list of strings representing package names or
FMRIs. If any pkg_names not specific to a publisher were
provided, the last tuple returned will be of the format (None,
pkg_names).
'data' is an optional string containing the p5i data.
'fileobj' is an optional file-like object that must support a
'read' method for retrieving data.
'location' is an optional string value that should either start
with a leading slash and be pathname of a file or a URI string.
If it is a URI string, supported protocol schemes are 'file',
'ftp', 'http', and 'https'.
'data' or 'fileobj' or 'location' must be provided."""
if location is not None:
# Convert the file path to a URI.
try:
except (EnvironmentError, ValueError,
HTTPError) as e:
raise api_errors.RetrievalError(e,
try:
if data is not None:
else:
except (EnvironmentError, HTTPError) as e:
raise api_errors.RetrievalError(e)
except ValueError as e:
# Not a valid JSON file.
raise api_errors.InvalidP5IFile(e)
try:
except KeyError:
except ValueError:
if ver > CURRENT_VERSION:
raise api_errors.UnsupportedP5IFile()
result = []
try:
for p in plist:
if not prefix:
prefix = "Unknown"
for r in p.get("repositories", []):
rargs = {}
for prop in ("collection_type",
"description", "name",
"refresh_seconds",
"registration_uri"):
continue
"origins", "related_uris"):
continue
if pkglist:
return result
"""Writes the publisher, repository, and provided package names to the
provided file-like object 'fileobj' in JSON p5i format.
'fileobj' is an object that has a 'write' method that accepts data to be
written as a parameter.
'pkg_names' is a dict of lists, tuples, or sets indexed by publisher
prefix that contain package names, FMRI strings, or FMRI objects. A
prefix of "" can be used for packages that are that are not specific to
a publisher.
'pubs' is a list of Publisher objects."""
dump_struct = {
"packages": [],
"publishers": [],
"version": CURRENT_VERSION,
}
if pkg_names is None:
pkg_names = {}
# Publisher information is intentionally
# omitted as association with this specific
# publisher is implied by location in the
# output.
else:
for p in pubs:
dpub = {
"alias": p.alias,
"name": p.prefix,
"packages": [],
"repositories": []
}
try:
dpub["packages"])
except KeyError:
pass
if p.repository:
r = p.repository
reg_uri = ""
if r.registration_uri:
"collection_type": r.collection_type,
"description": r.description,
"name": r.name,
"refresh_seconds": r.refresh_seconds,
"registration_uri": reg_uri,
"related_uris": [
u.uri for u in r.related_uris
],
})
try:
except KeyError:
pass