Eitol
3/14/2017 - 4:22 PM

Return the system timezone in linux

Return the system timezone in linux

    @staticmethod
    def get_system_timezone() -> str:
        """
        Retorna el timezone del sistema
        :return: Ej: America/Caracas
        """
        str_timezone = subprocess.getoutput('ls /etc/ -l | grep localtime | awk \'{print $11}\'')
        assert str_timezone is not None and len(str_timezone) and \
               str_timezone.find('../usr/share/zoneinfo/') != -1, "TIMEZONE_GET_ERROR:"
        str_timezone = str_timezone.replace('../usr/share/zoneinfo/', '')
        assert len(str_timezone), "INVALID_SYSTEM_TIMEZONE"
        return str_timezone