# 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


from kano.utils.shell import run_cmd
            from kano.logging import logger
#
# Utilities relating to disk manangement




def get_free_space(path="/"):
    """
        Returns the amount of free space in certain location in MB

        :param path: The location to measure the free space at.
        :type path: str

        :return: Number of free megabytes.
        :rtype: int
    """

    out, dummy_err, dummy_rv = run_cmd("df {}".format(path))

    dummy_device, dummy_size, dummy_used, free, dummy_percent, dummy_mp = \
        out.split('\n')[1].split()

    return int(free) / 1024


def get_partition_info():
    device = '/dev/mmcblk0'

    try:
        cmd = 'lsblk -n -b {} -o SIZE'.format(device)

# 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


# Path: kano/utils/disk.py
from kano.utils.shell import run_cmd
            from kano.logging import logger

#
# Utilities relating to disk manangement




def get_free_space(path="/"):
    """
        Returns the amount of free space in certain location in MB

        :param path: The location to measure the free space at.
        :type path: str

        :return: Number of free megabytes.
        :rtype: int
    """

    out, dummy_err, dummy_rv = run_cmd("df {}".format(path))

    dummy_device, dummy_size, dummy_used, free, dummy_percent, dummy_mp = \
        out.split('\n')[1].split()

    return int(free) / 1024


def get_partition_info():
    device = '/dev/mmcblk0'

    try:
        cmd = 'lsblk -n -b {} -o SIZE'.format(device)

        stdout, dummy_stderr, returncode = run_cmd(cmd)