# Path: simple_monitor_alert/utils/files.py
# def makedirs(path, mode=0o777, exist_ok=False):
#     if not exist_ok or (exist_ok and not os.path.exists(path)):
#         os.makedirs(path, mode)


import distutils
import filecmp
import getpass
import shutil
import subprocess
import pwd
import grp
import pip
import os
import sys
import uuid
from distutils.version import LooseVersion
from setuptools import setup, find_packages, Command
from distutils.util import convert_path
from fnmatch import fnmatchcase
from simple_monitor_alert.utils.files import makedirs
    from pip.req import parse_requirements
from setuptools.command.install import install
        print('-' * 80)
        if getpass.getuser() != 'root':
            print('WARNING: Simple-Monitor-Alert installed as "{}". Install as root to create the system files!')
            return
        print('Installing things that are not Python (system files).')
        for directory in [ENABLED_MONITORS_DIR, os.path.dirname(AVAILABLE_MONITORS_DIR)]:
            print('Creating directory {}'.format(directory))
            makedirs(directory, exist_ok=True)
        dir_path = os.path.dirname(os.path.realpath(__file__))
        for src_name, dest in [('monitors', MONITORS_DIR), ('alerts', ALERTS_DIR)]:
            print('Copying directory "{}" to "{}"'.format(os.path.join(dir_path, src_name), dest))
            distutils.dir_util.copy_tree(os.path.join(dir_path, src_name), dest)
        for from_, to in [(MONITORS_DIR, AVAILABLE_MONITORS_DIR), (ALERTS_DIR, AVAILABLE_ALERTS_DIR)]:
            if not os.path.exists(to):
                print('Creating symbolic link "{}" -> "{}"'.format(from_, to))
                os.symlink(from_, to)
        if not os.listdir(ENABLED_MONITORS_DIR):
            print('Enabling defaults monitors: {}'.format(', '.join(DEFAULT_ENABLEDS_MONITORS)))
            for enabled_monitor in DEFAULT_ENABLEDS_MONITORS:
                os.symlink('../{}/{}'.format(os.path.split(AVAILABLE_MONITORS_DIR)[1], enabled_monitor),
                           os.path.join(ENABLED_MONITORS_DIR, enabled_monitor))
        print('Creating user {}'.format(USERNAME))
        p = subprocess.Popen(['useradd', USERNAME])
        if sys.version_info >= (3,3):
            p.wait(2)
        else:
            p.wait()
        if p.returncode not in [0, 9]:
            raise Exception('It has failed to create the user {}. Returncode: {}'.format(USERNAME, p.returncode))
        print('Creating variable data directory: {}'.format(VAR_DIRECTORY))

# Path: simple_monitor_alert/utils/files.py
# def makedirs(path, mode=0o777, exist_ok=False):
#     if not exist_ok or (exist_ok and not os.path.exists(path)):
#         os.makedirs(path, mode)


# Path: setup.py
import distutils
import filecmp
import getpass
import shutil
import subprocess
import pwd
import grp
import pip
import os
import sys
import uuid
from distutils.version import LooseVersion
from setuptools import setup, find_packages, Command
from distutils.util import convert_path
from fnmatch import fnmatchcase
from simple_monitor_alert.utils.files import makedirs
    from pip.req import parse_requirements
from setuptools.command.install import install

        print('-' * 80)
        if getpass.getuser() != 'root':
            print('WARNING: Simple-Monitor-Alert installed as "{}". Install as root to create the system files!')
            return
        print('Installing things that are not Python (system files).')
        for directory in [ENABLED_MONITORS_DIR, os.path.dirname(AVAILABLE_MONITORS_DIR)]:
            print('Creating directory {}'.format(directory))
            makedirs(directory, exist_ok=True)
        dir_path = os.path.dirname(os.path.realpath(__file__))
        for src_name, dest in [('monitors', MONITORS_DIR), ('alerts', ALERTS_DIR)]:
            print('Copying directory "{}" to "{}"'.format(os.path.join(dir_path, src_name), dest))
            distutils.dir_util.copy_tree(os.path.join(dir_path, src_name), dest)
        for from_, to in [(MONITORS_DIR, AVAILABLE_MONITORS_DIR), (ALERTS_DIR, AVAILABLE_ALERTS_DIR)]:
            if not os.path.exists(to):
                print('Creating symbolic link "{}" -> "{}"'.format(from_, to))
                os.symlink(from_, to)
        if not os.listdir(ENABLED_MONITORS_DIR):
            print('Enabling defaults monitors: {}'.format(', '.join(DEFAULT_ENABLEDS_MONITORS)))
            for enabled_monitor in DEFAULT_ENABLEDS_MONITORS:
                os.symlink('../{}/{}'.format(os.path.split(AVAILABLE_MONITORS_DIR)[1], enabled_monitor),
                           os.path.join(ENABLED_MONITORS_DIR, enabled_monitor))
        print('Creating user {}'.format(USERNAME))
        p = subprocess.Popen(['useradd', USERNAME])
        if sys.version_info >= (3,3):
            p.wait(2)
        else:
            p.wait()
        if p.returncode not in [0, 9]:
            raise Exception('It has failed to create the user {}. Returncode: {}'.format(USERNAME, p.returncode))
        print('Creating variable data directory: {}'.format(VAR_DIRECTORY))

        makedirs(VAR_DIRECTORY, 0o700, True)