# Path: lib/tsconfiglint/TsconfigLinter.py
# @catch_CancelCommand
# def check_tsconfig(view):
#     """ Tests view for being a tsconfig.json.
#         Reads the tsconfig.json and checks for errors.
#         Show Errors using Regions.
#         Set a error map [<(a,b), msg>] into views settings. """
# 
#     if not _is_valid_and_enabled(view):
#         return
# 
#     Debug('tsconfig', 'tsconfig modified, check')
# 
#     linter = TsconfigLinter(view)
# 
#     return linter
# 
# Path: lib/utils/debug.py
# def Debug(classification, text):
#     if 'all' in print_classifications or classification in print_classifications:
#         print("ArcticTypescript: %s: %s" % (classification.ljust(8), text))
#     if classification not in possible_classifications:
#         print("ArcticTypescript: debug: got unknown debug message classification: %s. " \
#             "Consider adding this to possible_classifications" % classification)
#     sys.stdout.flush()
# 
# Path: lib/utils/pathutils.py
# def get_expandglob_path():
#     """ Return path to expandglob.js """
#     return os.path.join(package_path, 'bin', 'expandglob.js')
# 
# def default_node_path(node_path, project=None):
#     if node_path == 'none':
#         Debug('notify', 'The setting node_path is set to "none". That is depreciated. Remove the setting.')
#         node_path = None
# 
#     if node_path == "" or node_path is None:
#         if sys.platform == "linux":
#             return "nodejs"
#         elif sys.platform == "nt":
#             return "node"
#         elif sys.platform == "darwin":
#             return "/usr/local/bin/node"
#         else:
#             return "node"
#     else:
#         return expand_variables(node_path, project)
# 
# Path: lib/utils/osutils.py
# def get_kwargs(stderr=True):
#     if os.name == 'nt':
#         startupinfo = subprocess.STARTUPINFO()
#         startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
#         if stderr:
#             #errorlog = open(os.devnull, 'w')
#             return {'stderr':subprocess.DEVNULL, 'startupinfo': startupinfo}
#         return {'startupinfo': startupinfo}
#     else:
#         return {}
# 
# Path: lib/utils/disabling.py
# def set_tsglobexpansion_disabled():
#     """ Sets the disabled flag for tsglobexpansion """
#     if "*tsglob" not in plugin_disabled_for_folders:
#         plugin_disabled_for_folders.append("*tsglob")
# 
# def set_tsglobexpansion_enabled():
#     """ Clears the disabled flag for tsglobexpansion """
#     if "*tsglob" in plugin_disabled_for_folders:
#         plugin_disabled_for_folders.remove("*tsglob")
# 
# def is_tsglobexpansion_disabled():
#     """ Checks the disabled flag for tsglobexpansion """
#     return "*tsglob"  in plugin_disabled_for_folders


import os
import glob
import json
from subprocess import Popen, PIPE, TimeoutExpired
from .TsconfigLinter import check_tsconfig
from ..utils.debug import Debug
from ..utils.pathutils import get_expandglob_path, default_node_path
from ..utils.osutils import get_kwargs
from ..utils.disabling import set_tsglobexpansion_disabled, set_tsglobexpansion_enabled, is_tsglobexpansion_disabled
        node_path = default_node_path(node_path)

        expandglob_path = get_expandglob_path()
        cwd = os.path.abspath(project_dir)

        cmdline = [node_path, expandglob_path]

        kwargs = get_kwargs()

        try:
            # EXECUTE
            expand_glob_process = Popen(cmdline,
                                     stdin=PIPE, stdout=PIPE,
                                     cwd=cwd, **kwargs)
            # FETCH and terminate
            result_str, _err = expand_glob_process.communicate(timeout=10)

            # PARSE
            result = json.loads(str(result_str.decode('UTF-8')))

            # CHECK (only for error Display)
            if "error" in result and isinstance(result['error'], str):
                Debug('error', 'expandglob.js: %s' % result['error'])
            #elif "error" in result and "files" in result \
            #         and result['error'] == False:
            #    return result['files']

        except TimeoutExpired:
            expand_glob_process.kill()
            outs, errs = expand_glob_process.communicate()

# Path: lib/tsconfiglint/TsconfigLinter.py
# @catch_CancelCommand
# def check_tsconfig(view):
#     """ Tests view for being a tsconfig.json.
#         Reads the tsconfig.json and checks for errors.
#         Show Errors using Regions.
#         Set a error map [<(a,b), msg>] into views settings. """
# 
#     if not _is_valid_and_enabled(view):
#         return
# 
#     Debug('tsconfig', 'tsconfig modified, check')
# 
#     linter = TsconfigLinter(view)
# 
#     return linter
# 
# Path: lib/utils/debug.py
# def Debug(classification, text):
#     if 'all' in print_classifications or classification in print_classifications:
#         print("ArcticTypescript: %s: %s" % (classification.ljust(8), text))
#     if classification not in possible_classifications:
#         print("ArcticTypescript: debug: got unknown debug message classification: %s. " \
#             "Consider adding this to possible_classifications" % classification)
#     sys.stdout.flush()
# 
# Path: lib/utils/pathutils.py
# def get_expandglob_path():
#     """ Return path to expandglob.js """
#     return os.path.join(package_path, 'bin', 'expandglob.js')
# 
# def default_node_path(node_path, project=None):
#     if node_path == 'none':
#         Debug('notify', 'The setting node_path is set to "none". That is depreciated. Remove the setting.')
#         node_path = None
# 
#     if node_path == "" or node_path is None:
#         if sys.platform == "linux":
#             return "nodejs"
#         elif sys.platform == "nt":
#             return "node"
#         elif sys.platform == "darwin":
#             return "/usr/local/bin/node"
#         else:
#             return "node"
#     else:
#         return expand_variables(node_path, project)
# 
# Path: lib/utils/osutils.py
# def get_kwargs(stderr=True):
#     if os.name == 'nt':
#         startupinfo = subprocess.STARTUPINFO()
#         startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
#         if stderr:
#             #errorlog = open(os.devnull, 'w')
#             return {'stderr':subprocess.DEVNULL, 'startupinfo': startupinfo}
#         return {'startupinfo': startupinfo}
#     else:
#         return {}
# 
# Path: lib/utils/disabling.py
# def set_tsglobexpansion_disabled():
#     """ Sets the disabled flag for tsglobexpansion """
#     if "*tsglob" not in plugin_disabled_for_folders:
#         plugin_disabled_for_folders.append("*tsglob")
# 
# def set_tsglobexpansion_enabled():
#     """ Clears the disabled flag for tsglobexpansion """
#     if "*tsglob" in plugin_disabled_for_folders:
#         plugin_disabled_for_folders.remove("*tsglob")
# 
# def is_tsglobexpansion_disabled():
#     """ Checks the disabled flag for tsglobexpansion """
#     return "*tsglob"  in plugin_disabled_for_folders


# Path: lib/tsconfiglint/tsconfigglobexpand.py
import os
import glob
import json
from subprocess import Popen, PIPE, TimeoutExpired
from .TsconfigLinter import check_tsconfig
from ..utils.debug import Debug
from ..utils.pathutils import get_expandglob_path, default_node_path
from ..utils.osutils import get_kwargs
from ..utils.disabling import set_tsglobexpansion_disabled, set_tsglobexpansion_enabled, is_tsglobexpansion_disabled

        node_path = default_node_path(node_path)

        expandglob_path = get_expandglob_path()
        cwd = os.path.abspath(project_dir)

        cmdline = [node_path, expandglob_path]

        kwargs = get_kwargs()

        try:
            # EXECUTE
            expand_glob_process = Popen(cmdline,
                                     stdin=PIPE, stdout=PIPE,
                                     cwd=cwd, **kwargs)
            # FETCH and terminate
            result_str, _err = expand_glob_process.communicate(timeout=10)

            # PARSE
            result = json.loads(str(result_str.decode('UTF-8')))

            # CHECK (only for error Display)
            if "error" in result and isinstance(result['error'], str):
                Debug('error', 'expandglob.js: %s' % result['error'])
            #elif "error" in result and "files" in result \
            #         and result['error'] == False:
            #    return result['files']

        except TimeoutExpired:
            expand_glob_process.kill()
            outs, errs = expand_glob_process.communicate()

            Debug('notify', 'expandglob.js: Timeout')