tools/userland-incorporator
author Mike Sullivan <Mike.Sullivan@Oracle.COM>
Fri, 12 Aug 2016 17:23:26 -0700
changeset 6610 88360f57667e
parent 5682 94c0ca64c022
permissions -rwxr-xr-x
Close of build 106.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
     1
#!/usr/bin/python2.7
500
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     2
#
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     3
# CDDL HEADER START
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     4
#
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     5
# The contents of this file are subject to the terms of the
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     6
# Common Development and Distribution License (the "License").
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     7
# You may not use this file except in compliance with the License.
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     8
#
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    11
# See the License for the specific language governing permissions
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    12
# and limitations under the License.
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    13
#
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    19
#
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    20
# CDDL HEADER END
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    21
#
5682
94c0ca64c022 15558602 TCL_LD_SEARCH_FLAGS is wrongly defined in tclConfig.sh
Shawn Walker-Salas <shawn.walker@oracle.com>
parents: 5571
diff changeset
    22
94c0ca64c022 15558602 TCL_LD_SEARCH_FLAGS is wrongly defined in tclConfig.sh
Shawn Walker-Salas <shawn.walker@oracle.com>
parents: 5571
diff changeset
    23
#
5571
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
    24
# Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
500
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    25
#
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    26
#
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    27
# incorporator - an utility to incorporate packages in a repo
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    28
#
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    29
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    30
import subprocess
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    31
import json
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    32
import sys
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    33
import getopt
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    34
import re
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    35
import os.path
500
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    36
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    37
Werror = False	# set to true to exit with any warning
500
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    38
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    39
def warning(msg):
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    40
    if Werror == True:
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    41
        print >>sys.stderr, "ERROR: %s" % msg
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    42
        sys.exit(1)
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    43
    else:
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    44
        print >>sys.stderr, "WARNING: %s" % msg
500
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    45
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    46
class Incorporation(object):
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    47
    name = None
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    48
    version = '5.12'
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    49
    packages = {}
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    50
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    51
    def __init__(self, name, version):
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    52
        self.name = name
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    53
        self.version = version
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    54
        self.packages = {}
500
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    55
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    56
    def __package_to_str(self, name, version):
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    57
        # strip the :timestamp from the version string
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    58
        version = version.split(':', 1)[0]
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    59
        # strip the ,{build-release} from the version string
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    60
        version = re.sub(",[\d\.]+", "", version) 
500
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    61
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    62
        return "depend fmri=%[email protected]%s facet.version-lock.%s=true type=incorporate" % (name, version, name)
500
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    63
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    64
    def add_package(self, name, version):
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    65
        self.packages[name] = version
500
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    66
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    67
    def __str__(self):
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    68
        result = """
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    69
set name=pkg.fmri value=pkg:/%[email protected]%s
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    70
set name=info.classification value="org.opensolaris.category.2008:Meta Packages/Incorporations"
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    71
set name=org.opensolaris.consolidation value=userland
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    72
set name=pkg.depend.install-hold value=core-os.userland
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    73
set name=pkg.summary value="userland consolidation incorporation (%s)"
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    74
set name=pkg.description value="This incorporation constrains packages from the userland consolidation"
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    75
""" % (self.name, self.version, self.name)
500
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    76
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    77
        names = self.packages.keys()
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    78
        names.sort()
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    79
        for name in names:
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    80
            result += (self.__package_to_str(name, self.packages[name]) + '\n')
500
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    81
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    82
        return result
500
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    83
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    84
#
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    85
# This should probably use the pkg APIs at some point, but this appears to be
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    86
# a stable and less complicated interface to gathering information from the
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    87
# manifests in the package repo.
500
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    88
#
5571
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
    89
def get_incorporations(repository, publisher, inc_version='5.12',
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
    90
		       static_file=None):
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
    91
    packages = {}
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    92
    incorporations = {}
5571
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
    93
    versions = {}
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
    94
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
    95
    #
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
    96
    # if a static file was provided, prime the cache with the contents of
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
    97
    # that file.
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
    98
    #
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
    99
    if static_file:
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   100
        with open(static_file, 'r') as fp:
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   101
          for line in fp:
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   102
            line = line.partition('#')[0]
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   103
            line = line.rstrip()
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   104
5571
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   105
            try:
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   106
                (incorporation, package, version) = re.split(':|@', line)
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   107
            except ValueError:
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   108
                pass
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   109
            else:
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   110
                if incorporation not in incorporations:
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   111
                    incorporations[incorporation] = Incorporation(incorporation, inc_version)
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   112
                # find the incorporation and add the package
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   113
                tmp = incorporations[incorporation]
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   114
                tmp.add_package(package, version)
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   115
                versions[package] = version
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   116
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   117
    #
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   118
    # Load the repository for packages to incorporate.
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   119
    #
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   120
    if repository:
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   121
        tmp = subprocess.Popen(["/usr/bin/pkgrepo", "list", "-F", "json",
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   122
                                                            "-s", repository,
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   123
                                                            "-p", publisher],
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   124
                               stdout=subprocess.PIPE)
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   125
        packages = json.load(tmp.stdout)
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   126
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   127
    #
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   128
    # Check for multiple versions of packages in the repo, but keep track of
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   129
    # the latest one.
5571
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   130
    #
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   131
    for package in packages:
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   132
        pkg_name = package['name']
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   133
        pkg_version = package['version']
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   134
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   135
        if pkg_name in versions:
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   136
            warning("%s is in the repo at multiple versions (%s, %s)" % (pkg_name, pkg_version, versions[pkg_name]))
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   137
            pkg_version = max(pkg_version, versions[pkg_name])
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   138
        versions[pkg_name] = pkg_version
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   139
5571
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   140
    #
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   141
    # Add published packages to the incorporation lists
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   142
    #
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   143
    for package in packages:
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   144
        pkg_name = package['name']
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   145
        pkg_version = package['version']
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   146
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   147
        # skip older packages and those that don't want to be incorporated
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   148
        if 'pkg.tmp.incorporate' not in package or pkg_version != versions[pkg_name]:
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   149
            continue
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   150
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   151
        # a dict inside a list inside a dict
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   152
        incorporate = package['pkg.tmp.incorporate'][0]['value']
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   153
        
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   154
        for inc_name in incorporate:
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   155
            # if we haven't started to build this incorporation, create one.
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   156
            if inc_name not in incorporations:
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   157
                incorporations[inc_name] = Incorporation(inc_name, inc_version)
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   158
            # find the incorporation and add the package
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   159
            tmp = incorporations[inc_name]
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   160
            tmp.add_package(pkg_name, pkg_version)
5571
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   161
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   162
    return incorporations
500
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   163
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   164
def main_func():
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   165
    global Werror
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   166
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   167
    try: 
5571
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   168
        opts, pargs = getopt.getopt(sys.argv[1:], "S:c:s:p:v:d:w",
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   169
                                    ["repository=", "publisher=", "version=",
5571
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   170
                                     "consolidation=", "destdir=", "Werror",
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   171
				     "static-content-file="])
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   172
    except getopt.GetoptError, e:
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   173
        usage(_("illegal option: %s") % e.opt)
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   174
5571
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   175
    static_file = None
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   176
    repository = None
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   177
    publisher = None
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   178
    version = None
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   179
    destdir = None
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   180
    consolidation = None
1591
24aca88f3e99 17852021 userland-incorporator should detect duplicate packages
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 1517
diff changeset
   181
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   182
    for opt, arg in opts:
5571
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   183
        if opt in ("-S", "--static-content-file"):
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   184
            static_file = arg
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   185
        elif opt in ("-s", "--repository"):
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   186
            repository = arg
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   187
        elif opt in ("-p", "--publisher"):
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   188
            publisher = arg
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   189
        elif opt in ("-v", "--version"):
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   190
            version = arg
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   191
        elif opt in ("-d", "--destdir"):
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   192
            destdir = arg
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   193
        elif opt in ("-c", "--consolidation"):
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   194
            consolidation = arg
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   195
        elif opt in ("-w", "--Werror"):
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   196
            Werror = True
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   197
5571
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   198
    incorporations = get_incorporations(repository, publisher, version,
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   199
                                        static_file)
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   200
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   201
    for incorporation_name in incorporations.keys():
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   202
        filename = ''
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   203
        if destdir != None:
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   204
            filename = destdir + '/'
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   205
        filename += os.path.basename(incorporation_name) + '.p5m'
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   206
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   207
        print("Writing %s manifest to %s" % (incorporation_name, filename))
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   208
        fd = open(filename, "w+")
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   209
        fd.write(str(incorporations[incorporation_name]))
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   210
        fd.close()
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   211
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   212
if __name__ == "__main__":
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   213
    main_func()