def load_snapshot(self, name):
     return Publish.get_packages(self.data_manager.get_client(), "snapshots", name)
Exemple #2
0
def promote(client,
            source,
            target,
            components=None,
            recreate=False,
            no_recreate=False,
            packages=None,
            diff=False,
            force_overwrite=False,
            publish_contents=False,
            acquire_by_hash=False,
            storage=""):
    try:
        publish_source = Publish(client, source, load=True, storage=storage)
    except NoSuchPublish as e:
        lg.error(e)
        sys.exit(1)

    publish_target = Publish(client, target, storage=storage)
    try:
        publish_target.load()
    except NoSuchPublish:
        if diff:
            lg.error("Target publish %s does not exist" % target)
            sys.exit(1)
        # Target doesn't have to exist, it will be created
        pass

    if diff:
        # Only print differences and exit
        action_diff(source=publish_source,
                    target=publish_target,
                    components=components)
        sys.exit(0)

    # Check if target is not already up to date
    diffs, equals = publish_source.compare(publish_target,
                                           components=components)
    if not diffs:
        lg.warn("Target {0} is up to date with source publish {1}".format(
            target, source))
        if not recreate:
            lg.warn("There is nothing to do with target publish {0}".format(
                target))
            sys.exit(0)
        else:
            lg.warn(
                "Recreating target publish {0} on your command".format(target))

    if packages:
        # We are only going to promote specific packages
        packages_promoted = False
        for component, snapshots in publish_source.components.items():
            if components and component not in components:
                # We don't want to promote this component
                continue

            # Get packages to promote
            package_refs = publish_source.get_packages(component=component,
                                                       packages=packages)
            if package_refs:
                # Create snapshot for selected packages
                snapshot_name = 'ext_%s-%s' % (component,
                                               publish_target.timestamp)
                lg.debug(
                    "Creating snapshot %s for component %s of packages: %s" %
                    (snapshot_name, component, packages))
                client.do_post('/snapshots',
                               data={
                                   'Name':
                                   snapshot_name,
                                   'SourceSnapshots':
                                   snapshots,
                                   'Description':
                                   "Promoted packages from snapshots %s: %s" %
                                   (snapshots, packages),
                                   'PackageRefs':
                                   package_refs,
                               })
                publish_target.components[component].append(snapshot_name)
                packages_promoted = True
        if not packages_promoted:
            lg.error(
                "No packages were promoted : are you sure components: %s and packages: %s are valid?"
                % (components, packages))
            sys.exit(1)
    else:
        # Publish whole components
        # Use source publish components structure for creation of target publish
        if not components:
            publish_target.components = copy.deepcopy(
                publish_source.components)
        else:
            for component in components:
                try:
                    publish_target.components[component] = copy.deepcopy(
                        publish_source.components[component])
                except KeyError:
                    lg.error("Component %s does not exist")
                    sys.exit(1)

    publish_target.do_publish(recreate=recreate,
                              no_recreate=no_recreate,
                              force_overwrite=force_overwrite,
                              publish_contents=publish_contents,
                              acquire_by_hash=acquire_by_hash,
                              architectures=publish_source.architectures)
Exemple #3
0
def action_promote(client, source, target, components=None, recreate=False,
                   packages=None, diff=False):
    try:
        publish_source = Publish(client, source, load=True)
    except NoSuchPublish as e:
        lg.error(e)
        sys.exit(1)

    publish_target = Publish(client, target)
    try:
        publish_target.load()
    except NoSuchPublish:
        if diff:
            lg.error("Target publish %s does not exist" % target)
            sys.exit(1)
        # Target doesn't have to exist, it will be created
        pass

    if diff:
        # Only print differences and exit
        action_diff(source=publish_source, target=publish_target, components=components)
        sys.exit(0)

    # Check if target is not already up to date
    diffs, equals = publish_source.compare(publish_target, components=components)
    if not diffs:
        lg.warn("Target is up to date with source publish")
        if not recreate:
            lg.warn("There is nothing to do")
            sys.exit(0)
        else:
            lg.warn("Recreating publish on your command")

    if packages:
        # We are only going to promote specific packages
        for component, snapshots in publish_source.components.iteritems():
            if components and component not in components:
                # We don't want to promote this component
                continue

            # Get packages to promote
            package_refs = publish_source.get_packages(component=component, packages=packages)
            if package_refs:
                # Create snapshot for selected packages
                snapshot_name = 'ext_%s-%s' % (component, publish_target.timestamp)
                lg.debug("Creating snapshot %s for component %s of packages: %s" % (snapshot_name, component, packages))
                client.do_post(
                    '/snapshots',
                    data={
                        'Name': snapshot_name,
                        'SourceSnapshots': snapshots,
                        'Description': "Promoted packages from snapshots %s: %s" % (snapshots, packages),
                        'PackageRefs': package_refs,
                    }
                )
                publish_target.components[component].append(snapshot_name)
    else:
        # Publish whole components
        # Use source publish components structure for creation of target publish
        if not components:
            publish_target.components = copy.deepcopy(publish_source.components)
        else:
            for component in components:
                try:
                    publish_target.components[component] = copy.deepcopy(publish_source.components[component])
                except KeyError:
                    lg.error("Component %s does not exist")
                    sys.exit(1)

    publish_target.do_publish(recreate=recreate)