<commit_before>from os import path
from ..command_helper.current_view import VIEW_FILE_NAME
import sublime


class PathResolver(object):
    """Provides default paths for plugin"""
    curr_dir = path.dirname(path.realpath(__file__))
    package_dir = path.realpath(path.join(curr_dir, '..'))
    database_folder = path.join(package_dir, 'database')
    index_folder = 'index'
    scanner_folder = 'scanner'
    view_folder = 'view_db'
    log_file_name = 'scan_index.log'

    @property
    def default_db_dir(self):
        return path.join(self.package_dir, self.database_folder)

    @property
    def default_scanner_dir(self):
        return path.join(self.default_db_dir, self.scanner_folder)

    @property
    def default_index_dir(self):
        return path.join(self.default_db_dir, self.index_folder)

    @property
    def default_view_folder(self):
        return path.join(self.default_db_dir, self.view_folder)

    @property
    def default_current_view(self):
        return path.join(self.default_view_folder, VIEW_FILE_NAME)

    @property
    def default_log_file(self):
        return path.join(self.default_db_dir, self.log_file_name)

    @property
    def datapraser_folder(self):
        return path.join(self.package_dir, 'dataparser')

    @property
    def scanner_runner(self):
        return path.join(self.datapraser_folder, 'run_scanner.py')

    @property
    def index_runner(self):
        return path.join(self.datapraser_folder, 'run_index.py')

    @property
    def log_file(self):
        return path.join(self.default_db_dir, self.log_file_name)


class SettingObject(object):

    table_dir = 'table_dir'
    index_dir = 'index_dir'
    scanner_runner = 'scanner_runner'
    index_runner = 'index_runner'
    log_file = 'log_file'
    python_binary = 'path_to_python'
    workspace = 'robot_framework_workspace'
    extension = 'robot_framework_extension'
    builtin_variables = 'robot_framework_builtin_variables'
    module_search_path = 'robot_framework_module_search_path'
    view_completions = 'view_completions'
    view_path = 'view_path'
    arg_format = 'robot_framework_keyword_argument_format'
    lib_in_xml = 'robot_framework_libraries_in_xml'
    project_setting = 'robot_framework_assistant'
    db_dir = 'robot_framework_database_path'
    log_commands = 'robot_framework_log_commands'


def get_scanner_dir():
    project_setting = parse_project(SettingObject.db_dir)
    if not project_setting:
        return PathResolver().default_scanner_dir
    else:
        return path.join(project_setting, PathResolver().scanner_folder)


def get_index_dir():
    project_setting = parse_project(SettingObject.db_dir)
    if not project_setting:
        return PathResolver().default_index_dir
    else:
        return path.join(project_setting, PathResolver.index_folder)


def get_log_file():
    project_setting = parse_project(SettingObject.db_dir)
    if not project_setting:
        return PathResolver().log_file
    else:
        return path.join(project_setting, PathResolver().log_file_name)


def get_view_file():
    project_setting = parse_project(SettingObject.db_dir)
    if not project_setting:
        return PathResolver().default_current_view
    else:
        return path.join(
            project_setting,
            PathResolver().view_folder,
            VIEW_FILE_NAME)


def get_view_path():
    project_setting = parse_project(SettingObject.db_dir)
    if not project_setting:
        return PathResolver().default_view_folder
    else:
        return path.join(project_setting, PathResolver().view_folder)


def get_setting(setting):
    if setting.lower() == SettingObject.table_dir:
        return get_scanner_dir()
    elif setting.lower() == SettingObject.index_dir:
        return get_index_dir()
    elif setting.lower() == SettingObject.scanner_runner:
        return PathResolver().scanner_runner
    elif setting.lower() == SettingObject.index_runner:
        return PathResolver().index_runner
    elif setting.lower() == SettingObject.log_file:
        return get_log_file()
    elif setting.lower() == SettingObject.view_completions:
        return get_view_file()
    elif setting.lower() == SettingObject.view_path:
        return get_view_path()
    else:
        return get_sublime_setting(setting)


def parse_project(setting):
    rf_project_setting = None
    window = sublime.active_window()
    project_data = window.project_data()
    if SettingObject.project_setting in project_data:
        rf_project_data = project_data[SettingObject.project_setting]
        if setting in rf_project_data:
            rf_project_setting = rf_project_data[setting]
    if setting == SettingObject.db_dir:
        if not path.isdir(setting):
            rf_project_setting = None
    return rf_project_setting


def get_sublime_setting(setting):
    project_setting = parse_project(setting)
    if not project_setting:
        plugin_settings = sublime.load_settings('Robot.sublime-settings')
        return plugin_settings.get(setting)
    else:
        return project_setting<commit_msg>Fixes #128 by checking did project settings exist<commit_after>from os import path
from ..command_helper.current_view import VIEW_FILE_NAME
import sublime


class PathResolver(object):
    """Provides default paths for plugin"""
    curr_dir = path.dirname(path.realpath(__file__))
    package_dir = path.realpath(path.join(curr_dir, '..'))
    database_folder = path.join(package_dir, 'database')
    index_folder = 'index'
    scanner_folder = 'scanner'
    view_folder = 'view_db'
    log_file_name = 'scan_index.log'

    @property
    def default_db_dir(self):
        return path.join(self.package_dir, self.database_folder)

    @property
    def default_scanner_dir(self):
        return path.join(self.default_db_dir, self.scanner_folder)

    @property
    def default_index_dir(self):
        return path.join(self.default_db_dir, self.index_folder)

    @property
    def default_view_folder(self):
        return path.join(self.default_db_dir, self.view_folder)

    @property
    def default_current_view(self):
        return path.join(self.default_view_folder, VIEW_FILE_NAME)

    @property
    def default_log_file(self):
        return path.join(self.default_db_dir, self.log_file_name)

    @property
    def datapraser_folder(self):
        return path.join(self.package_dir, 'dataparser')

    @property
    def scanner_runner(self):
        return path.join(self.datapraser_folder, 'run_scanner.py')

    @property
    def index_runner(self):
        return path.join(self.datapraser_folder, 'run_index.py')

    @property
    def log_file(self):
        return path.join(self.default_db_dir, self.log_file_name)


class SettingObject(object):

    table_dir = 'table_dir'
    index_dir = 'index_dir'
    scanner_runner = 'scanner_runner'
    index_runner = 'index_runner'
    log_file = 'log_file'
    python_binary = 'path_to_python'
    workspace = 'robot_framework_workspace'
    extension = 'robot_framework_extension'
    builtin_variables = 'robot_framework_builtin_variables'
    module_search_path = 'robot_framework_module_search_path'
    view_completions = 'view_completions'
    view_path = 'view_path'
    arg_format = 'robot_framework_keyword_argument_format'
    lib_in_xml = 'robot_framework_libraries_in_xml'
    project_setting = 'robot_framework_assistant'
    db_dir = 'robot_framework_database_path'
    log_commands = 'robot_framework_log_commands'


def get_scanner_dir():
    project_setting = parse_project(SettingObject.db_dir)
    if not project_setting:
        return PathResolver().default_scanner_dir
    else:
        return path.join(project_setting, PathResolver().scanner_folder)


def get_index_dir():
    project_setting = parse_project(SettingObject.db_dir)
    if not project_setting:
        return PathResolver().default_index_dir
    else:
        return path.join(project_setting, PathResolver.index_folder)


def get_log_file():
    project_setting = parse_project(SettingObject.db_dir)
    if not project_setting:
        return PathResolver().log_file
    else:
        return path.join(project_setting, PathResolver().log_file_name)


def get_view_file():
    project_setting = parse_project(SettingObject.db_dir)
    if not project_setting:
        return PathResolver().default_current_view
    else:
        return path.join(
            project_setting,
            PathResolver().view_folder,
            VIEW_FILE_NAME)


def get_view_path():
    project_setting = parse_project(SettingObject.db_dir)
    if not project_setting:
        return PathResolver().default_view_folder
    else:
        return path.join(project_setting, PathResolver().view_folder)


def get_setting(setting):
    if setting.lower() == SettingObject.table_dir:
        return get_scanner_dir()
    elif setting.lower() == SettingObject.index_dir:
        return get_index_dir()
    elif setting.lower() == SettingObject.scanner_runner:
        return PathResolver().scanner_runner
    elif setting.lower() == SettingObject.index_runner:
        return PathResolver().index_runner
    elif setting.lower() == SettingObject.log_file:
        return get_log_file()
    elif setting.lower() == SettingObject.view_completions:
        return get_view_file()
    elif setting.lower() == SettingObject.view_path:
        return get_view_path()
    else:
        return get_sublime_setting(setting)


def parse_project(setting):
    rf_project_setting = None
    window = sublime.active_window()
    project_data = window.project_data()
    if project_data and SettingObject.project_setting in project_data:
        rf_project_data = project_data[SettingObject.project_setting]
        if setting in rf_project_data:
            rf_project_setting = rf_project_data[setting]
    if setting == SettingObject.db_dir:
        if not path.isdir(setting):
            rf_project_setting = None
    return rf_project_setting


def get_sublime_setting(setting):
    project_setting = parse_project(setting)
    if not project_setting:
        plugin_settings = sublime.load_settings('Robot.sublime-settings')
        return plugin_settings.get(setting)
    else:
        return project_setting
{'fraction_non_alphanumeric': 0.08373322887082559, 'fraction_numerical': 0.00029380080305552837, 'mean_word_length': 3.7059907834101384, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6674462', 'n_tokens_mistral': 3152, 'n_tokens_neox': 3085, 'n_words': 566}