def generateCmake(buildType="Release", cmakeToolchainFile="FrameworkInternals" + os.path.sep + "default_configuration.cmake"): """Generates CMake header lists in various directories, and then calls cmake. Keyword arguments: buildType -- Optional parameter to specify Debug or Release build. If it is not specified it will default to Release. """ transformDesignVerbose("AddressSpace" + os.path.sep + "designToGeneratedCmakeAddressSpace.xslt", "AddressSpace" + os.path.sep + "cmake_generated.cmake", 0, 0) transformDesignVerbose("Device" + os.path.sep + "designToGeneratedCmakeDevice.xslt", "Device" + os.path.sep + "generated" + os.path.sep + "cmake_header.cmake", 0, 0) print("Build type ["+buildType+"], Toolchain file [" + cmakeToolchainFile + "]") print("Calling CMake") if platform.system() == "Windows": subprocessWithImprovedErrors([getCommand("cmake"), "-DCMAKE_BUILD_TYPE=" + buildType, "-DCMAKE_TOOLCHAIN_FILE=" + cmakeToolchainFile, "-G", "Visual Studio 12 Win64", "."], getCommand("cmake")) elif platform.system() == "Linux": subprocessWithImprovedErrors([getCommand("cmake"), "-DCMAKE_BUILD_TYPE=" + buildType, "-DCMAKE_TOOLCHAIN_FILE=" + cmakeToolchainFile, "."], getCommand("cmake"))
def generateSourceVariables(): """Generates the files SourceVariables.h and SourceVariables.cpp. This method is called automatically by cmake, it does not need to be called by the user.""" output = "include/SourceVariables.h" returnCode = transformDesignVerbose(asPath + "designToSourceVariablesHeader.xslt", asPath + output, 0, 1) output = "src/SourceVariables.cpp" returnCode = transformDesignVerbose(asPath + "designToSourceVariablesBody.xslt", asPath + output,0, 1) return 0
def generateRoot(): """Generates the files DRoot.h and DRoot.cpp. This method is called automatically by cmake, it does not need to be called by the user.""" output = "include" + os.path.sep + "DRoot.h" returnCode = transformDesignVerbose(devicePath + "designToRootHeader.xslt", devicePath + output, 0, 1) output = "src" + os.path.sep + "DRoot.cpp" returnCode = transformDesignVerbose(devicePath + "designToRootBody.xslt", devicePath + output,0, 1) return 0
def generateInformationModel(): """Generates the files ASInformationModel.h and ASInformationModel.cpp. This method is called automatically by cmake, it does not need to be called by the user.""" output = "include/ASInformationModel.h" transformDesignVerbose(asPath + "designToInformationModelHeader.xslt", asPath + output, 0, 1) output = "src/ASInformationModel.cpp" transformDesignVerbose(asPath + "designToInformationModelBody.xslt", asPath + output,0, 1)
def generateBaseClass(classname): """Generates the files Base_D<classname>.h and Base_D<classname>.cpp. This method is called automatically by cmake, it does not need to be called by the user. Keyword arguments: classname -- the name of the device, which this class will be associated to. """ output = "generated/Base_D" + classname + ".h" transformDesignVerbose(devicePath + "designToDeviceBaseHeader.xslt", devicePath + output, 0, 1, "className=" + classname) output = "generated/Base_D" + classname + ".cpp" transformDesignVerbose(devicePath + "designToDeviceBaseBody.xslt", devicePath + output, 0, 1,"className=" + classname)
def generateASClass(classname): """Generates the files AS<classname>.h and AS<classname>.cpp. This method is called automatically by cmake, it does not need to be called by the user. Keyword arguments: classname -- the name of the device, which this class will be associated to. """ output = "include/AS" + classname + ".h" transformDesignVerbose(asPath + "designToClassHeader.xslt", asPath + output, 0, 1, "className=" + classname) output = "src/AS" + classname + ".cpp" transformDesignVerbose(asPath + "designToClassBody.xslt", asPath + output, 0, 1,"className=" + classname)
def generateASClass(projectBinaryDir, classname): """Generates the files AS<classname>.h and AS<classname>.cpp. This method is called automatically by cmake, it does not need to be called by the user. Keyword arguments: classname -- the name of the device, which this class will be associated to. """ output = os.path.join(projectBinaryDir, "AddressSpace", "include", "AS{0}.h".format(classname)) transformDesignVerbose(asPath + "designToClassHeader.xslt", output, 0, astyleRun=True, additionalParam="className=" + classname) output = os.path.join(projectBinaryDir, "AddressSpace", "src", "AS{0}.cpp".format(classname)) transformDesignVerbose(asPath + "designToClassBody.xslt", output, 0, astyleRun=True, additionalParam="className=" + classname)
def generateAllDevices(): """Generates the files D<classname>.h and D<classname>.cpp for ALL the different devices. This method needs to be called by the user, as this is the class where the device logic is, so a manual merge will be needed. """ project_directory = os.getcwd() classes = get_list_classes(project_directory+os.path.sep+"Design"+os.path.sep+"Design.xml") for classname in classes: output = "include/D" + classname + ".h" returnCode = transformDesignVerbose(devicePath + "designToDeviceHeader.xslt", devicePath + output, 1, 1, "className=" + classname) output = "src/D" + classname + ".cpp" returnCode = transformDesignVerbose(devicePath + "designToDeviceBody.xslt", devicePath + output, 1, 1,"className=" + classname) return 0
def generateAllDevices(): """Generates the files D<classname>.h and D<classname>.cpp for ALL the different devices. This method needs to be called by the user, as this is the class where the device logic is, so a manual merge will be needed. """ project_directory = os.getcwd() classes = get_list_classes(project_directory+os.path.sep+"Design"+os.path.sep+"Design.xml") for tuple in classes: classname = tuple['name'] output = "include/D" + classname + ".h" transformDesignVerbose(devicePath + "designToDeviceHeader.xslt", devicePath + output, 1, 1, "className=" + classname) output = "src/D" + classname + ".cpp" transformDesignVerbose(devicePath + "designToDeviceBody.xslt", devicePath + output, 1, 1,"className=" + classname)
def createDiagram(detailLevel=0): """Creates an UML diagram based on the classes of the server. Keyword arguments: detailLevel -- Detail level of the diagram. If it is not present, 0 will be assumed """ if detailLevel == "": detailLevel = 0 output = "Design.dot" transformDesignVerbose(designPath + "designToDot.xslt", designPath + output, 0, 1, "detailLevel=" + str(detailLevel)) print("Generating pdf diagram with dot.") subprocessWithImprovedErrors([getCommand("graphviz"), "-Tpdf", "-o", designPath + "diagram.pdf", designPath + "Design.dot"], "GraphViz (dot)")
def generateRoot(projectBinaryDir): """Generates the files DRoot.h and DRoot.cpp. This method is called automatically by cmake, it does not need to be called by the user.""" output = os.path.join(projectBinaryDir, devicePath, "include", "DRoot.h") transformDesignVerbose(devicePath + "designToRootHeader.xslt", output, 0, astyleRun=True) output = os.path.join(projectBinaryDir, devicePath, "src", "DRoot.cpp") transformDesignVerbose(devicePath + "designToRootBody.xslt", output, 0, astyleRun=True)
def validateDesign(): """Checks design.xml against Design.xsd, and after that performs some additional checks (defined in designValidation.xslt)""" # 1st line of validation -- does it matches its schema? # This allows some basic checks print("1st line of check -- XSD conformance") print("Validating the file " + designXML + " with the schema " + designXSD) try: subprocessWithImprovedErrors([getCommand("xmllint"), "--noout", "--schema", designPath + designXSD, designPath + designXML], getCommand("xmllint")) # 2nd line of validation -- including XSLT print("2nd line of check -- more advanced checks using XSLT processor") output = "validationOutput.removeme" transformDesignVerbose(designPath + "designValidation.xslt", designPath + output, 0, 0) except Exception, e: raise Exception ("There was a problem validating the file [" + designXML + "]; Exception: [" + str(e) + "]")
def validateDesign(projectBinaryDir): """Checks design.xml against Design.xsd, and after that performs some additional checks (defined in designValidation.xslt)""" # 1st line of validation -- does it matches its schema? # This allows some basic checks print("1st line of check -- XSD conformance") print("Validating the file " + designXML + " with the schema " + designXSD) try: subprocessWithImprovedErrors([getCommand("xmllint"), "--noout", "--schema", designPath + designXSD, designPath + designXML], getCommand("xmllint")) # 2nd line of validation -- including XSLT print("2nd line of check -- more advanced checks using XSLT processor") output = "validationOutput.removeme" transformDesignVerbose(designPath + "designValidation.xslt", os.path.join(projectBinaryDir, "Design", output), 0, astyleRun=False) except Exception, e: raise Exception ("There was a problem validating the file [" + designXML + "]; Exception: [" + str(e) + "]")
def upgradeDesign(additionalParam): """Method for adjusting Design.xml for a new Design.xsd when updating to a new version of the Framework""" if "quasarGUI.py" in __main__.__file__: print("Calling: python quasar.py upgrade_design") print("Formatting your design file ...") returnCode = formatDesign() if returnCode != 0: print("There was a problem generating " + output + "; Return code = " + str(returnCode)) return returnCode output = "Design.xml.upgraded" returnCode = transformDesignVerbose(designPath + "designToUpgradedDesign.xslt", designPath + output, 0, 0, additionalParam) print("Formatting the upgraded file ") formatedOutput = output + ".formatted" if platform.system() == "Windows": returnCode = subprocess.call("xmllint " + designPath + output + " > " + designPath + formatedOutput, shell=True) elif platform.system() == "Linux": returnCode = subprocess.call("xmllint --format " + designPath + output + " > " + designPath + formatedOutput, shell=True) if returnCode != 0: print("There was a problem formatting the upgraded file; Return code = " + str(returnCode)) return returnCode print("Now running merge-tool. Please merge the upgraded changed") returnCode = subprocess.call("kdiff3 -o " + designPath + designXML + " " + designPath + designXML + " " + designPath + formatedOutput, shell=True) if returnCode != 0: print("There was a problem with kdiff3; Return code = " + str(returnCode)) return returnCode return 0
def generateConfiguration(): """Generates the file Configuration.xsd. This method is called automatically by cmake, it does not need to be called by the user.""" outputFile = os.path.join('Configuration', 'Configuration.xsd') cleanedOutputFile = os.path.join('Configuration', 'Configuration.xsd.new') transformationFile = os.path.join(configPath, "designToConfigurationXSD.xslt") #output = "Configuration.xsd" transformDesignVerbose(transformationFile, outputFile, 0, 0) print("Calling xmllint to modify " + outputFile) #this call is not using subprocess with improved errors because of the need of the piping. subprocessWithImprovedErrorsPipeOutputToFile( [getCommand("xmllint"), "--xinclude", outputFile], cleanedOutputFile, getCommand("xmllint")) print("Copying the modified file " + cleanedOutputFile + " into the name of " + outputFile) shutil.copyfile(cleanedOutputFile, outputFile)
def upgradeDesign(additionalParam): """Method for adjusting Design.xml for a new Design.xsd when updating to a new version of the Framework""" print("Formatting your design file ...") formatDesign() output = "Design.xml.upgraded" transformDesignVerbose(designPath + "designToUpgradedDesign.xslt", designPath + output, 0, astyleRun=False, additionalParam=additionalParam) print("Formatting the upgraded file ") formatedOutput = output + ".formatted" if platform.system() == "Windows": subprocessWithImprovedErrorsPipeOutputToFile([getCommand("xmllint"), designPath + output], designPath + formatedOutput, getCommand("xmllint")) elif platform.system() == "Linux": subprocessWithImprovedErrorsPipeOutputToFile([getCommand("xmllint"), "--format", designPath + output], designPath + formatedOutput, getCommand("xmllint")) print("Now running merge-tool. Please merge the upgraded changed") subprocessWithImprovedErrors([getCommand("diff"), "-o", designPath + designXML, designPath + designXML, designPath + formatedOutput], getCommand("diff"))
def upgradeDesign(additionalParam): """Method for adjusting Design.xml for a new Design.xsd when updating to a new version of the Framework""" print("Formatting your design file ...") formatDesign() output = "Design.xml.upgraded" transformDesignVerbose(designPath + "designToUpgradedDesign.xslt", designPath + output, 0, 0, additionalParam) print("Formatting the upgraded file ") formatedOutput = output + ".formatted" if platform.system() == "Windows": subprocessWithImprovedErrorsPipeOutputToFile([getCommand("xmllint"), designPath + output], designPath + formatedOutput, getCommand("xmllint")) elif platform.system() == "Linux": subprocessWithImprovedErrorsPipeOutputToFile([getCommand("xmllint"), "--format", designPath + output], designPath + formatedOutput, getCommand("xmllint")) print("Now running merge-tool. Please merge the upgraded changed") subprocessWithImprovedErrors([getCommand("diff"), "-o", designPath + designXML, designPath + designXML, designPath + formatedOutput], getCommand("diff"))
def createDiagram(detailLevel=0): """Creates an UML diagram based on the classes of the server. Keyword arguments: detailLevel -- Detail level of the diagram. If it is not present, 0 will be assumed """ if detailLevel == "": detailLevel = 0 output = "Design.dot" transformDesignVerbose(designPath + "designToDot.xslt", designPath + output, 0, 1, "detailLevel=" + str(detailLevel)) print("Generating pdf diagram with dot.") subprocessWithImprovedErrors([ getCommand("graphviz"), "-Tpdf", "-o", designPath + "diagram.pdf", designPath + "Design.dot" ], "GraphViz (dot)")
def generateHonkyTonk(): """Generates honkyTonky.cc, a special class intended for testing your namespace with simulated (random) values.""" extraPath = "Extra" + os.path.sep output = "honkyTonky.cc" returnCode = transformDesignVerbose(extraPath + "designToHonkyTonk.xslt", extraPath + output, 0, 1) if returnCode == 0 : print("Properly generated.") return returnCode
def generateDeviceClass(*classList): """Generates the files D<classname>.h and D<classname>.cpp. This method needs to be called by the user, as this is the class where the device logic is, so a manual merge will be needed. Keyword arguments: classname -- the name of the device, which this class will be associated to. You can specify several classes (up to 10), separated by spaces or just --all to regenerate all device classes. """ if(len(classList) == 0): print("Please, provide the name of the class you wish to generate") return if classList[0] == '--all': return generateAllDevices() classList = [x for x in classList if x is not None]#Remove nones from the list for c in classList:#generate all the specified device classes output = "include/D" + c + ".h" transformDesignVerbose(devicePath + "designToDeviceHeader.xslt", devicePath + output, 1, 1, "className=" + c) output = "src/D" + c + ".cpp" transformDesignVerbose(devicePath + "designToDeviceBody.xslt", devicePath + output, 1, 1,"className=" + c)
def generateDeviceClass(classname1, classname2=None, classname3=None, classname4=None, classname5=None, classname6=None, classname7=None, classname8=None, classname9=None, classname10=None): """Generates the files D<classname>.h and D<classname>.cpp. This method needs to be called by the user, as this is the class where the device logic is, so a manual merge will be needed. Keyword arguments: classname -- the name of the device, which this class will be associated to. You can specify several classes (up to 10), separated by spaces or just --all to regenerate all device classes. """ if "quasarGUI.py" in __main__.__file__: print("Calling: python quasar.py generate device " + classname1) if classname1 == '--all': return generateAllDevices() classList = [classname1, classname2, classname3, classname4, classname5, classname6, classname7, classname8, classname9, classname10] classList = [x for x in classList if x is not None]#Remove nones from the list for c in classList:#generate all the specified device classes output = "include/D" + c + ".h" returnCode = transformDesignVerbose(devicePath + "designToDeviceHeader.xslt", devicePath + output, 1, 1, "className=" + c) output = "src/D" + c + ".cpp" returnCode = transformDesignVerbose(devicePath + "designToDeviceBody.xslt", devicePath + output, 1, 1,"className=" + c) return 0
def generateBaseClass(projectBinaryDir, classname): """Generates the files Base_D<classname>.h and Base_D<classname>.cpp. This method is called automatically by cmake, it does not need to be called by the user. Keyword arguments: classname -- the name of the device, which this class will be associated to. """ output = os.path.join(projectBinaryDir, devicePath, "generated", "Base_D{0}.h".format(classname)) transformDesignVerbose(devicePath + "designToDeviceBaseHeader.xslt", output, 0, astyleRun=True, additionalParam="className=" + classname) output = os.path.join(projectBinaryDir, devicePath, "generated", "Base_D{0}.cpp".format(classname)) transformDesignVerbose(devicePath + "designToDeviceBaseBody.xslt", output, 0, astyleRun=True, additionalParam="className=" + classname)
def generateCmake(projectSourceDir, projectBinaryDir,buildType="Release"): """Generates CMake header lists in various directories, and then calls cmake. Keyword arguments: buildType -- Optional parameter to specify Debug or Release build. If it is not specified it will default to Release. """ transformDesignVerbose( os.path.join("AddressSpace", "designToGeneratedCmakeAddressSpace.xslt"), os.path.join("AddressSpace", "cmake_generated.cmake"), 0, astyleRun=False, additionalParam="projectBinaryDir={0}".format(projectBinaryDir )) transformDesignVerbose( os.path.join("Device", "designToGeneratedCmakeDevice.xslt"), os.path.join("Device", "generated", "cmake_header.cmake"), 0, astyleRun=False, additionalParam="projectBinaryDir={0}".format(projectBinaryDir )) print("Build type ["+buildType+"]") if not os.path.isdir(projectBinaryDir): print("PROJECT_BINARY_DIR {0} doesn't exist -- creating it.".format(projectBinaryDir)) os.mkdir(projectBinaryDir) os.chdir(projectBinaryDir) print("Calling CMake") if platform.system() == "Windows": subprocessWithImprovedErrors([getCommand("cmake"), "-DCMAKE_BUILD_TYPE=" + buildType, "-G", "Visual Studio 12 Win64", projectSourceDir], getCommand("cmake")) elif platform.system() == "Linux": subprocessWithImprovedErrors([getCommand("cmake"), "-DCMAKE_BUILD_TYPE=" + buildType, projectSourceDir], getCommand("cmake"))
def generateConfiguration(projectBinaryDir): """Generates the file Configuration.xsd. This method is called automatically by cmake, it does not need to be called by the user.""" outputFile = os.path.join(projectBinaryDir, 'Configuration', 'Configuration.xsd') cleanedOutputFile = os.path.join(projectBinaryDir, 'Configuration', 'Configuration.xsd.new') transformationFile = os.path.join(configPath, "designToConfigurationXSD.xslt") transformDesignVerbose(transformationFile, outputFile, 0, astyleRun=False, additionalParam="metaXsdPath={0}".format( os.path.join(os.getcwd(), "Meta", "config", "Meta.xsd"))) print("Calling xmllint to modify " + outputFile) #this call is not using subprocess with improved errors because of the need of the piping. subprocessWithImprovedErrorsPipeOutputToFile( [getCommand("xmllint"), "--xinclude", outputFile], cleanedOutputFile, getCommand("xmllint")) print("Copying the modified file " + cleanedOutputFile + " into the name of " + outputFile) shutil.copyfile(cleanedOutputFile, outputFile)
def generateConfiguration(): """Generates the file Configuration.xsd. This method is called automatically by cmake, it does not need to be called by the user.""" output = "Configuration.xsd" returnCode = transformDesignVerbose(configPath + "designToConfigurationXSD.xslt", configPath + output, 0, 0) print("Calling xmllint to modify " + output) returnCode = subprocess.call("xmllint --xinclude " + configPath + output + " > " + configPath + output + ".new", shell=True) if returnCode != 0: print("ERROR: There was an problem executing xmllint") return returnCode else: print("Coping the modified file " + output + ".new into the name of " + output) shutil.copyfile(configPath + output + ".new", configPath + output) return 0 print("ERROR: Unknown platform") return -1
def validateDesign(): """Checks design.xml against Design.xsd, and after that performs some additional checks (defined in designValidation.xslt)""" if "quasarGUI.py" in __main__.__file__: print("Calling: python quasar.py validate_design") # 1st line of validation -- does it matches its schema? # This allows some basic checks print("1st line of check -- XSD conformance") print("Validating the file " + designXML + " with the schema " + designXSD) returnCode = subprocess.call("xmllint --noout --schema " + designPath + designXSD + " " + designPath + designXML, shell=True) if returnCode != 0: print("There was a problem validating the file" + designXML + " with the schema " + designXSD + "; Return code = " + str(returnCode)) return returnCode # 2nd line of validation -- including XSLT print("2nd line of check -- more advanced checks using XSLT processor") output = "validationOutput.removeme" returnCode = transformDesignVerbose(designPath + "designValidation.xslt", designPath + output, 0, 0) return 0
def createDiagram(detailLevel=0): """Creates an UML diagram based on the classes of the server. Keyword arguments: detailLevel -- Detail level of the diagram. If it is not present, 0 will be assumed """ if "quasarGUI.py" in __main__.__file__: print("Calling: python quasar.py generate diagram") if detailLevel == "": detailLevel = 0 output = "Design.dot" returnCode = transformDesignVerbose(designPath + "designToDot.xslt", designPath + output, 0, 1, "detailLevel=" + str(detailLevel)) print("Generating pdf diagram with dot.") returnCode = subprocess.call("dot -Tpdf -o" + designPath + "diagram.pdf " + designPath + "Design.dot", shell=True) if returnCode != 0: print("There was a problem generating pdf diagram with dot; Return code = " + str(returnCode)) return returnCode return 0
def generateSourceVariables(): """Generates the files SourceVariables.h and SourceVariables.cpp. This method is called automatically by cmake, it does not need to be called by the user.""" output = "include/SourceVariables.h" transformDesignVerbose(asPath + "designToSourceVariablesHeader.xslt", asPath + output, 0, 1) output = "src/SourceVariables.cpp" transformDesignVerbose(asPath + "designToSourceVariablesBody.xslt", asPath + output,0, 1)
def generateRoot(): """Generates the files DRoot.h and DRoot.cpp. This method is called automatically by cmake, it does not need to be called by the user.""" output = "include" + os.path.sep + "DRoot.h" transformDesignVerbose(devicePath + "designToRootHeader.xslt", devicePath + output, 0, 1) output = "src" + os.path.sep + "DRoot.cpp" transformDesignVerbose(devicePath + "designToRootBody.xslt", devicePath + output,0, 1)
def generateConfigValidator(): """Generates the file ConfigValidator.xsd. This method is called automatically by cmake, it does not need to be called by the user.""" output = "ConfigValidator.cpp" transformDesignVerbose(configPath + "designToConfigValidator.xslt", configPath + output, 0, 1)
def generateConfigValidator(): """Generates the file ConfigValidator.xsd. This method is called automatically by cmake, it does not need to be called by the user.""" output = "ConfigValidator.cpp" returnCode = transformDesignVerbose(configPath + "designToConfigValidator.xslt", configPath + output, 0, 1) return 0
def generateHonkyTonk(): """Generates honkyTonky.cc, a special class intended for testing your namespace with simulated (random) values.""" extraPath = "Extra" + os.path.sep output = "honkyTonky.cc" transformDesignVerbose(extraPath + "designToHonkyTonk.xslt", extraPath + output, 0, 1) print("Properly generated.")
def generateSourceVariables(projectBinaryDir): """Generates the files SourceVariables.h and SourceVariables.cpp. This method is called automatically by cmake, it does not need to be called by the user.""" output = os.path.join(projectBinaryDir, "AddressSpace", "include", "SourceVariables.h") transformDesignVerbose(asPath + "designToSourceVariablesHeader.xslt", output, 0, astyleRun=True) output = os.path.join(projectBinaryDir, "AddressSpace", "src", "SourceVariables.cpp") transformDesignVerbose(asPath + "designToSourceVariablesBody.xslt", output,0, astyleRun=True)