def saveProjectsList(allProjects):
        '''
        Store all the projects from memory into disk.
        '''
        def saveTreeFiles(treeFiles):
            jsonTreeFiles = []
            for myTreeFile in treeFiles:
                jsonTreeFile = {}
                jsonTreeFile[ProjectSerializer.FILE_TO_ANNOTATE] = myTreeFile[0]
                jsonTreeFile[ProjectSerializer.HEADER_TO_INCLUDE] = myTreeFile[1]
                jsonTreeFiles.append(jsonTreeFile)
            return jsonTreeFiles
        
        #First, save in all projects information
        dataFolder = config.installationConfig().getDataFolder()
        indexFilePath = os.path.join(dataFolder, ProjectSerializer.INDEX_FILE_NAME)
        
        projectsIndexMap = {}
        for projectName, aProject in allProjects.items():
            projectsIndexMap[projectName] = aProject.getFolder()
            #Now, save current project
            projectMap = {}
            projectMap[ProjectSerializer.NAME] = aProject.getName()
            projectMap[ProjectSerializer.LOCATION] = aProject.getFolder()
            projectMap[ProjectSerializer.LANGUAGE] = aProject.getLanguage()
            projectMap[ProjectSerializer.SOLUTION_FILE] = aProject.getSolutionFile()
            projectMap[ProjectSerializer.MAIN_FILE] = aProject.getMainFile()
            projectMap[ProjectSerializer.MAIN_FUNCTION] = aProject.getMainFunction()
            projectMap[ProjectSerializer.EXE_COMMAND] = aProject.getExeCommand()
            projectMap[ProjectSerializer.TREE_FILES] = saveTreeFiles(aProject.getTreeFiles())
            projectMap[ProjectSerializer.COMPILING_COMMAND] = aProject.getCompilingCommand()                        
            projectMap[ProjectSerializer.CPP_PROJECT] = aProject.getCppProject()
            
            projectFolder = aProject.getFolder()
            createFolderIfNotExists(projectFolder)
            executionsFolder = aProject.getExecutionsFolder()
            createFolderIfNotExists(executionsFolder)

            projectConfigPath = os.path.join(projectFolder, ProjectSerializer.PROJECT_SETTINGS_FILE_NAME)
            
            with open(projectConfigPath, 'w') as fp:
                json.dump(projectMap, fp, sort_keys=True, indent=ProjectSerializer.INDENT)
                
        with open(indexFilePath, 'w') as fp:
            json.dump(projectsIndexMap, fp, sort_keys=True, indent=ProjectSerializer.INDENT)
Ejemplo n.º 2
0
    def loadConfig():
        '''
        Load configuration.
        '''
        dataFolder = installationConfig().getDataFolder()
        file_utils.createFolderIfNotExists(dataFolder)
        projectsFolder = _getProjectsFolder()
        file_utils.createFolderIfNotExists(projectsFolder)

        settingsFolder = os.path.join(dataFolder, Config.SETTINGS_FOLDER_NAME)
        file_utils.createFolderIfNotExists(settingsFolder)

        ConfigSerializer.CONFIG_FILE_PATH = os.path.join(
            settingsFolder, ConfigSerializer.CONFIG_FILE_NAME)

        #Check existence of configuration file, and load it. Use default values otherwise
        if os.path.exists(ConfigSerializer.CONFIG_FILE_PATH):
            with open(ConfigSerializer.CONFIG_FILE_PATH, 'r') as fp:
                configMap = json.load(fp)
                defaultLanguage = configMap[ConfigSerializer.DEFAULT_LANGUAGE]
                cpp_defaultRootFolder = configMap[
                    ConfigSerializer.CPP_DEFAULT_ROOT_FOLDER]
                python_defaultRootFolder = configMap[
                    ConfigSerializer.PYTHON_DEFAULT_ROOT_FOLDER]
                defaultCompilingCommand = configMap[
                    ConfigSerializer.DEFAULT_COMPILING_COMMAND]
                cpp_defaultExeCommand = configMap[
                    ConfigSerializer.CPP_DEFAULT_EXE_COMMAND]
                python_defaultExeCommand = configMap[
                    ConfigSerializer.PYTHON_DEFAULT_EXE_COMMAND]
                boostIncludeFolder = configMap[
                    ConfigSerializer.BOOST_INCLUDE_FOLDER]
                boostLibraryFolder = configMap[
                    ConfigSerializer.BOOST_LIBRARY_FOLDER]
                visualStudioExe = configMap[ConfigSerializer.VISUAL_STUDIO_EXE]
                solutionExtensions = configMap[
                    ConfigSerializer.SOLUTION_EXTENSIONS]
                projectExtensions = configMap[
                    ConfigSerializer.PROJECT_EXTENSIONS]
        else:
            #TODO GERVA: Move this code to installer
            defaultLanguage, cpp_defaultRootFolder, python_defaultRootFolder, defaultCompilingCommand, cpp_defaultExeCommand, python_defaultExeCommand, boostIncludeFolder, boostLibraryFolder, visualStudioExe, solutionExtensions, projectExtensions = getDefaultValues(
            )

        myConfig = instance()
        myConfig.defaultLanguage = defaultLanguage
        myConfig.cpp_defaultRootFolder = cpp_defaultRootFolder
        myConfig.python_defaultRootFolder = python_defaultRootFolder
        myConfig.defaultCompilingCommand = defaultCompilingCommand
        myConfig.cpp_defaultExeCommand = cpp_defaultExeCommand
        myConfig.python_defaultExeCommand = python_defaultExeCommand
        myConfig.boostIncludeFolder = boostIncludeFolder
        myConfig.boostLibraryFolder = boostLibraryFolder
        myConfig.visualStudioExe = visualStudioExe
        myConfig.solutionExtensions = solutionExtensions
        myConfig.projectExtensions = projectExtensions
    def loadConfig():
        '''
        Load configuration.
        '''
        dataFolder = installationConfig().getDataFolder()
        file_utils.createFolderIfNotExists(dataFolder)
        projectsFolder = _getProjectsFolder()
        file_utils.createFolderIfNotExists(projectsFolder)
           
        settingsFolder = os.path.join(dataFolder, Config.SETTINGS_FOLDER_NAME)
        file_utils.createFolderIfNotExists(settingsFolder)
        
        ConfigSerializer.CONFIG_FILE_PATH = os.path.join(settingsFolder, ConfigSerializer.CONFIG_FILE_NAME)

        #Check existence of configuration file, and load it. Use default values otherwise
        if os.path.exists(ConfigSerializer.CONFIG_FILE_PATH):
            with open(ConfigSerializer.CONFIG_FILE_PATH, 'r') as fp:
                configMap = json.load(fp)
                defaultLanguage = configMap[ConfigSerializer.DEFAULT_LANGUAGE]
                cpp_defaultRootFolder = configMap[ConfigSerializer.CPP_DEFAULT_ROOT_FOLDER]
                python_defaultRootFolder = configMap[ConfigSerializer.PYTHON_DEFAULT_ROOT_FOLDER]
                defaultCompilingCommand = configMap[ConfigSerializer.DEFAULT_COMPILING_COMMAND]
                cpp_defaultExeCommand = configMap[ConfigSerializer.CPP_DEFAULT_EXE_COMMAND]
                python_defaultExeCommand = configMap[ConfigSerializer.PYTHON_DEFAULT_EXE_COMMAND]
                boostIncludeFolder = configMap[ConfigSerializer.BOOST_INCLUDE_FOLDER]
                boostLibraryFolder = configMap[ConfigSerializer.BOOST_LIBRARY_FOLDER]                
                visualStudioExe = configMap[ConfigSerializer.VISUAL_STUDIO_EXE] 
                solutionExtensions = configMap[ConfigSerializer.SOLUTION_EXTENSIONS]
                projectExtensions = configMap[ConfigSerializer.PROJECT_EXTENSIONS]
        else:
            #TODO GERVA: Move this code to installer
            defaultLanguage, cpp_defaultRootFolder, python_defaultRootFolder, defaultCompilingCommand, cpp_defaultExeCommand, python_defaultExeCommand, boostIncludeFolder, boostLibraryFolder, visualStudioExe, solutionExtensions, projectExtensions = getDefaultValues()
        
        myConfig = instance()
        myConfig.defaultLanguage = defaultLanguage
        myConfig.cpp_defaultRootFolder = cpp_defaultRootFolder
        myConfig.python_defaultRootFolder = python_defaultRootFolder
        myConfig.defaultCompilingCommand = defaultCompilingCommand
        myConfig.cpp_defaultExeCommand = cpp_defaultExeCommand
        myConfig.python_defaultExeCommand = python_defaultExeCommand
        myConfig.boostIncludeFolder = boostIncludeFolder
        myConfig.boostLibraryFolder = boostLibraryFolder        
        myConfig.visualStudioExe = visualStudioExe
        myConfig.solutionExtensions = solutionExtensions
        myConfig.projectExtensions = projectExtensions