5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
22 # Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
25 # incorporator - an utility to incorporate packages in a repo
34 from pkg.version import Version
36 Werror = False # set to true to exit with any warning
40 print("ERROR: %s" % msg, file=sys.stderr)
43 print("WARNING: %s" % msg, file=sys.stderr)
45 class Incorporation(object):
50 def __init__(self, name, version):
52 self.version = version
55 def __package_to_str(self, name, version):
56 # strip the :timestamp from the version string
57 version = version.split(':', 1)[0]
58 # strip the ,{build-release} from the version string
59 version = re.sub(",[\d\.]+", "", version)
61 return "depend fmri=%s@%s facet.version-lock.%s=true type=incorporate" % (name, version, name)
63 def add_package(self, name, version):
64 self.packages[name] = version
68 set name=pkg.fmri value=pkg:/%s@%s
69 set name=info.classification value="org.opensolaris.category.2008:Meta Packages/Incorporations"
70 set name=org.opensolaris.consolidation value=userland
71 set name=pkg.depend.install-hold value=core-os.userland
72 set name=pkg.summary value="userland consolidation incorporation (%s)"
73 set name=pkg.description value="This incorporation constrains packages from the userland consolidation"
74 """ % (self.name, self.version, self.name)
76 names = list(self.packages.keys())
79 result += (self.__package_to_str(name, self.packages[name]) + '\n')
84 # This should probably use the pkg APIs at some point, but this appears to be
85 # a stable and less complicated interface to gathering information from the
86 # manifests in the package repo.
88 def get_incorporations(repository, publisher, inc_version='5.11'):
89 tmp = subprocess.Popen(["/usr/bin/pkgrepo", "list", "-F", "json",
92 stdout=subprocess.PIPE,
93 universal_newlines=True)
95 packages = json.load(tmp.stdout)
96 inc_name='consolidation/userland/userland-incorporation'
98 # Check for multiple versions of packages in the repo, but keep track of
101 for package in packages:
102 pkg_name = package['name']
103 pkg_version = package['version']
105 if pkg_name in versions:
106 warning("%s is in the repo at multiple versions (%s, %s)" % (pkg_name, pkg_version, versions[pkg_name]))
107 if(Version(package['version']) < Version(versions[pkg_name])):
108 pkg_version = versions[pkg_name]
109 versions[pkg_name] = pkg_version
111 for package in packages:
112 pkg_name = package['name']
113 pkg_version = package['version']
115 consolidations = package['org.opensolaris.consolidation'][0]['value']
119 # skip older packages and those that explicitly don't want to be incorporated
120 # also skip the incorporation itself
121 if 'pkg.tmp.noincorporate' in package or pkg_version != versions[pkg_name] or pkg_name == inc_name:
124 # If this package is intended to be in any other incorporation than userland skip it.
125 if "userland" not in consolidations:
128 # We don't want to support multiple incorporations for now
129 # a dict inside a list inside a dict
130 # incorporate = package['pkg.tmp.incorporate'][0]['value']
132 # for inc_name in incorporate:
133 # if we haven't started to build this incorporation, create one.
134 if inc_name not in incorporations:
135 incorporations[inc_name] = Incorporation(inc_name, inc_version)
136 # find the incorporation and add the package
137 tmp = incorporations[inc_name]
138 tmp.add_package(pkg_name, pkg_version)
139 return incorporations
145 opts, pargs = getopt.getopt(sys.argv[1:], "c:s:p:v:d:w",
146 ["repository=", "publisher=", "version=",
147 "consolidation=", "destdir=", "Werror"])
148 except getopt.GetoptError as e:
149 usage(_("illegal option: %s") % e.opt)
157 for opt, arg in opts:
158 if opt in ("-s", "--repository"):
160 elif opt in ("-p", "--publisher"):
162 elif opt in ("-v", "--version"):
164 elif opt in ("-d", "--destdir"):
166 elif opt in ("-c", "--consolidation"):
168 elif opt in ("-w", "--Werror"):
171 incorporations = get_incorporations(repository, publisher, version)
173 for incorporation_name in list(incorporations.keys()):
176 filename = destdir + '/'
177 filename += os.path.basename(incorporation_name) + '.p5m'
179 print("Writing %s manifest to %s" % (incorporation_name, filename))
180 fd = open(filename, "w+")
181 fd.write(str(incorporations[incorporation_name]))
184 if __name__ == "__main__":