# Path: kano/utils/shell.py
# def run_cmd(cmd, localised=False, unsudo=False):
#     '''
#     Executes cmd, returning stdout, stderr, return code
#     if localised is False, LC_ALL will be set to "C"
#     '''
#     env = os.environ.copy()
#     if not localised:
#         env['LC_ALL'] = 'C'
# 
#     if unsudo and \
#             'SUDO_USER' in os.environ and \
#             os.environ['SUDO_USER'] != 'root':
#         cmd = "sudo -u {} bash -c '{}' ".format(os.environ['SUDO_USER'], cmd)
# 
#     process = subprocess.Popen(cmd, shell=True, env=env,
#                                stdout=subprocess.PIPE, stderr=subprocess.PIPE,
#                                preexec_fn=restore_signals)
# 
#     stdout, stderr = process.communicate()
#     returncode = process.returncode
#     return stdout, stderr, returncode
# 
# def run_bg(cmd, localised=False, unsudo=False):
#     '''
#     Starts cmd program in the background
#     '''
#     env = os.environ.copy()
#     if not localised:
#         env['LC_ALL'] = 'C'
# 
#     if unsudo and \
#             'SUDO_USER' in os.environ and \
#             os.environ['SUDO_USER'] != 'root':
#         cmd = "sudo -u {} bash -c '{}' ".format(os.environ['SUDO_USER'], cmd)
# 
#     s = subprocess.Popen(cmd, shell=True, env=env)
#     return s
# 
# def run_cmd_log(cmd, localised=False, unsudo=False):
#     '''
#     Wrapper against run_cmd but Kano Logging executuion and return code
#     '''
# 
#     from kano.logging import logger
# 
#     out, err, rv = run_cmd(cmd, localised, unsudo)
#     logger.info("Command: {}".format(cmd))
# 
#     if len(out.strip()) > 0:
#         logger.info(out)
# 
#     if len(err.strip()) > 0:
#         logger.error(err)
# 
#     logger.info("Return value: {}".format(rv))
# 
#     return out, err, rv


import os
from kano.utils.shell import run_cmd, run_bg, run_cmd_log
    from kano.logging import logger
            from kano_settings.system.audio import is_HDMI
        from math import log10
    from kano.logging import logger
            pass

        cmd = 'omxplayer -o {audio_out} {volume} {link}'.format(
            audio_out=audio_out,
            volume=volume_str,
            link=audio_file
        )

    logger.debug('cmd: {}'.format(cmd))

    # Delay the sound playback if specified
    if delay:
        cmd = '/bin/sleep {} ; {}'.format(delay, cmd)

    if background:
        run_bg(cmd)
        rc = 0
    else:
        dummy, dummy, rc = run_cmd_log(cmd)

    return rc == 0


def percent_to_millibel(percent, raspberry_mod=False):
    if not raspberry_mod:

        multiplier = 2.5

        percent *= multiplier
        percent = min(percent, 100. * multiplier)

# Path: kano/utils/shell.py
# def run_cmd(cmd, localised=False, unsudo=False):
#     '''
#     Executes cmd, returning stdout, stderr, return code
#     if localised is False, LC_ALL will be set to "C"
#     '''
#     env = os.environ.copy()
#     if not localised:
#         env['LC_ALL'] = 'C'
# 
#     if unsudo and \
#             'SUDO_USER' in os.environ and \
#             os.environ['SUDO_USER'] != 'root':
#         cmd = "sudo -u {} bash -c '{}' ".format(os.environ['SUDO_USER'], cmd)
# 
#     process = subprocess.Popen(cmd, shell=True, env=env,
#                                stdout=subprocess.PIPE, stderr=subprocess.PIPE,
#                                preexec_fn=restore_signals)
# 
#     stdout, stderr = process.communicate()
#     returncode = process.returncode
#     return stdout, stderr, returncode
# 
# def run_bg(cmd, localised=False, unsudo=False):
#     '''
#     Starts cmd program in the background
#     '''
#     env = os.environ.copy()
#     if not localised:
#         env['LC_ALL'] = 'C'
# 
#     if unsudo and \
#             'SUDO_USER' in os.environ and \
#             os.environ['SUDO_USER'] != 'root':
#         cmd = "sudo -u {} bash -c '{}' ".format(os.environ['SUDO_USER'], cmd)
# 
#     s = subprocess.Popen(cmd, shell=True, env=env)
#     return s
# 
# def run_cmd_log(cmd, localised=False, unsudo=False):
#     '''
#     Wrapper against run_cmd but Kano Logging executuion and return code
#     '''
# 
#     from kano.logging import logger
# 
#     out, err, rv = run_cmd(cmd, localised, unsudo)
#     logger.info("Command: {}".format(cmd))
# 
#     if len(out.strip()) > 0:
#         logger.info(out)
# 
#     if len(err.strip()) > 0:
#         logger.error(err)
# 
#     logger.info("Return value: {}".format(rv))
# 
#     return out, err, rv


# Path: kano/utils/audio.py
import os
from kano.utils.shell import run_cmd, run_bg, run_cmd_log
    from kano.logging import logger
            from kano_settings.system.audio import is_HDMI
        from math import log10
    from kano.logging import logger

            pass

        cmd = 'omxplayer -o {audio_out} {volume} {link}'.format(
            audio_out=audio_out,
            volume=volume_str,
            link=audio_file
        )

    logger.debug('cmd: {}'.format(cmd))

    # Delay the sound playback if specified
    if delay:
        cmd = '/bin/sleep {} ; {}'.format(delay, cmd)

    if background:
        run_bg(cmd)
        rc = 0
    else:
        dummy, dummy, rc = run_cmd_log(cmd)

    return rc == 0


def percent_to_millibel(percent, raspberry_mod=False):
    if not raspberry_mod:

        multiplier = 2.5

        percent *= multiplier
        percent = min(percent, 100. * multiplier)

        percent = max(percent, 0.000001)