<commit_before>import re
import commands
import tempfile
import os

gInstance = None
CMAKE_CACHE = "CMakeCache.txt"

class Vicmake():
    mVarList = []
    mInternalVarList = []
    mLogFilename = ""
    mNameCacheFilename = ""
    mValCacheFilename = ""
    mTypeCacheFilename = ""
    mInitDone = False
    mSrcDir = ""

    def __init__(self):
        self.mLogFilename = tempfile.NamedTemporaryFile()
        self.mNameCacheFilename = tempfile.NamedTemporaryFile()
        self.mValCacheFilename = tempfile.NamedTemporaryFile()
        self.mTypeCacheFilename = tempfile.NamedTemporaryFile()

    def ParseFile(self):
        self.mVarList = []
        self.mInternalVarList = []
        isStartInternal = False
        try:
            f = open(CMAKE_CACHE, "r")
        except Exception as e:
            raise e
        for l in f.readlines():
            m = re.search(r"^([a-zA-Z0-9_-]+):(\S+)=(.*)$", l)
            if m:
                name = m.group(1)
                type = m.group(2)
                val = m.group(3)
                if "CMAKE_HOME_DIRECTORY" == name:
                    self.mSrcDir = val
                if isStartInternal:
                    self.mInternalVarList.append((name, type, val))
                else:
                    self.mVarList.append((name, type, val))
            m = re.search(r"^# INTERNAL cache entries", l)
            if m:
                isStartInternal = True
        self.mInitDone = True

    def Dump(self):
        for v in self.mVarList:
            print "%s:%s\t\t%s"%(v[1], v[0], v[2])

    def RunCmake(self, dir):
        cmd = "cmake " + str(dir)
        (rv, out) = commands.getstatusoutput(cmd)
        self.ParseFile()
        self.InitEdit()

    def LoadCache(self):
        self.ParseFile()
        try:
            fval = open(self.GetValCacheFilename(), "w")
            fname = open(self.GetNameCacheFilename(), "w")
            ftype = open(self.GetTypeCacheFilename(), "w")
        except Exception as e:
            raise e

        for l in self.mVarList:
            fname.write("%s\n"%(l[0]))
            ftype.write("%s\n"%(l[1]))
            fval.write("%s\n"%(l[2]))

        fval.close()
        ftype.close()
        fname.close()
        return True

    def WritebackCache(self):
        try:
            fout = open(CMAKE_CACHE, "w")
            fval = open(self.mValCacheFilename.name, "r")
            fname = open(self.mNameCacheFilename.name, "r")
            ftype = open(self.mTypeCacheFilename.name, "r")
        except Exception as e:
            raise e

        linesVal = fval.readlines()
        linesName = fname.readlines()
        linesType = ftype.readlines()
<commit_msg>Separate static variables with others.<commit_after>import re
import commands
import tempfile
import os

gInstance = None
CMAKE_CACHE = "CMakeCache.txt"

class Vicmake():
    mVarList = []
    mStaticVarList = []
    mInternalVarList = []
    mLogFilename = ""
    mNameCacheFilename = ""
    mValCacheFilename = ""
    mTypeCacheFilename = ""
    mInitDone = False
    mSrcDir = ""

    def __init__(self):
        self.mLogFilename = tempfile.NamedTemporaryFile()
        self.mNameCacheFilename = tempfile.NamedTemporaryFile()
        self.mValCacheFilename = tempfile.NamedTemporaryFile()
        self.mTypeCacheFilename = tempfile.NamedTemporaryFile()

    def ParseFile(self):
        self.mVarList = []
        self.mInternalVarList = []
        isStartInternal = False
        try:
            f = open(CMAKE_CACHE, "r")
        except Exception as e:
            raise e
        for l in f.readlines():
            m = re.search(r"^([a-zA-Z0-9_-]+):(\S+)=(.*)$", l)
            if m:
                name = m.group(1)
                type = m.group(2)
                val = m.group(3)
                if "CMAKE_HOME_DIRECTORY" == name:
                    self.mSrcDir = val
                if isStartInternal:
                    self.mInternalVarList.append((name, type, val))
                else:
                    if type == "STATIC":
                        self.mStaticVarList.append((name, type, val))
                    else:
                        self.mVarList.append((name, type, val))
            m = re.search(r"^# INTERNAL cache entries", l)
            if m:
                isStartInternal = True
        self.mInitDone = True

    def Dump(self):
        for v in self.mVarList:
            print "%s:%s\t\t%s"%(v[1], v[0], v[2])
        for v in self.mStaticVarList:
            print "%s:%s\t\t%s"%(v[1], v[0], v[2])

    def RunCmake(self, dir):
        cmd = "cmake " + str(dir)
        (rv, out) = commands.getstatusoutput(cmd)
        self.ParseFile()
        self.InitEdit()

    def LoadCache(self):
        self.ParseFile()
        try:
            fval = open(self.GetValCacheFilename(), "w")
            fname = open(self.GetNameCacheFilename(), "w")
            ftype = open(self.GetTypeCacheFilename(), "w")
        except Exception as e:
            raise e

        for l in self.mVarList:
            fname.write("%s\n"%(l[0]))
            ftype.write("%s\n"%(l[1]))
            fval.write("%s\n"%(l[2]))
        for l in self.mStaticVarList:
            fname.write("%s\n"%(l[0]))
            ftype.write("%s\n"%(l[1]))
            fval.write("%s\n"%(l[2]))

        fval.close()
        ftype.close()
        fname.close()
        return True

    def WritebackCache(self):
        try:
            fout = open(CMAKE_CACHE, "w")
            fval = open(self.mValCacheFilename.name, "r")
            fname = open(self.mNameCacheFilename.name, "r")
            ftype = open(self.mTypeCacheFilename.name, "r")
        except Exception as e:
            raise e

        linesVal = fval.readlines()
        linesName = fname.readlines()
        linesType = ftype.readlines()

{'fraction_non_alphanumeric': 0.12863785086964008, 'fraction_numerical': 0.004821766833132427, 'mean_word_length': 1.724202626641651, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, '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': '4356147', 'n_tokens_mistral': 1845, 'n_tokens_neox': 1787, 'n_words': 365}