# 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 add_usr_local_bin_to_path_on_osx():
# def find_tsconfigdir(rootdir):
# def expand_variables(path, project=None, use_cache=False):
# def get_tss_path():
# def get_expandglob_path():
# def default_node_path(node_path, project=None):
# def default_tsc_path(tsc_path=None, project=None):
# def search_node_modules(rootdir):
# 
# 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/pathutils.py
# def default_tsc_path(tsc_path=None, project=None):
#     if tsc_path is not None and tsc_path:
#         tsc_path = expand_variables(tsc_path, project)
#         return tsc_path
# 
#     # search node_modules
#     if project:
#         node_modules_dir = search_node_modules(project.tsconfigdir)
#         if node_modules_dir:
#             tsc_path = os.path.join(node_modules_dir, ".bin", "tsc")
#             if file_exists(tsc_path):
#                 return os.path.normcase(tsc_path)
# 
#     # use ArcticTypescript's tsc
#     return os.path.join(package_path, 'bin', 'node_modules', 'typescript', 'bin', 'tsc')
# 
# 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)
# 
# def expand_variables(path, project=None, use_cache=False):
#     variables = {}
#     if project is not None:
#         variables.update(project.extract_variables(use_cache))
#     return replace_variables(path, variables)
# 
# Path: lib/display/Panel.py
# PANEL = Panel()


from subprocess import Popen, PIPE
from threading import Thread
    from queue import Queue
    from Queue import Queue
from ..utils import package_path, Debug
from ..utils.osutils import get_kwargs
from ..utils.pathutils import default_tsc_path, default_node_path, expand_variables
from ..display.Panel import PANEL
import sublime
import os
import json
        cmdline = [node_path, tsc_path, "--project", "."]

        return node_path, cmdline


    def _run_forward_compiler_output(self):
        for line in iter(self.p.stdout.readline, b''):
                Debug('build+', 'BUILD RESULTS: %s' % line)
                try:
                    line = line.decode('UTF-8')
                    line = line.replace('\r', '')
                except ValueError as v:
                    break
                self._show_output(line)
        Debug('build+', 'BUILD RESULTS: all lined read')
        self.p.stdout.close()
        self._show_output("\n")


    def kill(self):
        self.cancel_build = True
        if self.p:
            try:
                Debug('build+', 'BUILD: Kill process!')
                self.p.terminate()
                self.p.kill()
                self._show_output("<<< Process has been terminated. Waiting for Compiler Thread to finish\n")
                self.p.communicate() # release readline() block
                Debug('build+', 'BUILD: process killed')
            except Exception as e:

# 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 add_usr_local_bin_to_path_on_osx():
# def find_tsconfigdir(rootdir):
# def expand_variables(path, project=None, use_cache=False):
# def get_tss_path():
# def get_expandglob_path():
# def default_node_path(node_path, project=None):
# def default_tsc_path(tsc_path=None, project=None):
# def search_node_modules(rootdir):
# 
# 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/pathutils.py
# def default_tsc_path(tsc_path=None, project=None):
#     if tsc_path is not None and tsc_path:
#         tsc_path = expand_variables(tsc_path, project)
#         return tsc_path
# 
#     # search node_modules
#     if project:
#         node_modules_dir = search_node_modules(project.tsconfigdir)
#         if node_modules_dir:
#             tsc_path = os.path.join(node_modules_dir, ".bin", "tsc")
#             if file_exists(tsc_path):
#                 return os.path.normcase(tsc_path)
# 
#     # use ArcticTypescript's tsc
#     return os.path.join(package_path, 'bin', 'node_modules', 'typescript', 'bin', 'tsc')
# 
# 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)
# 
# def expand_variables(path, project=None, use_cache=False):
#     variables = {}
#     if project is not None:
#         variables.update(project.extract_variables(use_cache))
#     return replace_variables(path, variables)
# 
# Path: lib/display/Panel.py
# PANEL = Panel()


# Path: lib/commands/Compiler.py
from subprocess import Popen, PIPE
from threading import Thread
    from queue import Queue
    from Queue import Queue
from ..utils import package_path, Debug
from ..utils.osutils import get_kwargs
from ..utils.pathutils import default_tsc_path, default_node_path, expand_variables
from ..display.Panel import PANEL
import sublime
import os
import json

        cmdline = [node_path, tsc_path, "--project", "."]

        return node_path, cmdline


    def _run_forward_compiler_output(self):
        for line in iter(self.p.stdout.readline, b''):
                Debug('build+', 'BUILD RESULTS: %s' % line)
                try:
                    line = line.decode('UTF-8')
                    line = line.replace('\r', '')
                except ValueError as v:
                    break
                self._show_output(line)
        Debug('build+', 'BUILD RESULTS: all lined read')
        self.p.stdout.close()
        self._show_output("\n")


    def kill(self):
        self.cancel_build = True
        if self.p:
            try:
                Debug('build+', 'BUILD: Kill process!')
                self.p.terminate()
                self.p.kill()
                self._show_output("<<< Process has been terminated. Waiting for Compiler Thread to finish\n")
                self.p.communicate() # release readline() block
                Debug('build+', 'BUILD: process killed')
            except Exception as e:

                Debug('error', "Failure while killing compiler thread: %s" % e)