# Path: kano/utils/user.py
# def get_user_unsudoed():
#     if 'SUDO_USER' in os.environ:
#         return os.environ['SUDO_USER']
#     elif 'LOGNAME' in os.environ:
#         return os.environ['LOGNAME']
#     else:
#         return 'root'
# 
# 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


import os
import re
import pwd
import getpass
import grp
import shutil
import json
import fcntl
import errno
import stat
import time
import tempfile
from kano.utils.user import get_user_unsudoed
from kano.utils.shell import run_cmd
        from kano.logging import logger
        from kano.logging import logger
        from kano.logging import logger
        from kano.logging import logger
        from kano.logging import logger
        from kano.logging import logger
        from kano.logging import logger
        from kano.logging import logger
        from kano.logging import logger
        from kano.logging import logger
            for dir_n in dirs:
                new_dir = os.path.join(dest_root, dir_n)
                os.mkdir(new_dir)
            # Now deal with the files
            for file_n in files:
                src_file = os.path.join(root_d, file_n)
                new_file = os.path.join(dest_root, file_n)
                shutil.copy(src_file, new_file)
    except (IOError, OSError) as exc_err:
        logger.warn(
            "Can't copy '{}' contents into '{}', due to permission/IO - {}"
            .format(src_dir, dest_dir, exc_err)
        )
        return False
    return True


def ensure_dir(directory):
    if not os.path.exists(directory):
        os.makedirs(directory)


def list_dir(dir_path):
    if os.path.exists(dir_path):
        return os.listdir(dir_path)

    return list()


def chown_path(path, user=None, group=None):

# Path: kano/utils/user.py
# def get_user_unsudoed():
#     if 'SUDO_USER' in os.environ:
#         return os.environ['SUDO_USER']
#     elif 'LOGNAME' in os.environ:
#         return os.environ['LOGNAME']
#     else:
#         return 'root'
# 
# 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/file_operations.py
import os
import re
import pwd
import getpass
import grp
import shutil
import json
import fcntl
import errno
import stat
import time
import tempfile
from kano.utils.user import get_user_unsudoed
from kano.utils.shell import run_cmd
        from kano.logging import logger
        from kano.logging import logger
        from kano.logging import logger
        from kano.logging import logger
        from kano.logging import logger
        from kano.logging import logger
        from kano.logging import logger
        from kano.logging import logger
        from kano.logging import logger
        from kano.logging import logger

            for dir_n in dirs:
                new_dir = os.path.join(dest_root, dir_n)
                os.mkdir(new_dir)
            # Now deal with the files
            for file_n in files:
                src_file = os.path.join(root_d, file_n)
                new_file = os.path.join(dest_root, file_n)
                shutil.copy(src_file, new_file)
    except (IOError, OSError) as exc_err:
        logger.warn(
            "Can't copy '{}' contents into '{}', due to permission/IO - {}"
            .format(src_dir, dest_dir, exc_err)
        )
        return False
    return True


def ensure_dir(directory):
    if not os.path.exists(directory):
        os.makedirs(directory)


def list_dir(dir_path):
    if os.path.exists(dir_path):
        return os.listdir(dir_path)

    return list()


def chown_path(path, user=None, group=None):

    user_unsudoed = get_user_unsudoed()