Example #1
0
    def serialize(self,
                  document,
                  indent=False,
                  encoding=bridge.ENCODING,
                  prefixes=None,
                  omit_declaration=False):
        doc = XmlDocument()
        doc.LoadXml(self.__start_document(document))
        if document.xml_text:
            doc.DocumentElement.AppendChild(
                doc.CreateTextNode(document.xml_text))
        self.__serialize_element(doc, doc.DocumentElement, document)

        settings = XmlWriterSettings()
        settings.Indent = indent
        settings.Encoding = Encoding.GetEncoding(encoding)
        settings.OmitXmlDeclaration = omit_declaration

        ms = MemoryStream()
        xw = XmlWriter.Create(ms, settings)
        doc.Save(xw)
        sr = StreamReader(ms)
        ms.Seek(0, SeekOrigin.Begin)
        content = sr.ReadToEnd()
        ms.Close()

        return content
Example #2
0
def FWConfigureManifest():
    """
    Configures python manifest file according to the current version of 
    FieldWorks.
    Returns True if FlexTools needs to be restarted (necessary if
    the manifest file has been changed)
    """
    # Nov2014:
    # There are different versions of python32.exe.manifest for different versions of FieldWorks
    # FW 7: this one is stable and distributed in the PythonXX.NET\FW7 directories
    # FW 8.0: distributed in the PythonXX.NET\FW8 directories
    # FW 8.1: reference FwKernel.X.manifest from a created python32.exe.manifest
    #         so we can pick up updates automatically.

    restartRequired = False

    FwKernelManifestName = "FwKernel.X.manifest"
    Python32ManifestName = "python32.exe.manifest"
    # For FW 8.1+
    FwKernelManifestPath = os.path.join(FWCodeDir, FwKernelManifestName)
    if os.access(FwKernelManifestPath, os.F_OK):        # Doesn't exist in FW 7
        # FwKernel.X.manifest will have been copied by FWConfigureDLLs()

        # Find version number of FwKernel.X.manifest
        FwKernelXML = XmlDocument()
        FwKernelXML.Load(FwKernelManifestPath)

        # <assemblyIdentity name="FwKernel.X" version="8.1.2.41947" type="win32" />
        FwKernelVersion = FwKernelXML.DocumentElement.FirstChild.GetAttribute("version")

        Python32ManifestXML = XmlDocument()
        Python32ManifestXML.LoadXml(Python32Manifest)

        Python32ManifestXML.DocumentElement.LastChild.FirstChild.FirstChild.SetAttribute("version", FwKernelVersion)
        # print Python32ManifestXML.DocumentElement.LastChild.FirstChild.FirstChild.GetAttribute("version")

        py_net_folders = glob.glob("..\Python*.NET\FW%s" % FWMajorVersion)

        # Compare with version number in each python32.exe.manifest
        for folder in py_net_folders:
            manifestFilename = os.path.join(folder, Python32ManifestName)
            ToCheckXML = XmlDocument()
            ToCheckXML.Load(manifestFilename)

            try:
                ver = ToCheckXML.DocumentElement.LastChild.FirstChild.FirstChild.GetAttribute("version")
            except AttributeError:
                # Arrives here with the default python32.exe.manifest for earlier versions of FW.
                ver = ""

            # If different then write a new python32.exe.manifest, and force restart
            if ver <> FwKernelVersion:
                restartRequired = True
                Python32ManifestXML.Save(manifestFilename)  # Overwrite the manifest
                print "Startup: Manifest updated:", manifestFilename

    return restartRequired
Example #3
0
    def SaveSettings(self):
        import clr
        clr.AddReference("System.Xml")
        from System.Xml import XmlDocument
        import nt

        xmldoc = XmlDocument()
        try:
            xmldoc.Load(nt.getcwd() + "\load.xml")
        except:
            print "Error reading load.xml"
            return

        nodelist = xmldoc.GetElementsByTagName("Cache")
        a = xmldoc.CreateAttribute("allow")
        if self.checkCache.Checked is True:
            a.Value = "true"
        else:
            a.Value = "false"
        nodelist.Item(0).Attributes.Append(a)

        nodelist = xmldoc.GetElementsByTagName("TopLeftPreviewTile")
        a = xmldoc.CreateAttribute("x")
        a.Value = str(self.previewTile[0][0].tile[0])
        nodelist.Item(0).Attributes.Append(a)
        a = xmldoc.CreateAttribute("y")
        a.Value = str(self.previewTile[0][0].tile[1])
        nodelist.Item(0).Attributes.Append(a)
        a = xmldoc.CreateAttribute("dimension")
        if self.radio3x3.Checked is True:
            a.Value = "3"
        else:
            a.Value = "4"
        nodelist.Item(0).Attributes.Append(a)
        a = xmldoc.CreateAttribute("level")
        a.Value = str(self.scrollZoom.Value)
        nodelist.Item(0).Attributes.Append(a)

        try:
            xmldoc.Save(nt.getcwd() + "\load.xml")
        except:
            print "Error writing load.xml"
Example #4
0
    def SaveCurrentGame(self, caption):
        import clr
        clr.AddReference("System.Xml")
        from System.Xml import *
        import nt

        xmldoc = XmlDocument()
        try:
            xmldoc.Load(nt.getcwd() + "\load.xml")
        except:
            print "Error reading load.xml"
            return

        nodeSavedGames = xmldoc.GetElementsByTagName("SavedGames")
        nodeNewGame = xmldoc.CreateElement("Game")
        a = xmldoc.CreateAttribute("caption")
        a.Value = caption
        nodeNewGame.Attributes.Append(a)
        a = xmldoc.CreateAttribute("type")
        a.Value = self.currentGameState[0]
        nodeNewGame.Attributes.Append(a)
        a = xmldoc.CreateAttribute("x")
        a.Value = str(self.currentGameState[1])
        nodeNewGame.Attributes.Append(a)
        a = xmldoc.CreateAttribute("y")
        a.Value = str(self.currentGameState[2])
        nodeNewGame.Attributes.Append(a)
        a = xmldoc.CreateAttribute("level")
        a.Value = str(self.currentGameState[3])
        nodeNewGame.Attributes.Append(a)
        a = xmldoc.CreateAttribute("dimension")
        a.Value = str(self.currentGameState[4])
        nodeNewGame.Attributes.Append(a)
        nodeSavedGames[0].AppendChild(nodeNewGame)

        try:
            xmldoc.Save(nt.getcwd() + "\load.xml")
        except:
            print "Error writing load.xml"
def save_last_used(file_path, lastused):
    "Saves the lastused profiles to the xml file."""
    x = XmlDocument()
    x.Load(file_path)
    x.DocumentElement.SetAttribute("LastUsed", ",".join(lastused))
    x.Save(file_path)