Ejemplo n.º 1
0
    def _channel_line_format(self, channel, longest_label):
        if self._is_channel_eol(channel):
            eol_status = "EOL"
        else:
            eol_status = ""
        if channel in self.synced_channels:
            sync_status = 'p'
        else:
            sync_status = '.'
        try:
            packages_number = open(constants.CDN_REPODATA_ROOT + '/' + channel + "/packages_num", 'r').read()
        # pylint: disable=W0703
        except Exception:
            packages_number = '?'

        try:
            packages_size = open(constants.CDN_REPODATA_ROOT + '/' + channel + "/packages_size", 'r').read()
            packages_size = human_readable_size(int(packages_size))
        # pylint: disable=W0703
        except Exception:
            packages_size = '?B'

        packages_size = "(%s)" % packages_size
        space = " "
        offset = longest_label - len(channel)
        space += " " * offset

        return "%3s %s %s%s%6s packages %9s" % (eol_status, sync_status, channel, space,
                                                packages_number, packages_size)
Ejemplo n.º 2
0
    def _channel_line_format(self, channel, longest_label):
        if self._is_channel_eol(channel):
            eol_status = "EOL"
        else:
            eol_status = ""
        if channel in self.synced_channels:
            sync_status = 'p'
        else:
            sync_status = '.'
        try:
            packages_number = open(
                constants.CDN_REPODATA_ROOT + '/' + channel + "/packages_num",
                'r').read()
        # pylint: disable=W0703
        except Exception:
            packages_number = '?'

        try:
            packages_size = open(
                constants.CDN_REPODATA_ROOT + '/' + channel + "/packages_size",
                'r').read()
            packages_size = human_readable_size(int(packages_size))
        # pylint: disable=W0703
        except Exception:
            packages_size = '?B'

        packages_size = "(%s)" % packages_size
        space = " "
        offset = longest_label - len(channel)
        space += " " * offset

        return "%3s %s %s%s%6s packages %9s" % (eol_status, sync_status,
                                                channel, space,
                                                packages_number, packages_size)
Ejemplo n.º 3
0
    def print_channel_tree(self, repos=False):
        channel_tree, not_available_channels = self._list_available_channels()

        if not channel_tree:
            log2(
                0,
                0,
                "No available channels were found. Is your %s activated for CDN?"
                % PRODUCT_NAME,
                stream=sys.stderr)
            return

        log(0, "p = previously imported/synced channel")
        log(0, ". = channel not yet imported/synced")
        log(
            0,
            "? = package count not available (try to run cdn-sync --count-packages)"
        )

        log(0, "Base channels:")
        available_base_channels = [
            x for x in sorted(channel_tree) if x not in not_available_channels
        ]
        if not available_base_channels:
            log(0, "      NONE")

        longest_label = len(
            max(available_base_channels +
                [i for l in channel_tree.values() for i in l],
                key=len or ""))
        for channel in available_base_channels:
            if channel in self.synced_channels:
                status = 'p'
            else:
                status = '.'

            try:
                packages_number = open(
                    constants.CDN_REPODATA_ROOT + '/' + channel +
                    "/packages_num", 'r').read()
            # pylint: disable=W0703
            except Exception:
                packages_number = '?'

            try:
                packages_size = open(
                    constants.CDN_REPODATA_ROOT + '/' + channel +
                    "/packages_size", 'r').read()
                packages_size = human_readable_size(int(packages_size))
            # pylint: disable=W0703
            except Exception:
                packages_size = '?B'

            space = " "
            offset = longest_label - len(channel)
            space += " " * offset

            log(
                0, "    %s %s%s%s packages (%s)" %
                (status, channel, space, packages_number, packages_size))
            sources = self.cdn_repository_manager.get_content_sources(channel)
            if repos:
                if sources:
                    for source in sources:
                        log(0, "        %s" % source['relative_url'])
                else:
                    log(0, "        No CDN source provided!")

        # print information about child channels
        for channel in sorted(channel_tree):
            # Print only if there are any child channels
            if len(channel_tree[channel]) > 0:
                log(0, "%s:" % channel)
                for child in sorted(channel_tree[channel]):
                    if child in self.synced_channels:
                        status = 'p'
                    else:
                        status = '.'

                    try:
                        packages_number = open(
                            constants.CDN_REPODATA_ROOT + '/' + child +
                            "/packages_num", 'r').read()
                    # pylint: disable=W0703
                    except Exception:
                        packages_number = '?'

                    try:
                        packages_size = open(
                            constants.CDN_REPODATA_ROOT + '/' + child +
                            "/packages_size", 'r').read()
                        packages_size = human_readable_size(int(packages_size))
                    # pylint: disable=W0703
                    except Exception:
                        packages_size = '?B'

                    space = " "
                    offset = longest_label - len(child)
                    space += " " * offset

                    log(
                        0, "    %s %s%s%s packages (%s)" %
                        (status, child, space, packages_number, packages_size))
                    if repos:
                        sources = self.cdn_repository_manager.get_content_sources(
                            child)
                        if sources:
                            for source in sources:
                                log(0, "        %s" % source['relative_url'])
                        else:
                            log(0, "        No CDN source provided!")