# Path: lib/Settings.py
# class Settings:
#     def __init__(self,
#                  override_settings_path='settings.cfg'):
#         self.settingsFilePath = override_settings_path
#         self.parser = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation())
#         self.settings = None
#         self.getSettings()
# 
#     def getSettings(self):
#         self.parser.read('./settings.cfg')
#         self.settings = {section: dict(**self.parser[section]) for section in self.parser.sections()}
# 
#         return self.settings
# 
#     def getServiceIp(self, service):
#         return self.settings['general']['my_ip']
# 
# Path: lib/Tools/paths.py

# 
# Path: lib/Wrappers/Logger.py
# class Logger:
#     def __init__(self, name):
#         if 'UNITTESTING' in os.environ:
#             self.logging = NullLogger()
#         else:
#             settings = Settings().getSettings()
#             logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
#                                 level=settings["logs"]["level"])
#             self.logging = logging.getLogger(name)
# 
#     def debug(self, *args, **kwargs):
#         self.logging.debug(*args, **kwargs)
# 
#     def info(self, *args, **kwargs):
#         self.logging.info(*args, **kwargs)
# 
#     def warning(self, *args, **kwargs):
#         self.logging.warning(*args, **kwargs)
# 
#     def error(self, *args, **kwargs):
#         self.logging.error(*args, **kwargs)
# 
#     def critical(self, *args, **kwargs):
#         self.logging.critical(*args, **kwargs)
# 
#     def log(self, *args, **kwargs):
#         self.logging.log(*args, **kwargs)


import os
import shutil
import subprocess
from lib.Settings import Settings
from lib.Tools import paths
from lib.Wrappers.Logger import Logger
        self._clean_files(paths.data + "/elasticsearch")
        self.logger.info("Cleaning MySql.")
        self._clean_files(paths.data + "/mysql")
        self.logger.info("Cleaning Seafile Sync Files.")
        self._clean_files(paths.data + "/seafilesync")
        self.logger.info("Cleaning Seafile Raw Data.")
        self._clean_files(paths.data + "/seafileRawData")
        self.logger.debug("Cleaning PIM Raw Data.")
        self._clean_files(paths.data + "/pim")

    def _clean_files(self, path):
        if os.path.isdir(path):
            shutil.rmtree(path)
            if not os.path.exists(path):
                os.makedirs(path)

    def create_skel(self, username, domain):
        self.logger.debug("Creating folders for " + username)
        list_of_dirs = ["config", "files", "local", "mailbox", "networkdrives", "workgroups"]
        if self.settings['general']['multitenant'] == "true":
            base_path = paths.raw_fs + "/users/" + domain + "/" + username + "/"
        else:
            base_path = paths.raw_fs + "/users/" + username + "/"
        mode = 0o755
        for directory in list_of_dirs:
            os.makedirs(base_path + directory, mode, exist_ok=True)
            self.logger.debug("Created " + base_path + directory)
        os.system("chmod 777 " + base_path + "mailbox")
        os.chown(base_path + "mailbox",
                 int(self.settings['email']['mailbox_owner_uid']),

# Path: lib/Settings.py
# class Settings:
#     def __init__(self,
#                  override_settings_path='settings.cfg'):
#         self.settingsFilePath = override_settings_path
#         self.parser = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation())
#         self.settings = None
#         self.getSettings()
# 
#     def getSettings(self):
#         self.parser.read('./settings.cfg')
#         self.settings = {section: dict(**self.parser[section]) for section in self.parser.sections()}
# 
#         return self.settings
# 
#     def getServiceIp(self, service):
#         return self.settings['general']['my_ip']
# 
# Path: lib/Tools/paths.py

# 
# Path: lib/Wrappers/Logger.py
# class Logger:
#     def __init__(self, name):
#         if 'UNITTESTING' in os.environ:
#             self.logging = NullLogger()
#         else:
#             settings = Settings().getSettings()
#             logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
#                                 level=settings["logs"]["level"])
#             self.logging = logging.getLogger(name)
# 
#     def debug(self, *args, **kwargs):
#         self.logging.debug(*args, **kwargs)
# 
#     def info(self, *args, **kwargs):
#         self.logging.info(*args, **kwargs)
# 
#     def warning(self, *args, **kwargs):
#         self.logging.warning(*args, **kwargs)
# 
#     def error(self, *args, **kwargs):
#         self.logging.error(*args, **kwargs)
# 
#     def critical(self, *args, **kwargs):
#         self.logging.critical(*args, **kwargs)
# 
#     def log(self, *args, **kwargs):
#         self.logging.log(*args, **kwargs)


# Path: lib/FS/FileSystem.py
import os
import shutil
import subprocess
from lib.Settings import Settings
from lib.Tools import paths
from lib.Wrappers.Logger import Logger

        self._clean_files(paths.data + "/elasticsearch")
        self.logger.info("Cleaning MySql.")
        self._clean_files(paths.data + "/mysql")
        self.logger.info("Cleaning Seafile Sync Files.")
        self._clean_files(paths.data + "/seafilesync")
        self.logger.info("Cleaning Seafile Raw Data.")
        self._clean_files(paths.data + "/seafileRawData")
        self.logger.debug("Cleaning PIM Raw Data.")
        self._clean_files(paths.data + "/pim")

    def _clean_files(self, path):
        if os.path.isdir(path):
            shutil.rmtree(path)
            if not os.path.exists(path):
                os.makedirs(path)

    def create_skel(self, username, domain):
        self.logger.debug("Creating folders for " + username)
        list_of_dirs = ["config", "files", "local", "mailbox", "networkdrives", "workgroups"]
        if self.settings['general']['multitenant'] == "true":
            base_path = paths.raw_fs + "/users/" + domain + "/" + username + "/"
        else:
            base_path = paths.raw_fs + "/users/" + username + "/"
        mode = 0o755
        for directory in list_of_dirs:
            os.makedirs(base_path + directory, mode, exist_ok=True)
            self.logger.debug("Created " + base_path + directory)
        os.system("chmod 777 " + base_path + "mailbox")
        os.chown(base_path + "mailbox",
                 int(self.settings['email']['mailbox_owner_uid']),

                 int(self.settings['email']['mailbox_owner_gid']))