Exemplo n.º 1
0
    def _checkExistingKit(self, session: Session, kitname: str,
                          kitversion: str, kitarch: str):
        """
        Raises:
            KitAlreadyExists
        """

        try:
            kit = self._kit_db_api.getKit(session, kitname, kitversion)

            longname = format_kit_descriptor(kitname, kitversion, kitarch)

            # Attempt to get matching OS component
            for c in kit.getComponentList(session):
                if c.getName() != longname:
                    continue

                for cOs in c.getOsInfoList():
                    if cOs == OsInfo(kitname, kitversion, kitarch):
                        raise KitAlreadyExists(
                            "OS kit [%s] already installed" % longname)

            # Kit exists, but doesn't have a matching os component
        except KitNotFound:
            pass
Exemplo n.º 2
0
    def addKit(self, session, kit):
        """
        Insert kit into the db.

        Raises:
            KitAlreadyExists
        """

        try:
            self.getKit(session, kit.getName(), kit.getVersion(),
                        kit.getIteration())

            raise KitAlreadyExists('Kit [%s] already exists' % (kit))
        except KitNotFound:
            # OK.
            pass

        self.getLogger().debug('Installing kit [%s]' % (kit))

        dbKit = Kits(name=kit.getName(),
                     version=kit.getVersion(),
                     iteration=kit.getIteration(),
                     description=kit.getDescription(),
                     isOs=kit.getIsOs(),
                     isRemovable=kit.getIsRemovable())

        # Add components.
        for c in kit.getComponentList():
            self._addComponentToKit(session, c, dbKit)

        # Add the newly created kit to the db session
        session.add(dbKit)

        return dbKit
Exemplo n.º 3
0
    def _check_if_kit_exists(self, kit):
        """
        Check if a kit exists, if it does then raise an exception.

        :raisesKitAlreadyExists:

        """
        try:
            self._kit_db_api.getKit(kit.getName(), kit.getVersion(),
                                    kit.getIteration())
            raise KitAlreadyExists('Kit already exists: ({}, {}, {})'.format(
                kit.getName(), kit.getVersion(), kit.getIteration()))
        except KitNotFound:
            pass