Ejemplo n.º 1
0
    def generateConfig(self, asyncConfigPath=None, asyncConfigFileName=None):
        outIncludeDir = os.path.join(FileSystem.getDirectory(FileSystem.OUT_ROOT),
                                     "include")
        projectLogDir = FileSystem.getDirectory(FileSystem.LOG_DIR, self._config, self._project_name)
        asyncConfig = None
        if asyncConfigPath is None:
            asyncConfig = os.path.join(FileSystem.getDirectory(FileSystem.CLIENT_CONFIG),
                                       (asyncConfigFileName if asyncConfigFileName is not None else "AsyncConfig.xml"))
        else:
            asyncConfig = asyncConfigPath
        Utilities.mkdir(outIncludeDir)

        configArgs = []

        configArgs.append(['std::string', 'LOGGING_ROOT', 'dir', projectLogDir.replace("\\", "/")])
        if "Robos" in self._project_name:
            configArgs.append(['std::string', 'ASYNC_CONFIG_PATH', 'file', asyncConfig.replace("\\", "/")])

        (formattedConfigArgsHeader, formattedConfigArgsSrc) = self.checkConfigArgsAndFormat("\t", configArgs)

        if os.path.exists(projectLogDir):
            Utilities.rmTree(projectLogDir)
        Utilities.mkdir(projectLogDir)
        projNameUpper = self._project_name.upper()
        with open(os.path.join(outIncludeDir, self._project_name + "Config.hpp"), 'w') as file:
            file.write("#pragma once\n"
                       "#ifndef " + projNameUpper + "_CONFIG_" + projNameUpper + "CONFIG_HPP\n"
                       "#define " + projNameUpper + "_CONFIG_" + projNameUpper + "CONFIG_HPP\n\n"
                       "// SYSTEM INCLUDES\n"
                       "#include <string>\n\n"
                       "// C++ PROJECT INCLUDES\n\n"
                       "namespace " + self._project_name + "\n"
                       "{\n"
                       "namespace Config\n"
                       "{\n\n" +
                       formattedConfigArgsHeader +
                       "} // end of namespace Config\n"
                       "} // end of namespace " + self._project_name + "\n"
                       "#endif // end of " + projNameUpper + "_CONFIG_" + projNameUpper + "CONFIG_HPP\n")
        with open(os.path.join(outIncludeDir, self._project_name + "Config.cpp"), 'w') as file:
            file.write("// SYSTEM INCLUDES\n\n"
                       "// C++ PROJECT INCLUDES\n"
                       "#include \"" + self._project_name + "Config.hpp\"\n\n"
                       "namespace " + self._project_name + "\n"
                       "{\n"
                       "namespace Config\n"
                       "{\n\n" +
                       formattedConfigArgsSrc +
                       "} // end of namespace Config\n"
                       "} // end of namespace " + self._project_name + "\n")
Ejemplo n.º 2
0
    def checkConfigArgsAndFormat(self, offset, configArgs):
        formattedHeader = ""
        formattedSrc = ""
        for arg in configArgs:
            if arg[2] == "dir":
                if os.path.exists(arg[3]):
                    if os.path.isdir(arg[3]):
                        Utilities.rmTree(arg[3])
                    else:
                        Utilities.failExecution("Path [%s] was assumed to be a directory" % arg[3])
                Utilities.mkdir(arg[3])
            elif arg[2] == "file":
                if not os.path.exists(arg[3]) or not os.path.isfile(arg[3]):
                    Utilities.failExecution("Path [%s] does not exist or is not a file" % arg[3])
            elif arg[2] is not None:
                Utilities.failExecution("unknown config variable value specifier [%s]" % arg[2])

            formattedHeader += offset + "extern const " + arg[0] + " " + arg[1] + ";\n\n"
            formattedSrc += offset + "const " + arg[0] + " " + \
                arg[1] + " = " + ("\"" + str(arg[3]) + "\"" if "string" in arg[0] else str(arg[3])) + \
                ";\n\n"

        return formattedHeader, formattedSrc
Ejemplo n.º 3
0
 def cleanBuildWorkspace(self):
     print("Cleaning build directory for project [%s]" % self._project_name)
     buildDirectory = FileSystem.getDirectory(FileSystem.WORKING, self._config, self._project_name)
     if os.path.exists(buildDirectory):
         Utilities.rmTree(buildDirectory)