Exemplo n.º 1
0
    def run_dump(self):
        t = Template(self.args.template, user=self.args.username)

        try:
            t = self.cs.template_get(
                t, resolve_includes=not self.args.no_resolve_includes)

        except ServiceException as e:
            logging.exception(e)
            return 1

        if self.args.kickstart:
            print(t.to_kickstart(resolved=not self.args.no_resolve_includes))
            return 0

        elif self.args.yaml:
            print(
                yaml.dump(
                    t.to_object(resolved=not self.args.no_resolve_includes),
                    indent=4))
            return 0

        elif self.args.json:
            print(
                json.dumps(
                    t.to_object(resolved=not self.args.no_resolve_includes),
                    indent=4,
                    sort_keys=True))
            return 0

        # pretty general information
        print('TEMPLATE: {0} ({1})\n'.format(t.name, t.user))

        if t.description is not None and len(t.description):
            print('Description:\n{0}\n'.format(t.description))

        # pretty print includes
        if len(t.includes):
            l = TextTable(header=['INCLUDE'])
            for i in t.includes:
                l.add_row([i])

            print(l)
            print()

        # pretty print packages
        repos = list(t.repos_all)
        repos.sort(key=lambda x: x.stub)

        if len(repos):
            l = TextTable(header=["REPO", "NAME", "ENABLED", "TEMPLATE"])

            for r in repos:
                cost = r.cost
                if cost is None:
                    cost = '-'

                priority = r.priority
                if priority is None:
                    priority = '-'

                enabled = 'N'
                if r.enabled:
                    enabled = 'Y'

                template = r.template
                if template == t.unv:
                    template = ''

                #l.add_row([r.stub, r.name, priority, cost, enabled])
                l.add_row([r.stub, r.name, enabled, template])

            print(l)
            print()

        # pretty print packages
        packages = list(t.packages_all)
        packages.sort(key=lambda x: x.name)

        if len(packages):
            l = TextTable(header=["PACKAGE", "ACTION", "TEMPLATE"])

            for p in packages:
                if p.included:
                    p.action = '+'

                elif p.excluded:
                    p.action = '-'

                elif p.ignored:
                    p.action = '!'

                else:
                    p.action = '?'

                # no template specified indicates it's part of this template
                if p.template == t.unv:
                    p.template = ''

                l.add_row([p.name, p.action, p.template])

            print(l)
            print()

        return 0
Exemplo n.º 2
0
    def run_dump(self):
        t = Template(self.args.template, user=self.args.username)

        try:
            t = self.cs.template_get(
                t, resolve_includes=not self.args.no_resolve_includes)

        except ServiceException as e:
            print(e)
            return 1

        if self.args.kickstart:
            print(t.to_kickstart(resolved=not self.args.no_resolve_includes))
            return 0

        elif self.args.yaml:
            print(
                yaml.dump(
                    t.to_object(resolved=not self.args.no_resolve_includes),
                    indent=4))
            return 0

        elif self.args.json:
            print(
                json.dumps(
                    t.to_object(resolved=not self.args.no_resolve_includes),
                    indent=4,
                    sort_keys=True))
            return 0

        # pretty general information
        print('Name: {0} ({1})'.format(t.name, t.user))

        if t.description is not None and len(t.description):
            print('Description:\n{0}\n'.format(t.description))

        # pretty print includes
        if len(t.includes):
            print('Includes:')
            for i in t.includes:
                print(' - {0}'.format(i))
            print()

        # pretty print packages
        repos = list(t.repos_all)
        repos.sort(key=lambda x: x.stub)

        if len(repos):
            l = prettytable.PrettyTable(
                ['repo', 'name', 'priority', 'cost', 'enabled'])
            l.min_table_width = 120
            l.hrules = prettytable.HEADER
            l.vrules = prettytable.NONE
            l.align = 'l'
            l.padding_witdth = 1

            for r in repos:
                if r.cost is None:
                    r.cost = '-'

                if r.priority is None:
                    r.priority = '-'

                if r.enabled:
                    r.enabled = 'Y'

                else:
                    r.enabled = 'N'

                l.add_row([r.stub, r.name, r.priority, r.cost, r.enabled])

            print(l)
            print()

        # pretty print packages
        packages = list(t.packages_all)
        packages.sort(key=lambda x: x.name)

        if len(packages):
            l = prettytable.PrettyTable(
                ['package', 'epoch', 'version', 'release', 'arch', 'action'])
            l.min_table_width = 120
            l.hrules = prettytable.HEADER
            l.vrules = prettytable.NONE
            l.align = 'l'
            l.padding_witdth = 1

            for p in packages:
                if p.epoch is None:
                    p.epoch = '-'

                if p.version is None:
                    p.version = '-'

                if p.release is None:
                    p.release = '-'

                if p.arch is None:
                    p.arch = '-'

                if p.included:
                    p.action = '+'

                else:
                    p.action = '-'

                l.add_row(
                    [p.name, p.epoch, p.version, p.release, p.arch, p.action])

            print(l)
            print()

        return 0
Exemplo n.º 3
0
    def run_dump(self):
        t = Template(self.args.template, user=self.args.username)

        try:
            t = self.cs.template_get(t, resolve_includes=not self.args.no_resolve_includes)

        except ServiceException as e:
            logging.exception(e)
            return 1

        if self.args.kickstart:
            print(t.to_kickstart(resolved=not self.args.no_resolve_includes))
            return 0

        elif self.args.yaml:
            print(yaml.dump(t.to_object(resolved=not self.args.no_resolve_includes), indent=4))
            return 0

        elif self.args.json:
            print(json.dumps(t.to_object(resolved=not self.args.no_resolve_includes), indent=4, sort_keys=True))
            return 0

        # pretty general information
        print('TEMPLATE: {0} ({1})\n'.format(t.name, t.user))

        if t.description is not None and len(t.description):
            print('Description:\n{0}\n'.format(t.description))

        # pretty print includes
        if len(t.includes):
            l = TextTable(header=['INCLUDE'])
            for i in t.includes:
                l.add_row([i])

            print(l)
            print()

        # pretty print packages
        repos = list(t.repos_all)
        repos.sort(key=lambda x: x.stub)

        if len(repos):
            l = TextTable(header=["REPO", "NAME", "ENABLED"])

            for r in repos:
                cost = r.cost
                if cost is None:
                    cost = '-'

                priority = r.priority
                if priority is None:
                    priority = '-'

                enabled = 'N'
                if r.enabled:
                    enabled = 'Y'

                #l.add_row([r.stub, r.name, priority, cost, enabled])
                l.add_row([r.stub, r.name, enabled])

            print(l)
            print()

        # pretty print packages
        packages = list(t.packages_all)
        packages.sort(key=lambda x: x.name)

        if len(packages):
            l = TextTable(header=["PACKAGE", "ACTION"])

            for p in packages:
                if p.included:
                    p.action = '+'

                else:
                    p.action = '-'

                l.add_row([p.name, p.action])

            print(l)
            print()

        return 0
Exemplo n.º 4
0
    def run_dump(self):
        t = Template(self.args.template, user=self.args.username)

        try:
            t = self.cs.template_get(t)

        except ServiceException as e:
            print(e)
            return 1

        if self.args.kickstart:
            print(t.to_kickstart())
            return 0

        elif self.args.yaml:
            print(yaml.dump(t.to_object(), indent=4))
            return 0

        elif self.args.json:
            print(json.dumps(t.to_object(), indent=4))
            return 0

        # pretty general information
        print('Name: {0} ({1})'.format(t.name, t.user))

        if t.description is not None and len(t.description):
            print('Description:\n{0}\n'.format(t.description))

        # pretty print includes
        if len(t.includes):
            print('Includes:')
            for i in t.includes:
                print(' - {0}'.format(i))
            print()

        # pretty print packages
        repos = list(t.repos_all)
        repos.sort(key=lambda x: x.stub)

        if len(repos):
            l = prettytable.PrettyTable(['repo', 'name', 'priority', 'cost', 'enabled'])
            l.min_table_width = 120
            l.hrules = prettytable.HEADER
            l.vrules = prettytable.NONE
            l.align = 'l'
            l.padding_witdth = 1

            for r in repos:
                if r.cost is None:
                    r.cost = '-'

                if r.priority is None:
                    r.priority = '-'

                if r.enabled:
                    r.enabled = 'Y'

                else:
                    r.enabled = 'N'

                l.add_row([r.stub, r.name, r.priority, r.cost, r.enabled])

            print(l)
            print()

        # pretty print packages
        packages = list(t.packages_all)
        packages.sort(key=lambda x: x.name)

        if len(packages):
            l = prettytable.PrettyTable(['package', 'epoch', 'version', 'release', 'arch', 'action'])
            l.min_table_width = 120
            l.hrules = prettytable.HEADER
            l.vrules = prettytable.NONE
            l.align = 'l'
            l.padding_witdth = 1

            for p in packages:
                if p.epoch is None:
                    p.epoch = '-'

                if p.version is None:
                    p.version = '-'

                if p.release is None:
                    p.release = '-'

                if p.arch is None:
                    p.arch = '-'

                if p.included():
                    p.action = '+'

                else:
                    p.action = '-'

                l.add_row([p.name, p.epoch, p.version, p.release, p.arch, p.action])

            print(l)
            print()

        return 0