コード例 #1
0
ファイル: winmanifest.py プロジェクト: vt0r/Nagstamon
 def todom(self):
     """ Return the manifest as DOM tree """
     doc = Document()
     docE = doc.cE(self.manifestType)
     if self.manifestType == "assemblyBinding":
         cfg = doc.cE("configuration")
         win = doc.cE("windows")
         win.aChild(docE)
         cfg.aChild(win)
         doc.aChild(cfg)
     else:
         doc.aChild(docE)
     if self.manifestType != "dependentAssembly":
         docE.setA("xmlns", "urn:schemas-microsoft-com:asm.v1")
         if self.manifestType != "assemblyBinding":
             docE.setA("manifestVersion", ".".join([str(i) for i in self.manifestVersion]))
     if self.noInheritable:
         docE.aChild(doc.cE("noInheritable"))
     if self.noInherit:
         docE.aChild(doc.cE("noInherit"))
     aId = doc.cE("assemblyIdentity")
     if self.type:
         aId.setAttribute("type", self.type)
     if self.name:
         aId.setAttribute("name", self.name)
     if self.language:
         aId.setAttribute("language", self.language)
     if self.processorArchitecture:
         aId.setAttribute("processorArchitecture", self.processorArchitecture)
     if self.version:
         aId.setAttribute("version", ".".join([str(i) for i in self.version]))
     if self.publicKeyToken:
         aId.setAttribute("publicKeyToken", self.publicKeyToken)
     if aId.hasAttributes():
         docE.aChild(aId)
     else:
         aId.unlink()
     if self.applyPublisherPolicy != None:
         ppE = doc.cE("publisherPolicy")
         if self.applyPublisherPolicy:
             ppE.setA("apply", "yes")
         else:
             ppE.setA("apply", "no")
         docE.aChild(ppE)
     if self.description:
         descE = doc.cE("description")
         descE.aChild(doc.cT(self.description))
         docE.aChild(descE)
     if self.requestedExecutionLevel in ("asInvoker", "highestAvailable", "requireAdministrator"):
         tE = doc.cE("trustInfo")
         tE.setA("xmlns", "urn:schemas-microsoft-com:asm.v3")
         sE = doc.cE("security")
         rpE = doc.cE("requestedPrivileges")
         relE = doc.cE("requestedExecutionLevel")
         relE.setA("level", self.requestedExecutionLevel)
         if self.uiAccess:
             relE.setA("uiAccess", "true")
         else:
             relE.setA("uiAccess", "false")
         rpE.aChild(relE)
         sE.aChild(rpE)
         tE.aChild(sE)
         docE.aChild(tE)
     if self.dependentAssemblies:
         for assembly in self.dependentAssemblies:
             if self.manifestType != "assemblyBinding":
                 dE = doc.cE("dependency")
                 if assembly.optional:
                     dE.setAttribute("optional", "yes")
             daE = doc.cE("dependentAssembly")
             adom = assembly.todom()
             for child in adom.documentElement.childNodes:
                 daE.aChild(child.cloneNode(False))
             adom.unlink()
             if self.manifestType != "assemblyBinding":
                 dE.aChild(daE)
                 docE.aChild(dE)
             else:
                 docE.aChild(daE)
     if self.bindingRedirects:
         for bindingRedirect in self.bindingRedirects:
             brE = doc.cE("bindingRedirect")
             brE.setAttribute(
                 "oldVersion", "-".join([".".join([str(i) for i in part]) for part in bindingRedirect[0]])
             )
             brE.setAttribute("newVersion", ".".join([str(i) for i in bindingRedirect[1]]))
             docE.aChild(brE)
     if self.files:
         for file_ in self.files:
             fE = doc.cE("file")
             for attr in ("name", "hashalg", "hash"):
                 val = getattr(file_, attr)
                 if val:
                     fE.setA(attr, val)
             docE.aChild(fE)
     return doc
コード例 #2
0
    def todom(self):
        """
        Return the manifest as DOM tree.
        """
        doc = Document()
        docE = doc.cE(self.manifestType)
        if self.manifestType == "assemblyBinding":
            cfg = doc.cE("configuration")
            win = doc.cE("windows")
            win.aChild(docE)
            cfg.aChild(win)
            doc.aChild(cfg)
        else:
            doc.aChild(docE)
        if self.manifestType != "dependentAssembly":
            docE.setA("xmlns", "urn:schemas-microsoft-com:asm.v1")
            if self.manifestType != "assemblyBinding":
                docE.setA("manifestVersion",
                          ".".join([str(i) for i in self.manifestVersion]))
        if self.noInheritable:
            docE.aChild(doc.cE("noInheritable"))
        if self.noInherit:
            docE.aChild(doc.cE("noInherit"))
        aId = doc.cE("assemblyIdentity")
        if self.type:
            aId.setAttribute("type", self.type)
        if self.name:
            aId.setAttribute("name", self.name)
        if self.language:
            aId.setAttribute("language", self.language)
        if self.processorArchitecture:
            aId.setAttribute("processorArchitecture",
                             self.processorArchitecture)
        if self.version:
            aId.setAttribute("version",
                             ".".join([str(i) for i in self.version]))
        if self.publicKeyToken:
            aId.setAttribute("publicKeyToken", self.publicKeyToken)
        if aId.hasAttributes():
            docE.aChild(aId)
        else:
            aId.unlink()
        if self.applyPublisherPolicy is not None:
            ppE = doc.cE("publisherPolicy")
            if self.applyPublisherPolicy:
                ppE.setA("apply", "yes")
            else:
                ppE.setA("apply", "no")
            docE.aChild(ppE)
        if self.description:
            descE = doc.cE("description")
            descE.aChild(doc.cT(self.description))
            docE.aChild(descE)
        if self.requestedExecutionLevel in ("asInvoker", "highestAvailable",
                                            "requireAdministrator"):
            tE = doc.cE("trustInfo")
            tE.setA("xmlns", "urn:schemas-microsoft-com:asm.v3")
            sE = doc.cE("security")
            rpE = doc.cE("requestedPrivileges")
            relE = doc.cE("requestedExecutionLevel")
            relE.setA("level", self.requestedExecutionLevel)
            if self.uiAccess:
                relE.setA("uiAccess", "true")
            else:
                relE.setA("uiAccess", "false")
            rpE.aChild(relE)
            sE.aChild(rpE)
            tE.aChild(sE)
            docE.aChild(tE)
        if self.dependentAssemblies:
            for assembly in self.dependentAssemblies:
                if self.manifestType != "assemblyBinding":
                    dE = doc.cE("dependency")
                    if assembly.optional:
                        dE.setAttribute("optional", "yes")
                daE = doc.cE("dependentAssembly")
                adom = assembly.todom()
                for child in adom.documentElement.childNodes:
                    daE.aChild(child.cloneNode(False))
                adom.unlink()
                if self.manifestType != "assemblyBinding":
                    dE.aChild(daE)
                    docE.aChild(dE)
                else:
                    docE.aChild(daE)
        if self.bindingRedirects:
            for bindingRedirect in self.bindingRedirects:
                brE = doc.cE("bindingRedirect")
                brE.setAttribute(
                    "oldVersion", "-".join([
                        ".".join([str(i) for i in part])
                        for part in bindingRedirect[0]
                    ]))
                brE.setAttribute(
                    "newVersion",
                    ".".join([str(i) for i in bindingRedirect[1]]))
                docE.aChild(brE)
        if self.files:
            for file_ in self.files:
                fE = doc.cE("file")
                for attr in ("name", "hashalg", "hash"):
                    val = getattr(file_, attr)
                    if val:
                        fE.setA(attr, val)
                docE.aChild(fE)

        # Add compatibility section: http://stackoverflow.com/a/10158920
        cE = doc.cE("compatibility")
        cE.setAttribute("xmlns", "urn:schemas-microsoft-com:compatibility.v1")
        caE = doc.cE("application")
        supportedOS_guids = {
            "Vista": "{e2011457-1546-43c5-a5fe-008deee3d3f0}",
            "7": "{35138b9a-5d96-4fbd-8e2d-a2440225f93a}",
            "8": "{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}",
            "8.1": "{1f676c76-80e1-4239-95bb-83d0f6d0da78}",
            "10": "{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"
        }
        for guid in supportedOS_guids.values():
            sosE = doc.cE("supportedOS")
            sosE.setAttribute("Id", guid)
            caE.aChild(sosE)
        cE.aChild(caE)
        docE.aChild(cE)

        # Add application.windowsSettings section to enable longPathAware
        # option (issue #5423).
        if self.manifestType == "assembly":
            aE = doc.cE("application")
            aE.setAttribute("xmlns", "urn:schemas-microsoft-com:asm.v3")
            wsE = doc.cE("windowsSettings")
            lpaE = doc.cE("longPathAware")
            lpaE.setAttribute(
                "xmlns",
                "http://schemas.microsoft.com/SMI/2016/WindowsSettings")
            lpaT = doc.cT("true")
            lpaE.aChild(lpaT)
            wsE.aChild(lpaE)
            aE.aChild(wsE)
            docE.aChild(aE)

        return doc
コード例 #3
0
ファイル: winmanifest.py プロジェクト: larseggert/xml2rfc
 def todom(self):
     """ Return the manifest as DOM tree """
     doc = Document()
     docE = doc.cE(self.manifestType)
     if self.manifestType == "assemblyBinding":
         cfg = doc.cE("configuration")
         win = doc.cE("windows")
         win.aChild(docE)
         cfg.aChild(win)
         doc.aChild(cfg)
     else:
         doc.aChild(docE)
     if self.manifestType != "dependentAssembly":
         docE.setA("xmlns", "urn:schemas-microsoft-com:asm.v1")
         if self.manifestType != "assemblyBinding":
             docE.setA("manifestVersion",
                       ".".join([str(i) for i in self.manifestVersion]))
     if self.noInheritable:
         docE.aChild(doc.cE("noInheritable"))
     if self.noInherit:
         docE.aChild(doc.cE("noInherit"))
     aId = doc.cE("assemblyIdentity")
     if self.type:
         aId.setAttribute("type", self.type)
     if self.name:
         aId.setAttribute("name", self.name)
     if self.language:
         aId.setAttribute("language", self.language)
     if self.processorArchitecture:
         aId.setAttribute("processorArchitecture",
                          self.processorArchitecture)
     if self.version:
         aId.setAttribute("version",
                          ".".join([str(i) for i in self.version]))
     if self.publicKeyToken:
         aId.setAttribute("publicKeyToken", self.publicKeyToken)
     if aId.hasAttributes():
         docE.aChild(aId)
     else:
         aId.unlink()
     if self.applyPublisherPolicy != None:
         ppE = doc.cE("publisherPolicy")
         if self.applyPublisherPolicy:
             ppE.setA("apply", "yes")
         else:
             ppE.setA("apply", "no")
         docE.aChild(ppE)
     if self.description:
         descE = doc.cE("description")
         descE.aChild(doc.cT(self.description))
         docE.aChild(descE)
     if self.requestedExecutionLevel in ("asInvoker", "highestAvailable",
                                         "requireAdministrator"):
         tE = doc.cE("trustInfo")
         tE.setA("xmlns", "urn:schemas-microsoft-com:asm.v3")
         sE = doc.cE("security")
         rpE = doc.cE("requestedPrivileges")
         relE = doc.cE("requestedExecutionLevel")
         relE.setA("level", self.requestedExecutionLevel)
         if self.uiAccess:
             relE.setA("uiAccess", "true")
         else:
             relE.setA("uiAccess", "false")
         rpE.aChild(relE)
         sE.aChild(rpE)
         tE.aChild(sE)
         docE.aChild(tE)
     if self.dependentAssemblies:
         for assembly in self.dependentAssemblies:
             if self.manifestType != "assemblyBinding":
                 dE = doc.cE("dependency")
                 if assembly.optional:
                     dE.setAttribute("optional", "yes")
             daE = doc.cE("dependentAssembly")
             adom = assembly.todom()
             for child in adom.documentElement.childNodes:
                 daE.aChild(child.cloneNode(False))
             adom.unlink()
             if self.manifestType != "assemblyBinding":
                 dE.aChild(daE)
                 docE.aChild(dE)
             else:
                 docE.aChild(daE)
     if self.bindingRedirects:
         for bindingRedirect in self.bindingRedirects:
             brE = doc.cE("bindingRedirect")
             brE.setAttribute(
                 "oldVersion", "-".join([
                     ".".join([str(i) for i in part])
                     for part in bindingRedirect[0]
                 ]))
             brE.setAttribute(
                 "newVersion",
                 ".".join([str(i) for i in bindingRedirect[1]]))
             docE.aChild(brE)
     if self.files:
         for file_ in self.files:
             fE = doc.cE("file")
             for attr in ("name", "hashalg", "hash"):
                 val = getattr(file_, attr)
                 if val:
                     fE.setA(attr, val)
             docE.aChild(fE)
     return doc
コード例 #4
0
ファイル: winmanifest.py プロジェクト: Bluehorn/pyinstaller
    def todom(self):
        """ Return the manifest as DOM tree """
        doc = Document()
        docE = doc.cE(self.manifestType)
        if self.manifestType == "assemblyBinding":
            cfg = doc.cE("configuration")
            win = doc.cE("windows")
            win.aChild(docE)
            cfg.aChild(win)
            doc.aChild(cfg)
        else:
            doc.aChild(docE)
        if self.manifestType != "dependentAssembly":
            docE.setA("xmlns", "urn:schemas-microsoft-com:asm.v1")
            if self.manifestType != "assemblyBinding":
                docE.setA("manifestVersion", 
                          ".".join([str(i) for i in self.manifestVersion]))
        if self.noInheritable:
            docE.aChild(doc.cE("noInheritable"))
        if self.noInherit:
            docE.aChild(doc.cE("noInherit"))
        aId = doc.cE("assemblyIdentity")
        if self.type:
            aId.setAttribute("type", self.type)
        if self.name:
            aId.setAttribute("name", self.name)
        if self.language:
            aId.setAttribute("language", self.language)
        if self.processorArchitecture:
            aId.setAttribute("processorArchitecture", 
                             self.processorArchitecture)
        if self.version:
            aId.setAttribute("version", 
                             ".".join([str(i) for i in self.version]))
        if self.publicKeyToken:
            aId.setAttribute("publicKeyToken", self.publicKeyToken)
        if aId.hasAttributes():
            docE.aChild(aId)
        else:
            aId.unlink()
        if self.applyPublisherPolicy != None:
            ppE = doc.cE("publisherPolicy")
            if self.applyPublisherPolicy:
                ppE.setA("apply", "yes")
            else:
                ppE.setA("apply", "no")
            docE.aChild(ppE)
        if self.description:
            descE = doc.cE("description")
            descE.aChild(doc.cT(self.description))
            docE.aChild(descE)
        if self.requestedExecutionLevel in ("asInvoker", "highestAvailable", 
                                            "requireAdministrator"):
            tE = doc.cE("trustInfo")
            tE.setA("xmlns", "urn:schemas-microsoft-com:asm.v3")
            sE = doc.cE("security")
            rpE = doc.cE("requestedPrivileges")
            relE = doc.cE("requestedExecutionLevel")
            relE.setA("level", self.requestedExecutionLevel)
            if self.uiAccess:
                relE.setA("uiAccess", "true")
            else:
                relE.setA("uiAccess", "false")
            rpE.aChild(relE)
            sE.aChild(rpE)
            tE.aChild(sE)
            docE.aChild(tE)
        if self.dependentAssemblies:
            for assembly in self.dependentAssemblies:
                if self.manifestType != "assemblyBinding":
                    dE = doc.cE("dependency")
                    if assembly.optional:
                        dE.setAttribute("optional", "yes")
                daE = doc.cE("dependentAssembly")
                adom = assembly.todom()
                for child in adom.documentElement.childNodes:
                    daE.aChild(child.cloneNode(False))
                adom.unlink()
                if self.manifestType != "assemblyBinding":
                    dE.aChild(daE)
                    docE.aChild(dE)
                else:
                    docE.aChild(daE)
        if self.bindingRedirects:
            for bindingRedirect in self.bindingRedirects:
                brE = doc.cE("bindingRedirect")
                brE.setAttribute("oldVersion", 
                                 "-".join([".".join([str(i) 
                                                     for i in 
                                                     part]) 
                                           for part in 
                                           bindingRedirect[0]]))
                brE.setAttribute("newVersion", 
                                 ".".join([str(i) for i in bindingRedirect[1]]))
                docE.aChild(brE)
        if self.files:
            for file_ in self.files:
                fE = doc.cE("file")
                for attr in ("name", "hashalg", "hash"):
                    val = getattr(file_, attr)
                    if val:
                        fE.setA(attr, val)
                docE.aChild(fE)

        # Add compatibility section: http://stackoverflow.com/a/10158920
        cE = doc.cE("compatibility")
        cE.setAttribute("xmlns", "urn:schemas-microsoft-com:compatibility.v1")
        caE = doc.cE("application")
        supportedOS_guids = {"Vista":"{e2011457-1546-43c5-a5fe-008deee3d3f0}",
                             "7"    :"{35138b9a-5d96-4fbd-8e2d-a2440225f93a}",
                             "8"    :"{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}",
                             "8.1"  :"{1f676c76-80e1-4239-95bb-83d0f6d0da78}",
                             "10"   :"{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"}
        for guid in supportedOS_guids.values():
            sosE = doc.cE("supportedOS")
            sosE.setAttribute("Id", guid)
            caE.aChild(sosE)
        cE.aChild(caE)
        docE.aChild(cE)

        return doc