<commit_before>import csnUtility
import os
import glob
import shutil
import GlobDirectoryWalker

class Manager:
    def __init__(self, _project):
        self.project = _project
        self.filesToInstall = dict()
        self.filesToInstall["Debug"] = dict()
        self.filesToInstall["Release"] = dict()

    def AddFilesToInstall(self, _list, _location = None, _debugOnly = 0, _releaseOnly = 0, _WIN32 = 0, _NOT_WIN32 = 0):
        if not self.project.context.IsForPlatform(_WIN32, _NOT_WIN32):
            return
            
        if _location is None:
            _location = '.'
            
        for file in _list:
            if not _debugOnly:
                if not self.filesToInstall["Release"].has_key(_location):
                    self.filesToInstall["Release"][_location] = []
                if not file in self.filesToInstall["Release"][_location]:
                    self.filesToInstall["Release"][_location].append( file )
            if not _releaseOnly:
                if not self.filesToInstall["Debug"].has_key(_location):
                    self.filesToInstall["Debug"][_location] = []
                if not file in self.filesToInstall["Debug"][_location]:
                    self.filesToInstall["Debug"][_location].append( file )
    
    def ResolvePathsOfFilesToInstall(self, _skipCVS = 1):
        """ 
        This function replaces relative paths and wildcards in self.filesToInstall with absolute paths without wildcards.
        Any folder is replaced by a complete list of the files in that folder.
        _skipCVS - If true, folders called CVS and .svn are automatically skipped. 
        """
        excludedFolderList = ("CVS", ".svn")
        for mode in ("Debug", "Release"):
            for project in self.project.GetProjects(_recursive = 1, _includeSelf = True):
                filesToInstall = dict()
                for location in project.installManager.filesToInstall[mode].keys():
                    for dllPattern in project.installManager.filesToInstall[mode][location]:
                        path = csnUtility.NormalizePath(dllPattern)
                        if not os.path.isabs(path):
                            path = "%s/%s" % (self.project.context.thirdPartyBuildFolder, path)
                        for file in glob.glob(path):
                            if (os.path.basename(file) in excludedFolderList) and _skipCVS and os.path.isdir(file):
                                continue
                            if os.path.isdir(file):
                                for folderFile in GlobDirectoryWalker.Walker(file, ["*"], excludedFolderList):
                                    if not os.path.isdir(folderFile):
                                        normalizedLocation = location + "/" + csnUtility.RemovePrefixFromPath(os.path.dirname(folderFile), file)
                                        normalizedLocation = csnUtility.NormalizePath(normalizedLocation)
                                        if not filesToInstall.has_key(normalizedLocation):
                                            filesToInstall[normalizedLocation] = []
                                        filesToInstall[normalizedLocation].append(csnUtility.NormalizePath(folderFile))
                            else:
                                normalizedLocation = csnUtility.NormalizePath(location)
                                if not filesToInstall.has_key(normalizedLocation):
                                    filesToInstall[normalizedLocation] = []
                                filesToInstall[normalizedLocation].append(csnUtility.NormalizePath(file))
                    
                project.installManager.filesToInstall[mode] = filesToInstall
 
    def InstallBinariesToBuildFolder(self):
        """ 
        This function copies all third party dlls to the build folder, so that you can run the executables in the
        build folder without having to build the INSTALL target.
        """
        result = True
        self.ResolvePathsOfFilesToInstall()

        for mode in ("Debug", "Release"):
            outputFolder = self.project.context.GetOutputFolder(mode)
            os.path.exists(outputFolder) or os.makedirs(outputFolder)
            for project in self.project.GetProjects(_recursive = 1, _includeSelf = True):
                for location in project.installManager.filesToInstall[mode].keys():
                    for file in project.installManager.filesToInstall[mode][location]:
                        absLocation = "%s/%s" % (outputFolder, location)
                        assert not os.path.isdir(file), "\n\nError: InstallBinariesToBuildFolder cannot install a folder (%s)" % file
                        os.path.exists(absLocation) or os.makedirs(absLocation)
                        assert os.path.exists(absLocation), "Could not create %s\n" % absLocation
                        #print "Copying %s to %s\n" % (file, absLocation)
                        fileResult = (0 != shutil.copy(file, absLocation))
                        result = fileResult and result
                        if not fileResult:
                            print "Failed to copy %s to %s\n" % (file, absLocation)
        return result<commit_msg>Create a log for installed files<commit_after>import csnUtility
import os
import glob
import shutil
import GlobDirectoryWalker

class Manager:
    def __init__(self, _project):
        self.project = _project
        self.filesToInstall = dict()
        self.filesToInstall["Debug"] = dict()
        self.filesToInstall["Release"] = dict()

    def AddFilesToInstall(self, _list, _location = None, _debugOnly = 0, _releaseOnly = 0, _WIN32 = 0, _NOT_WIN32 = 0):
        if not self.project.context.IsForPlatform(_WIN32, _NOT_WIN32):
            return
            
        if _location is None:
            _location = '.'
            
        for file in _list:
            if not _debugOnly:
                if not self.filesToInstall["Release"].has_key(_location):
                    self.filesToInstall["Release"][_location] = []
                if not file in self.filesToInstall["Release"][_location]:
                    self.filesToInstall["Release"][_location].append( file )
            if not _releaseOnly:
                if not self.filesToInstall["Debug"].has_key(_location):
                    self.filesToInstall["Debug"][_location] = []
                if not file in self.filesToInstall["Debug"][_location]:
                    self.filesToInstall["Debug"][_location].append( file )
    
    def ResolvePathsOfFilesToInstall(self, _skipCVS = 1):
        """ 
        This function replaces relative paths and wildcards in self.filesToInstall with absolute paths without wildcards.
        Any folder is replaced by a complete list of the files in that folder.
        _skipCVS - If true, folders called CVS and .svn are automatically skipped. 
        """
        excludedFolderList = ("CVS", ".svn")
        for mode in ("Debug", "Release"):
            for project in self.project.GetProjects(_recursive = 1, _includeSelf = True):
                filesToInstall = dict()
                for location in project.installManager.filesToInstall[mode].keys():
                    for dllPattern in project.installManager.filesToInstall[mode][location]:
                        path = csnUtility.NormalizePath(dllPattern)
                        if not os.path.isabs(path):
                            path = "%s/%s" % (self.project.context.thirdPartyBuildFolder, path)
                        for file in glob.glob(path):
                            if (os.path.basename(file) in excludedFolderList) and _skipCVS and os.path.isdir(file):
                                continue
                            if os.path.isdir(file):
                                for folderFile in GlobDirectoryWalker.Walker(file, ["*"], excludedFolderList):
                                    if not os.path.isdir(folderFile):
                                        normalizedLocation = location + "/" + csnUtility.RemovePrefixFromPath(os.path.dirname(folderFile), file)
                                        normalizedLocation = csnUtility.NormalizePath(normalizedLocation)
                                        if not filesToInstall.has_key(normalizedLocation):
                                            filesToInstall[normalizedLocation] = []
                                        filesToInstall[normalizedLocation].append(csnUtility.NormalizePath(folderFile))
                            else:
                                normalizedLocation = csnUtility.NormalizePath(location)
                                if not filesToInstall.has_key(normalizedLocation):
                                    filesToInstall[normalizedLocation] = []
                                filesToInstall[normalizedLocation].append(csnUtility.NormalizePath(file))
                    
                project.installManager.filesToInstall[mode] = filesToInstall
 
    def InstallBinariesToBuildFolder(self):
        """ 
        This function copies all third party dlls to the build folder, so that you can run the executables in the
        build folder without having to build the INSTALL target.
        """
        result = True
        self.ResolvePathsOfFilesToInstall()
        
        logFilename = "%s/Install.log" % self.project.pathsManager.GetBuildFolder()
        f = open(logFilename, 'w')

        for mode in ("Debug", "Release"):
            outputFolder = self.project.context.GetOutputFolder(mode)
            os.path.exists(outputFolder) or os.makedirs(outputFolder)
            for project in self.project.GetProjects(_recursive = 1, _includeSelf = True):
                for location in project.installManager.filesToInstall[mode].keys():
                    for file in project.installManager.filesToInstall[mode][location]:
                        absLocation = "%s/%s" % (outputFolder, location)
                        assert not os.path.isdir(file), "\n\nError: InstallBinariesToBuildFolder cannot install a folder (%s)" % file
                        os.path.exists(absLocation) or os.makedirs(absLocation)
                        assert os.path.exists(absLocation), "Could not create %s\n" % absLocation
                        #print "Copying %s to %s\n" % (file, absLocation)
                        fileResult = (0 != shutil.copy(file, absLocation))
                        result = fileResult and result
                        if not fileResult:
                            print "Failed to copy %s to %s\n" % (file, absLocation)
                        else:
                            message = "copied %s to %s\n" % (file, absLocation)
                            f.write( message )
                            
        f.close()
        return result
{'fraction_non_alphanumeric': 0.08526558891454965, 'fraction_numerical': 0.002956120092378753, 'mean_word_length': 1.7262654243263662, 'pattern_counts': {'":': 0, '<': 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': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3780497', 'n_tokens_mistral': 2652, 'n_tokens_neox': 2564, 'n_words': 647}