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 >>sys.stderr, "ERROR: %s" % msg
43 print >>sys.stderr, "WARNING: %s" % msg
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 = 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)
94 packages = json.load(tmp.stdout)
95 inc_name='consolidation/userland/userland-incorporation'
97 # Check for multiple versions of packages in the repo, but keep track of
100 for package in packages:
101 pkg_name = package['name']
102 pkg_version = package['version']
104 if pkg_name in versions:
105 warning("%s is in the repo at multiple versions (%s, %s)" % (pkg_name, pkg_version, versions[pkg_name]))
106 if(Version(package['version']) < Version(versions[pkg_name])):
107 pkg_version = versions[pkg_name]
108 versions[pkg_name] = pkg_version
110 for package in packages:
111 pkg_name = package['name']
112 pkg_version = package['version']
114 # skip older packages and those that explicitly don't want to be incorporated
115 # also skip the incorporation itself
116 if 'pkg.tmp.noincorporate' in package or pkg_version != versions[pkg_name] or pkg_name == inc_name:
119 # We don't want to support multiple incorporations for now
120 # a dict inside a list inside a dict
121 # incorporate = package['pkg.tmp.incorporate'][0]['value']
123 # for inc_name in incorporate:
124 # if we haven't started to build this incorporation, create one.
125 if inc_name not in incorporations:
126 incorporations[inc_name] = Incorporation(inc_name, inc_version)
127 # find the incorporation and add the package
128 tmp = incorporations[inc_name]
129 tmp.add_package(pkg_name, pkg_version)
130 return incorporations
136 opts, pargs = getopt.getopt(sys.argv[1:], "c:s:p:v:d:w",
137 ["repository=", "publisher=", "version=",
138 "consolidation=", "destdir=", "Werror"])
139 except getopt.GetoptError, e:
140 usage(_("illegal option: %s") % e.opt)
148 for opt, arg in opts:
149 if opt in ("-s", "--repository"):
151 elif opt in ("-p", "--publisher"):
153 elif opt in ("-v", "--version"):
155 elif opt in ("-d", "--destdir"):
157 elif opt in ("-c", "--consolidation"):
159 elif opt in ("-w", "--Werror"):
162 incorporations = get_incorporations(repository, publisher, version)
164 for incorporation_name in incorporations.keys():
167 filename = destdir + '/'
168 filename += os.path.basename(incorporation_name) + '.p5m'
170 print("Writing %s manifest to %s" % (incorporation_name, filename))
171 fd = open(filename, "w+")
172 fd.write(str(incorporations[incorporation_name]))
175 if __name__ == "__main__":