# ------------------------------------------------------------------------------------
# Class to get jenkins environment variables
# ------------------------------------------------------------------------------------

import os
from robot.api import logger


class Jenkins:
    JENKINS_WORKSPACE = "WORKSPACE"
    JENKINS_BUILD_NUMBER = "BUILD_NUMBER"
    JENKINS_JOB_NAME = "JOB_NAME"

    @staticmethod
    def is_running_from_jenkins():
        """Checks if jenkins env variables exist, returns True/False"""
        if Jenkins.JENKINS_JOB_NAME in os.environ and Jenkins.JENKINS_BUILD_NUMBER in os.environ:
            logger.info("Executing from Jenkins")
            return True
        else:
            logger.info("Not executing from Jenkins")
            return False

    @staticmethod
    def get_job_name():
        """Gets the jenkins job name"""
        value = os.getenv(Jenkins.JENKINS_JOB_NAME)
        logger.info("Jenkins job name: %s" % value)
        return value

    @staticmethod
    def get_build_number():
        """Gets the jenkins build number"""
        value = os.getenv(Jenkins.JENKINS_BUILD_NUMBER)
        logger.info("Jenkins build number: %s" % value)
        return value

    @staticmethod
    def get_workspace():
        """Gets the workspace path"""
        value = os.getenv(Jenkins.JENKINS_WORKSPACE)
        logger.info("Jenkins workspace: %s" % value)
        return value
