# Path: kiwixbuild/utils.py
# COLORS = {
#     'OK': '\033[92m',
#     'WARNING': '\033[93m',
#     'NEEDED': '\033[93m',
#     'SKIP': '\033[34m',
#     'ERROR': '\033[91m',
#     '': '\033[0m',
# }
# REMOTE_PREFIX = 'http://mirror.download.kiwix.org/dev/'
# def which(name):
# def xrun_find(name):
#     def __getattr__(self, name):
# def DefaultEnv():
# def remove_duplicates(iterable, key_function=None):
# def get_sha256(path):
# def colorize(text, color=None):
# def print_progress(progress):
# def add_execution_right(file_path):
# def copy_tree(src, dst, post_copy_function=None):
# def download_remote(what, where):
#     def __init__(self, msg=""):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def __new__(cls, name, sha256, url=None):
#     def __init__(self, command_name, log_file, force_native_build):
#     def try_skip(self, path, extra_name=""):
#     def _finalise(self):
# def extract_archive(archive_path, dest_dir, topdir=None, name=None):
# def run_command(command, cwd, context, *, env=None, input=None):
# class Defaultdict(defaultdict):
# class BaseCommandResult(Exception):
# class SkipCommand(BaseCommandResult):
# class WarningMessage(BaseCommandResult):
# class StopBuild(BaseCommandResult):
# class Remotefile(namedtuple('Remotefile', ('name', 'sha256', 'url'))):
# class Context:
# 
# Path: kiwixbuild/_global.py
# def neutralEnv(what):
#     return getattr(_neutralEnv, what)
# 
# def option(what):
#     return getattr(_options, what)


import os, sys, shutil
import subprocess
import platform
import distro
from .utils import pj, download_remote, Defaultdict
from ._global import neutralEnv, option
                  self.log_dir):
            os.makedirs(d, exist_ok=True)
        self.detect_platform()
        self.ninja_command = self._detect_ninja()
        if not self.ninja_command:
            sys.exit("ERROR: ninja command not found.")
        self.meson_command = self._detect_meson()
        if not self.meson_command:
            sys.exit("ERROR: meson command not found.")
        self.qmake_command = self._detect_qmake()
        if not self.qmake_command:
            print("WARNING: qmake command not found.", file=sys.stderr)
        self.mesontest_command = "{} test".format(self.meson_command)

    def detect_platform(self):
        _platform = platform.system()
        self.distname = _platform
        if _platform == 'Windows':
            print('ERROR: kiwix-build is not intented to run on Windows platform.\n'
                  'It should probably not work, but well, you still can have a try.')
            cont = input('Do you want to continue ? [y/N]')
            if cont.lower() != 'y':
                sys.exit(0)
        if _platform == 'Linux':
            self.distname = distro.id()
            if self.distname == 'ubuntu':
                self.distname = 'debian'

    def download(self, what, where=None):
        where = where or self.archive_dir

# Path: kiwixbuild/utils.py
# COLORS = {
#     'OK': '\033[92m',
#     'WARNING': '\033[93m',
#     'NEEDED': '\033[93m',
#     'SKIP': '\033[34m',
#     'ERROR': '\033[91m',
#     '': '\033[0m',
# }
# REMOTE_PREFIX = 'http://mirror.download.kiwix.org/dev/'
# def which(name):
# def xrun_find(name):
#     def __getattr__(self, name):
# def DefaultEnv():
# def remove_duplicates(iterable, key_function=None):
# def get_sha256(path):
# def colorize(text, color=None):
# def print_progress(progress):
# def add_execution_right(file_path):
# def copy_tree(src, dst, post_copy_function=None):
# def download_remote(what, where):
#     def __init__(self, msg=""):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def __new__(cls, name, sha256, url=None):
#     def __init__(self, command_name, log_file, force_native_build):
#     def try_skip(self, path, extra_name=""):
#     def _finalise(self):
# def extract_archive(archive_path, dest_dir, topdir=None, name=None):
# def run_command(command, cwd, context, *, env=None, input=None):
# class Defaultdict(defaultdict):
# class BaseCommandResult(Exception):
# class SkipCommand(BaseCommandResult):
# class WarningMessage(BaseCommandResult):
# class StopBuild(BaseCommandResult):
# class Remotefile(namedtuple('Remotefile', ('name', 'sha256', 'url'))):
# class Context:
# 
# Path: kiwixbuild/_global.py
# def neutralEnv(what):
#     return getattr(_neutralEnv, what)
# 
# def option(what):
#     return getattr(_options, what)


# Path: kiwixbuild/buildenv.py
import os, sys, shutil
import subprocess
import platform
import distro
from .utils import pj, download_remote, Defaultdict
from ._global import neutralEnv, option

                  self.log_dir):
            os.makedirs(d, exist_ok=True)
        self.detect_platform()
        self.ninja_command = self._detect_ninja()
        if not self.ninja_command:
            sys.exit("ERROR: ninja command not found.")
        self.meson_command = self._detect_meson()
        if not self.meson_command:
            sys.exit("ERROR: meson command not found.")
        self.qmake_command = self._detect_qmake()
        if not self.qmake_command:
            print("WARNING: qmake command not found.", file=sys.stderr)
        self.mesontest_command = "{} test".format(self.meson_command)

    def detect_platform(self):
        _platform = platform.system()
        self.distname = _platform
        if _platform == 'Windows':
            print('ERROR: kiwix-build is not intented to run on Windows platform.\n'
                  'It should probably not work, but well, you still can have a try.')
            cont = input('Do you want to continue ? [y/N]')
            if cont.lower() != 'y':
                sys.exit(0)
        if _platform == 'Linux':
            self.distname = distro.id()
            if self.distname == 'ubuntu':
                self.distname = 'debian'

    def download(self, what, where=None):
        where = where or self.archive_dir

        download_remote(what, where)