Example #1
0
    def exists(self, environment_id=None, environment_unique_hash=None):
        """Returns a boolean if the environment exists

        Parameters
        ----------
        environment_id : str
            environment id to check for
        environment_unique_hash : str
            unique hash for the environment to check for

        Returns
        -------
        bool
            True if exists else False
        """
        if environment_id:
            environment_objs = self.dal.environment.query(
                {"id": environment_id})
        elif environment_unique_hash:
            environment_objs = self.dal.environment.query(
                {"unique_hash": environment_unique_hash})
        else:
            raise ArgumentError()
        env_exists = False
        if environment_objs:
            env_exists = True
        return env_exists
Example #2
0
File: code.py Project: yyht/datmo
    def exists(self, code_id=None, code_commit_id=None):
        """Returns a boolean if the code exists

        Parameters
        ----------
        code_id : str
            code id to check for
        code_commit_id : str
            unique commit id for the code

        Returns
        -------
        bool
            True if exists else False
        """
        if not self.is_initialized:
            return False
        if code_id:
            code_objs = self.dal.code.query({"id": code_id})
        elif code_commit_id:
            code_objs = self.dal.code.query({"commit_id": code_commit_id})
        else:
            raise ArgumentError()
        if code_objs:
            return True
        return False
Example #3
0
 def prompt_validator(self,
                      msg,
                      validate_function,
                      tries=5,
                      error_message="Invalid input"):
     if not callable(validate_function):
         raise ArgumentError('validate_function argument must be function')
     val = input(msg).lower()
     if not validate_function(val) and tries >= 0:
         tries -= 1
         return self.prompt_validator(msg, validate_function, tries,
                                      error_message)
     if tries == 0:
         self.echo(error_message)
     return val