Пример #1
0
class ParameterManager(TortugaObjectManager, Singleton):
    def __init__(self):
        super(ParameterManager, self).__init__()

        self._globalParameterDbApi = GlobalParameterDbApi()

    def getParameter(self, name):
        """
        Raises:
            ParameterNotFound
        """

        return self._globalParameterDbApi.getParameter(name)

    def getBoolParameter(self, name, default=None):
        """
        Raises:
            ParameterNotFound
            TortugaException
        """

        try:
            param = self.getParameter(name)
        except ParameterNotFound:
            if default is not None:
                return default

            raise

        return param.getValue() and \
            param.getValue()[0].lower() in ('1', 'y', 't')

    def getIntParameter(self, name, default=None):
        """
        Raises:
            ParameterNotFound
            TortugaException
        """

        try:
            param = self.getParameter(name)
        except ParameterNotFound:
            if default is not None:
                return default

            raise

        return int(param.getValue())

    def getParameterList(self):
        return self._globalParameterDbApi.getParameterList()

    def upsertParameter(self, parameter):
        return self._globalParameterDbApi.upsertParameter(parameter)

    def deleteParameter(self, name):
        return self._globalParameterDbApi.deleteParameter(name)
Пример #2
0
class ParameterManager(TortugaObjectManager):
    def __init__(self):
        super(ParameterManager, self).__init__()

        self._globalParameterDbApi = GlobalParameterDbApi()

    def getParameter(self, session: Session, name: str) -> Parameter:
        """
        Raises:
            ParameterNotFound
        """

        return self._globalParameterDbApi.getParameter(session, name)

    def getBoolParameter(self,
                         session: Session,
                         name: str,
                         default: Optional[bool] = None) -> bool:
        """
        Raises:
            ParameterNotFound
            TortugaException
        """

        try:
            param = self.getParameter(session, name)
        except ParameterNotFound:
            if default is not None:
                return default

            raise

        return param.getValue() and \
            param.getValue()[0].lower() in ('1', 'y', 't')

    def getIntParameter(self,
                        session: Session,
                        name: str,
                        default: Optional[int] = None) -> int:
        """
        Raises:
            ParameterNotFound
            TortugaException
        """

        try:
            param = self.getParameter(name)
        except ParameterNotFound:
            if default is not None:
                return default

            raise

        return int(param.getValue())

    def getParameterList(self, session: Session) -> TortugaObjectList:
        return self._globalParameterDbApi.getParameterList(session)

    def upsertParameter(self, session: Session, parameter: Parameter) -> None:
        self._globalParameterDbApi.upsertParameter(session, parameter)

    def deleteParameter(self, session: Session, name: str) -> None:
        self._globalParameterDbApi.deleteParameter(session, name)