예제 #1
0
def find_publishes(client, source, target):
    ret = []
    if not re.search(r'{[0-9]+}', target):
        lg.error(
            "Source publish is regular expression but target does not refer any match groups. See help for more info."
        )
        sys.exit(1)
    lg.debug(
        "Looking for source publishes matching regular expression: {0}".format(
            source))
    publishes = Publish._get_publishes(client)
    re_source = re.compile(source)
    for publish in publishes:
        name = "{}{}{}".format(
            publish['Storage'] + ":" if publish['Storage'] else "",
            publish['Prefix'] + "/" if publish['Prefix'] else "",
            publish['Distribution'])
        match = re_source.match(name)
        if match:
            try:
                target_parsed = target.format(*match.groups())
            except IndexError:
                lg.error(
                    "Can't format target publish {0} using groups {1}".format(
                        target, match.groups()))
                sys.exit(1)
            ret.append((name, target_parsed))
    return ret
예제 #2
0
def action_publish(client,
                   publishmgr,
                   config_file,
                   recreate=False,
                   no_recreate=False,
                   force_overwrite=False,
                   publish_contents=False,
                   acquire_by_hash=False,
                   publish_dist=None,
                   publish_names=None,
                   architectures=None,
                   only_latest=False,
                   components=[]):
    if not architectures:
        architectures = []
    snapshots = Publish._get_snapshots(client)

    config = load_config(config_file)
    for name, repo in config.get('mirror', {}).items():
        snapshot = get_latest_snapshot(snapshots, name)
        if not snapshot:
            continue
        publishmgr.add(component=repo.get('component', 'main'),
                       distributions=repo['distributions'],
                       storage=repo.get('storage', ""),
                       snapshot=snapshot)
        for arch in repo.get('architectures', []):
            if arch not in architectures:
                architectures.append(arch)

    for name, repo in config.get('repo', {}).items():
        snapshot = get_latest_snapshot(snapshots, name)
        if not snapshot:
            continue
        publishmgr.add(component=repo.get('component', 'main'),
                       distributions=repo['distributions'],
                       storage=repo.get('storage', ""),
                       snapshot=snapshot)
        for arch in repo.get('architectures', []):
            if arch not in architectures:
                architectures.append(arch)

    publishmgr.do_publish(recreate=recreate,
                          no_recreate=no_recreate,
                          force_overwrite=force_overwrite,
                          acquire_by_hash=acquire_by_hash,
                          publish_contents=publish_contents,
                          dist=publish_dist,
                          names=publish_names,
                          architectures=architectures,
                          only_latest=only_latest,
                          config=config,
                          components=components)
예제 #3
0
def action_promote(client, source, target, components=None, recreate=False,
                   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:
        action_diff(source=publish_source, target=publish_target, components=components)
    else:
        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 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)
예제 #4
0
    def update_list(self):
        self.model.removeRows(0, self.model.rowCount())
        current_repo = self.repo_box.currentText()
        if current_repo == "":
            return
        if current_repo not in self.repo_dictionary.keys():
            self.repo_dictionary[current_repo] = sorted(
                Publish._get_packages(self.data_manager.get_client(), "repos",
                                      current_repo))

        if self.repo_dictionary[current_repo]:
            for package in self.repo_dictionary[current_repo]:
                item = QStandardItem(package)
                item.setCheckable(True)
                item.setCheckState(Qt.Unchecked)
                self.model.appendRow(item)
            self.package_label.setModel(self.model)
예제 #5
0
    def get_package_from_publish_component(self, publish, component):
        snapshot = self.publish_dict[publish].components[component][0]

        return sorted(Publish._get_packages(self.client, "snapshots",
                                            snapshot))
예제 #6
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)
 def load_snapshot(self, name):
     return Publish.get_packages(self.data_manager.get_client(), "snapshots", name)
예제 #8
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)
예제 #9
0
def action_promote(client,
                   source,
                   target,
                   components=None,
                   recreate=False,
                   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:
        action_diff(source=publish_source,
                    target=publish_target,
                    components=components)
    else:
        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 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)
예제 #10
0
    def run(self):
        publish_dict = {}
        repo_dict = {}

        try:
            publishes = self.client.do_get('/publish')
            repos = self.client.do_get('/repos')
        except Exception as e:
            self.log.emit(e, "error")
            self.terminate()

        i = 0
        nb_max = len(publishes) + len(repos)

        for repo in repos:
            i += 1
            self.log.emit("Loading repository {0}".format(repo["Name"]),
                          "info")
            self.progress.emit(i / nb_max * 100)
            repo_dict[repo["Name"]] = sorted(
                Publish._get_packages(self.data_manager.get_client(), "repos",
                                      repo["Name"]))

        for publish in publishes:
            i += 1
            name = "{}{}{}".format(
                publish['Storage'] + ":" if publish['Storage'] else "",
                publish['Prefix'] + "/" if publish['Prefix'] else "",
                publish['Distribution'])

            # Only publishes made of snapshots are loaded, others are managed in the repository tab
            if publish['SourceKind'] != 'snapshot':
                continue

            self.progress.emit(i / nb_max * 100)
            self.log.emit("Loading publish {0}".format(name), "info")

            tmp = Publish(self.client,
                          name,
                          load=True,
                          storage=publish.get('Storage', "local"))
            publish_dict[name] = tmp

            for snapshot in tmp.publish_snapshots:
                try:
                    if self.cancelled:
                        self.terminate()
                    self.log.emit(
                        "Loading snapshot {0} of publish {1}".format(
                            snapshot["Name"], name), "debug")
                    Publish._get_packages(self.client, "snapshots",
                                          snapshot["Name"])
                except Exception as e:
                    self.log.emit(
                        "Failed to fetch snapshot {0}: {1}".format(
                            snapshot["Name"], e), "error")
            if self.cancelled:
                self.terminate()

        self.log.emit("Successfully loaded publishes", "success")
        self.data_manager.publish_dict = publish_dict
        self.data_manager.repo_dict = repo_dict