tools/userland-incorporator
author Mike Sullivan <Mike.Sullivan@Oracle.COM>
Wed, 30 Mar 2016 10:07:29 -0700
changeset 5679 d91b8121bb2a
parent 5571 bd6c9b9b753f
child 5682 94c0ca64c022
permissions -rwxr-xr-x
Sync with build 96.1.
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
#
5571
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
    22
# 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
    23
#
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    24
#
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    25
# 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
    26
#
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    27
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    28
import subprocess
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    29
import json
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    30
import sys
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    31
import getopt
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    32
import re
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    33
import os.path
500
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    34
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    35
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
    36
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    37
def warning(msg):
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    38
    if Werror == True:
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    39
        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
    40
        sys.exit(1)
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    41
    else:
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    42
        print >>sys.stderr, "WARNING: %s" % msg
500
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    43
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    44
class Incorporation(object):
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    45
    name = None
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    46
    version = '5.12'
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    47
    packages = {}
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    48
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    49
    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
    50
        self.name = name
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    51
        self.version = version
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    52
        self.packages = {}
500
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    53
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    54
    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
    55
        # 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
    56
        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
    57
        # 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
    58
        version = re.sub(",[\d\.]+", "", version) 
500
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    59
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    60
        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
    61
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    62
    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
    63
        self.packages[name] = version
500
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    64
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    65
    def __str__(self):
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    66
        result = """
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    67
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
    68
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
    69
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
    70
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
    71
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
    72
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
    73
""" % (self.name, self.version, self.name)
500
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    74
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    75
        names = self.packages.keys()
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    76
        names.sort()
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    77
        for name in names:
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    78
            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
    79
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    80
        return result
500
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    81
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    82
#
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    83
# 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
    84
# 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
    85
# manifests in the package repo.
500
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    86
#
5571
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
    87
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
    88
		       static_file=None):
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
    89
    packages = {}
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
    90
    incorporations = {}
5571
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
    91
    versions = {}
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
    92
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
    93
    #
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
    94
    # 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
    95
    # that file.
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
    96
    #
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
    97
    if static_file:
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
    98
        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
    99
          for line in fp:
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   100
            line = line.partition('#')[0]
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   101
            line = line.rstrip()
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   102
5571
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   103
            try:
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   104
                (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
   105
            except ValueError:
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   106
                pass
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   107
            else:
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   108
                if incorporation not in incorporations:
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   109
                    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
   110
                # 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
   111
                tmp = incorporations[incorporation]
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   112
                tmp.add_package(package, version)
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   113
                versions[package] = version
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   114
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   115
    #
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   116
    # 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
   117
    #
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   118
    if repository:
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   119
        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
   120
                                                            "-s", repository,
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   121
                                                            "-p", publisher],
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   122
                               stdout=subprocess.PIPE)
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   123
        packages = json.load(tmp.stdout)
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   124
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   125
    #
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   126
    # 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
   127
    # the latest one.
5571
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   128
    #
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   129
    for package in packages:
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   130
        pkg_name = package['name']
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   131
        pkg_version = package['version']
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   132
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   133
        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
   134
            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
   135
            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
   136
        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
   137
5571
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   138
    #
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   139
    # 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
   140
    #
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   141
    for package in packages:
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   142
        pkg_name = package['name']
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   143
        pkg_version = package['version']
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   144
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   145
        # 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
   146
        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
   147
            continue
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   148
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   149
        # 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
   150
        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
   151
        
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   152
        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
   153
            # 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
   154
            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
   155
                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
   156
            # 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
   157
            tmp = incorporations[inc_name]
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   158
            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
   159
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   160
    return incorporations
500
3d451539794b 7064724 userland should deliver a consolidation incorporation
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
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
def main_func():
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   163
    global Werror
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   164
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   165
    try: 
5571
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   166
        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
   167
                                    ["repository=", "publisher=", "version=",
5571
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   168
                                     "consolidation=", "destdir=", "Werror",
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   169
				     "static-content-file="])
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   170
    except getopt.GetoptError, e:
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   171
        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
   172
5571
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   173
    static_file = None
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   174
    repository = None
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   175
    publisher = None
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   176
    version = None
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   177
    destdir = None
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   178
    consolidation = None
1591
24aca88f3e99 17852021 userland-incorporator should detect duplicate packages
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 1517
diff changeset
   179
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   180
    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
   181
        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
   182
            static_file = arg
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   183
        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
   184
            repository = arg
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   185
        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
   186
            publisher = 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 ("-v", "--version"):
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   188
            version = 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 ("-d", "--destdir"):
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   190
            destdir = 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 ("-c", "--consolidation"):
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   192
            consolidation = 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 ("-w", "--Werror"):
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   194
            Werror = True
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   195
5571
bd6c9b9b753f 22839226 Migrate Desktop meta-packages to Userland gate
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 2142
diff changeset
   196
    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
   197
                                        static_file)
2142
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   198
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   199
    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
   200
        filename = ''
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   201
        if destdir != None:
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   202
            filename = destdir + '/'
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   203
        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
   204
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   205
        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
   206
        fd = open(filename, "w+")
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   207
        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
   208
        fd.close()
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   209
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   210
if __name__ == "__main__":
813e4817e573 18139749 userland-incorporator should allow generation of multiple incorporations
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1591
diff changeset
   211
    main_func()