# Path: commands/scan.py
# def scan_popen_arg_parser(mode):
#     arg_list = []
#     arg_list.append(get_setting(SettingObject.python_binary))
#     arg_list.append(get_setting(SettingObject.scanner_runner))
#     arg_list.append(mode)
#     arg_list.append('--db_path')
#     arg_list.append(get_setting(SettingObject.table_dir))
#     arg_list.append('--extension')
#     arg_list.append(get_setting(SettingObject.extension))
#     arg_list.append('--path_to_lib_in_xml')
#     arg_list.append(get_setting(SettingObject.lib_in_xml))
#     arg_list.append('--module_search_path')
#     for module in get_setting(SettingObject.module_search_path):
#         arg_list.append(module)
#     return arg_list


import sublime_plugin
import sublime
import subprocess
from platform import system
from os import path, makedirs
from ..setting.setting import get_setting
from ..setting.setting import SettingObject
from .scan import scan_popen_arg_parser

class ScanOpenTabCommand(sublime_plugin.TextCommand):

    def run(self, edit):
        """Command to scan open tab RF file and create db table

        Purpose of the command is scan and create the db table
        from the currently open tab.
        """
        log_file = get_setting(SettingObject.log_file)
        makedirs(path.dirname(log_file), exist_ok=True)
        open_tab = self.view.file_name()
        if self.file_in_workspace(open_tab):
            file_ = open(log_file, 'a')
            sublime.set_timeout_async(
                self.run_single_scan(
                    open_tab,
                    file_
                ),
                0
            )
            file_.close()
        else:
            message = 'Not able to scan file: {0}'.format(open_tab)
            sublime.status_message(message)

    def run_single_scan(self, open_tab, log_file):
        startupinfo = None
        if system() == 'Windows':
            startupinfo = subprocess.STARTUPINFO()
            startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW

# Path: commands/scan.py
# def scan_popen_arg_parser(mode):
#     arg_list = []
#     arg_list.append(get_setting(SettingObject.python_binary))
#     arg_list.append(get_setting(SettingObject.scanner_runner))
#     arg_list.append(mode)
#     arg_list.append('--db_path')
#     arg_list.append(get_setting(SettingObject.table_dir))
#     arg_list.append('--extension')
#     arg_list.append(get_setting(SettingObject.extension))
#     arg_list.append('--path_to_lib_in_xml')
#     arg_list.append(get_setting(SettingObject.lib_in_xml))
#     arg_list.append('--module_search_path')
#     for module in get_setting(SettingObject.module_search_path):
#         arg_list.append(module)
#     return arg_list


# Path: commands/scan_open_tab.py
import sublime_plugin
import sublime
import subprocess
from platform import system
from os import path, makedirs
from ..setting.setting import get_setting
from ..setting.setting import SettingObject
from .scan import scan_popen_arg_parser

class ScanOpenTabCommand(sublime_plugin.TextCommand):

    def run(self, edit):
        """Command to scan open tab RF file and create db table

        Purpose of the command is scan and create the db table
        from the currently open tab.
        """
        log_file = get_setting(SettingObject.log_file)
        makedirs(path.dirname(log_file), exist_ok=True)
        open_tab = self.view.file_name()
        if self.file_in_workspace(open_tab):
            file_ = open(log_file, 'a')
            sublime.set_timeout_async(
                self.run_single_scan(
                    open_tab,
                    file_
                ),
                0
            )
            file_.close()
        else:
            message = 'Not able to scan file: {0}'.format(open_tab)
            sublime.status_message(message)

    def run_single_scan(self, open_tab, log_file):
        startupinfo = None
        if system() == 'Windows':
            startupinfo = subprocess.STARTUPINFO()
            startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW

        p_args = scan_popen_arg_parser('single')
