<commit_before>import sublime, sublime_plugin
import os
import ConfigParser
from StringIO import StringIO

# This may only work on Windows 7 and up -- fine for our purposes
INI_LOCATION = os.path.expanduser("~/Documents/SublimePapyrus.ini")

# Default values for a standardized Steam installation (for end-users and modders)
if (os.path.exists("C:\\Program Files (x86)")):
    END_USER_ROOT = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\skyrim"
else:
    END_USER_ROOT = "C:\\Program Files\\Steam\\steamapps\\common\\skyrim"
END_USER_OUTPUT   = os.path.join(END_USER_ROOT, "Data\\Scripts")
END_USER_SCRIPTS  = os.path.join(END_USER_OUTPUT, "Source")
END_USER_COMPILER = os.path.join(END_USER_ROOT, "Papyrus Compiler\\PapyrusCompiler.exe")
END_USER_FLAGS    = "TESV_Papyrus_Flags.flg"

DEFAULT_INI_TEXT = """[Skyrim]
# The path to the folder containing the vanilla Skyrim .psc files.
scripts=%s

# The path to PapyrusCompiler.exe
compiler=%s

# The folder you wish to output the .pex files to. If commented out, then .pex files are placed in the folder one level above the .psc file.
output=%s

# The name of the file containing Papyrus' flags. The file has to be among the folders that are imported, which includes the scripts folder defined above and the folder containing the .psc file(s) to be compiled.
flags=%s

[Import]
# Additional folders that contain .psc you wish to import when compiling.
# The folders are processed from the lowest entry (path1) to the highest entry (pathN).
# pathN=DriveName:\\FolderName\\SubfolderName\\
path1=C:\\SKSE\\Scripts\\Source
""" % (END_USER_SCRIPTS, END_USER_COMPILER, END_USER_OUTPUT, END_USER_FLAGS)

def getPrefs(filePath):
    fileDir, fileName = os.path.split(filePath)
    ret = {}
    if (not os.path.exists(INI_LOCATION)):
        ret["compiler"] = END_USER_COMPILER
        ret["output"] = END_USER_OUTPUT
        ret["flags"] = END_USER_FLAGS
        ret["import"] = END_USER_SCRIPTS
    else:
        parser = ConfigParser.ConfigParser()
        parser.read([INI_LOCATION])

        if (parser.has_section("Skyrim")):
            if(parser.has_option("Skyrim", "compiler")):
                ret["compiler"] = parser.get("Skyrim", "compiler")
            else:
                ret["compiler"] = END_USER_COMPILER

            if(parser.has_option("Skyrim", "output")):
                ret["output"] = parser.get("Skyrim", "output")
            else:
                ret["output"] = os.path.dirname(fileDir)

            if(parser.has_option("Skyrim", "flags")):
                ret["flags"] = parser.get("Skyrim", "flags")
            else:
                ret["flags"] = END_USER_FLAGS

        else:
            ret["compiler"]  = END_USER_COMPILER
            ret["output"]    = END_USER_OUTPUT
            ret["flags"]     = END_USER_FLAGS

        ret["import"] = [fileDir]
        if (parser.has_section("Import")):
            for configKey, configValue in parser.items("Import"):
                if (configKey.startswith("path")):
                    ret["import"].append(configValue)

        ret["import"].append(parser.get("Skyrim", "scripts"))
        ret["import"] = ";".join(filter(None, ret["import"]))

    ret["filename"] = fileName
    return ret

class CompilePapyrusCommand(sublime_plugin.WindowCommand):
    def run(self, **args):
        config = getPrefs(args["cmd"])
        if (len(config) > 0):
            args["cmd"] = [config["compiler"], config["filename"]]
            args["cmd"].append("-f=%s" % config["flags"])<commit_msg>Added check for existence of imported folder<commit_after>import sublime, sublime_plugin
import os
import ConfigParser
from StringIO import StringIO

# This may only work on Windows 7 and up -- fine for our purposes
INI_LOCATION = os.path.expanduser("~/Documents/SublimePapyrus.ini")

# Default values for a standardized Steam installation (for end-users and modders)
if (os.path.exists("C:\\Program Files (x86)")):
    END_USER_ROOT = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\skyrim"
else:
    END_USER_ROOT = "C:\\Program Files\\Steam\\steamapps\\common\\skyrim"
END_USER_OUTPUT   = os.path.join(END_USER_ROOT, "Data\\Scripts")
END_USER_SCRIPTS  = os.path.join(END_USER_OUTPUT, "Source")
END_USER_COMPILER = os.path.join(END_USER_ROOT, "Papyrus Compiler\\PapyrusCompiler.exe")
END_USER_FLAGS    = "TESV_Papyrus_Flags.flg"

DEFAULT_INI_TEXT = """[Skyrim]
# The path to the folder containing the vanilla Skyrim .psc files.
scripts=%s

# The path to PapyrusCompiler.exe
compiler=%s

# The folder you wish to output the .pex files to. If commented out, then .pex files are placed in the folder one level above the .psc file.
output=%s

# The name of the file containing Papyrus' flags. The file has to be among the folders that are imported, which includes the scripts folder defined above and the folder containing the .psc file(s) to be compiled.
flags=%s

[Import]
# Additional folders that contain .psc you wish to import when compiling.
# The folders are processed from the lowest entry (path1) to the highest entry (pathN).
# pathN=DriveName:\\FolderName\\SubfolderName\\
path1=C:\\SKSE\\Scripts\\Source
""" % (END_USER_SCRIPTS, END_USER_COMPILER, END_USER_OUTPUT, END_USER_FLAGS)

def getPrefs(filePath):
    fileDir, fileName = os.path.split(filePath)
    ret = {}
    if (not os.path.exists(INI_LOCATION)):
        ret["compiler"] = END_USER_COMPILER
        ret["output"] = END_USER_OUTPUT
        ret["flags"] = END_USER_FLAGS
        ret["import"] = END_USER_SCRIPTS
    else:
        parser = ConfigParser.ConfigParser()
        parser.read([INI_LOCATION])

        if (parser.has_section("Skyrim")):
            if(parser.has_option("Skyrim", "compiler")):
                ret["compiler"] = parser.get("Skyrim", "compiler")
            else:
                ret["compiler"] = END_USER_COMPILER

            if(parser.has_option("Skyrim", "output")):
                ret["output"] = parser.get("Skyrim", "output")
            else:
                ret["output"] = os.path.dirname(fileDir)

            if(parser.has_option("Skyrim", "flags")):
                ret["flags"] = parser.get("Skyrim", "flags")
            else:
                ret["flags"] = END_USER_FLAGS

        else:
            ret["compiler"]  = END_USER_COMPILER
            ret["output"]    = END_USER_OUTPUT
            ret["flags"]     = END_USER_FLAGS

        ret["import"] = [fileDir]
        if (parser.has_section("Import")):
            for configKey, configValue in parser.items("Import"):
                if (configKey.startswith("path")):
                    if (os.path.exists(configValue)):
                        ret["import"].append(configValue)

        ret["import"].append(parser.get("Skyrim", "scripts"))
        ret["import"] = ";".join(filter(None, ret["import"]))

    ret["filename"] = fileName
    return ret

class CompilePapyrusCommand(sublime_plugin.WindowCommand):
    def run(self, **args):
        config = getPrefs(args["cmd"])
        if (len(config) > 0):
            args["cmd"] = [config["compiler"], config["filename"]]
            args["cmd"].append("-f=%s" % config["flags"])
{'fraction_non_alphanumeric': 0.13263157894736843, 'fraction_numerical': 0.002245614035087719, 'mean_word_length': 3.065031374786081, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4505502', 'n_tokens_mistral': 2265, 'n_tokens_neox': 2169, 'n_words': 541}