Exemplo n.º 1
0
    def run_add(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

        for p in self.args.package:
            try:
                pkg = Package(p)
            except TypeError as e:
                print(e)
                return 1

            t.add_package(pkg)

        packages = list(t.packages_delta)
        packages.sort(key=lambda x: x.name)

        # describe process for dry runs
        if self.args.dry_run:
            if len(packages):
                print(
                    'The following would be added to the template: {0}'.format(
                        t.name))

                for p in packages:
                    print('  - ' + str(p))

                print()
                print('Summary:')
                print('  - Package(s): %d' % (len(packages)))
                print()

            else:
                print('No template changes required.')

            print('No action peformed during this dry-run.')
            return 0

        if not len(packages):
            print('info: no changes detected, template up to date.')
            return 0

        # push our updated template
        try:
            res = self.cs.template_update(t)

        except ServiceException as e:
            print(e)
            return 1
Exemplo n.º 2
0
    def run_add(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

        for p in self.args.package:
            try:
                pkg = Package(p)
            except TypeError as e:
                print(e)
                return 1

            t.add_package(pkg)

        packages = list(t.packages_delta)
        packages.sort(key=lambda x: x.name)

        # describe process for dry runs
        if self.args.dry_run:
            if len(packages):
                print("The following would be added to the template: {0}".format(t.name))

                for p in packages:
                    print("  - " + str(p))

                print()
                print("Summary:")
                print("  - Package(s): %d" % (len(packages)))
                print()

            else:
                print("No template changes required.")

            print("No action peformed during this dry-run.")
            return 0

        if not len(packages):
            print("info: no changes detected, template up to date.")
            return 0

        # push our updated template
        try:
            res = self.cs.template_update(t)

        except ServiceException as e:
            print(e)
            return 1
Exemplo n.º 3
0
    def test_template_add_includes_obj(self):
        t1 = Template("foo:bar")
        t2 = Template("bar:baz")
        t3 = Template("baz:daz")

        p1 = Package("foo")
        p2 = Package("bar")
        p3 = Package("baz")
        p4 = Package("~baz")

        t1.add_package(p1)

        t2.add_package(p2)
        t2.add_package(p3)

        t3.add_package(p4)

        # check includes
        t1.includes = [t2]
        self.assertEqual(["bar:baz"], t1.includes)

        # check includes (rebuild)
        t1.includes = [t2, t3]
        self.assertEqual(["bar:baz", "baz:daz"], t1.includes)

        # check package resolution
        t1.includes = [t2]
        self.assertEqual(PackageSet([p1, p2, p3]), t1.packages_all)

        # check package resolution (ordered)
        t1.includes = [t2, t3]
        self.assertEqual(PackageSet([p1, p2, p3]), t1.packages_all)

        t1.includes = [t3, t2]
        self.assertEqual(PackageSet([p1, p2, p4]), t1.packages_all)
Exemplo n.º 4
0
    def test_template_add_includes_obj(self):
        t1 = Template("foo:bar")
        t2 = Template("bar:baz")
        t3 = Template("baz:daz")

        p1 = Package("foo")
        p2 = Package("bar")
        p3 = Package("baz")
        p4 = Package("~baz")

        t1.add_package(p1)

        t2.add_package(p2)
        t2.add_package(p3)

        t3.add_package(p4)

        # check includes
        t1.includes = [t2]
        self.assertEqual(["bar:baz"], t1.includes)

        # check includes (rebuild)
        t1.includes = [t2, t3]
        self.assertEqual(["bar:baz", "baz:daz"], t1.includes)

        # check package resolution
        t1.includes = [t2]
        self.assertEqual(PackageSet([p1, p2, p3]), t1.packages_all)

        # check package resolution (ordered)
        t1.includes = [t2, t3]
        self.assertEqual(PackageSet([p1, p2, p3]), t1.packages_all)

        t1.includes = [t3, t2]
        self.assertEqual(PackageSet([p1, p2, p4]), t1.packages_all)
Exemplo n.º 5
0
    def run_push(self):
        t = Template(self.args.template, user=self.args.username)

        # grab the template we're pushing to
        try:
            t = self.cs.template_get(t)

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

        if self.args.push_clean:
            t.clear()

        if self.args.kickstart is not None:
            logging.info('Parsing kickstart ...')
            t.from_kickstart(self.args.kickstart)

        else:
            # prepare dnf
            logging.info('Analysing system ...')
            db = dnf.Base()
            db.read_all_repos()
            db.read_comps()

            try:
                db.fill_sack()

            except OSError as e:
                pass

            db_list = db.iter_userinstalled()

            if self.args.push_all:
                db_list = db.sack.query().installed()

            # add our user installed packages
            for p in db_list:
                # no need to store versions
                t.add_package(Package(p, evr=False))

            # add only enabled repos
            for r in db.repos.enabled():
                t.add_repo(Repository(r))

        objects = list(t.objects_delta)
        objects.sort(key=lambda x: x.name)

        packages = list(t.packages_delta)
        packages.sort(key=lambda x: x.name)

        repos = list(t.repos_delta)
        repos.sort(key=lambda x: x.name)

        # describe process for dry runs
        if self.args.dry_run:
            if len(packages) or len(repos):
                print(
                    'The following would be added to the template: {0}'.format(
                        t.name))

                for r in repos:
                    print('  - ' + str(r))

                for p in packages:
                    print('  - ' + str(p))

                for o in objects:
                    print('  - ' + str(o))

                print()
                print('Summary:')
                print('  - Repo(s): %d' % (len(repos)))
                print('  - Package(s): %d' % (len(packages)))
                print('  - Object(s): %d' % (len(objects)))
                print()

            else:
                print('No template changes required.')

            logging.info('No action peformed during this dry-run.')
            return 0

        if self.args.kickstart is None and not len(packages) and not len(
                repos):
            logging.info('No changes detected, template up to date.')
            return 0

        # push our updated template
        try:
            res = self.cs.template_update(t)

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

        logging.info('Template pushed.')
        return 0
Exemplo n.º 6
0
    def run_push(self):
        t = Template(self.args.template, user=self.args.username)

        # grab the template we're pushing to
        try:
            t = self.cs.template_get(t)

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

        if self.args.push_clean:
            t.clear()

        if self.args.kickstart is not None:
            logging.info('Parsing kickstart ...')
            t.from_kickstart(self.args.kickstart)

        else:
            # prepare dnf
            logging.info('Analysing system ...')
            db = dnf.Base()
            db.read_all_repos()
            db.read_comps()

            try:
                db.fill_sack()

            except OSError as e:
                pass

            db_list = db.iter_userinstalled()

            if self.args.push_all:
                db_list = db.sack.query().installed()

            # add our user installed packages
            for p in db_list:
                # no need to store versions
                t.add_package(Package(p, evr=False))

            # add only enabled repos
            for r in db.repos.enabled():
                t.add_repo(Repository(r))

        objects = list(t.objects_delta)
        objects.sort(key=lambda x: x.name)

        packages = list(t.packages_delta)
        packages.sort(key=lambda x: x.name)

        repos = list(t.repos_delta)
        repos.sort(key=lambda x: x.name)

        # describe process for dry runs
        if self.args.dry_run:
            if len(packages) or len(repos):
                print('The following would be added to the template: {0}'.format(t.name))

                for r in repos:
                    print('  - ' + str(r))

                for p in packages:
                    print('  - ' + str(p))

                for o in objects:
                    print('  - ' + str(o))

                print()
                print('Summary:')
                print('  - Repo(s): %d' % (len(repos)))
                print('  - Package(s): %d' % (len(packages)))
                print('  - Object(s): %d' % (len(objects)))
                print()

            else:
                print('No template changes required.')

            logging.info('No action peformed during this dry-run.')
            return 0

        if self.args.kickstart is None and not len(packages) and not len(repos):
            logging.info('No changes detected, template up to date.')
            return 0

        # push our updated template
        try:
            res = self.cs.template_update(t)

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

        logging.info('Template pushed.')
        return 0