Example #1
0
def __write_android_config__(file:str, config:dict):
    if config:
        doc = Document()
        doc.encoding = 'utf-8'
        root = doc.createElement('android')
        for androidFile in config.values():
            node = doc.createElement('file')
            node.setAttribute('fileName', androidFile.fileName)
            node.setAttribute('path', androidFile.path)
            if androidFile.progress:
                node.setAttribute('progress', androidFile.progress)
            if androidFile.action:
                node.setAttribute('action', androidFile.action)
            if androidFile.start:
                node.setAttribute('start', androidFile.start)
            if androidFile.clean:
                node.setAttribute('clean', 'yes')
            if androidFile.delayTime:
                node.setAttribute('delayTime', str(androidFile.delayTime))
            root.appendChild(node)
    if not isdir(dirname(file)):
        makedirs(dirname(file))
    with open(file, mode='w', encoding='utf-8') as out:
        out.write(root.toprettyxml(indent='    '))
        out.close()
Example #2
0
def main():
    png_files = [file for file in glob.glob("%s/*/*.png" % SRC_PATH)]
    pending_files = [file for file in png_files if not os.path.exists(file.replace(".png",".swf").replace("Output", "Swf"))]
    if pending_files == []:
        print "没有需要转换的文件!"
        return
    for file in pending_files:
        xmlTree = Document()
        firstNode = xmlTree.createElement("lib")
        xmlTree.appendChild(firstNode)
        firstNode.setAttribute("allowDomain", "*")
        bitmapdata_node = xmlTree.createElement("bitmapdata")
        bitmapdata_node.setAttribute("file", file)
        bitmapdata_node.setAttribute("compression", "true")
        bitmapdata_node.setAttribute("quality", "65")
        bitmapdata_node.setAttribute("class","bmp_%s" % os.path.basename(file)[:-4])
        firstNode.appendChild(bitmapdata_node)
        bytearray_node = xmlTree.createElement("bytearray")
        bytearray_node.setAttribute("file", file.replace(".png", ".tbe"))
        bytearray_node.setAttribute("class", "tbe_%s" % os.path.basename(file)[:-4])
        firstNode.appendChild(bytearray_node)
        xmlTree.encoding = "UTF-8"
        xml_file = os.path.join(LATEST_PATH, os.path.basename(file).replace(".png",".xml"))
        swf_file = xml_file.replace(".xml",".swf")
        with open(xml_file, "w") as f:
            f.write(xmlTree.toprettyxml().decode("gbk").encode("utf-8"))
        os.system("java -jar Swift.jar xml2lib %s %s" % (xml_file, swf_file))
        dest_path = os.path.dirname(file.replace("Output", "Swf"))
        if not os.path.exists(dest_path):
            os.makedirs(dest_path)
        shutil.copy(swf_file, dest_path)
Example #3
0
    def to_xml(self, encoding="UTF-8", pretty=True):
        dom = Document()
        dom.version = "1.0"
        dom.encoding = "UTF-8"
        doc_type = DocumentType("plist")
        doc_type.publicId = "-//Apple Computer//DTD PLIST 1.0//EN"
        doc_type.systemId = "http://www.apple.com/DTDs/PropertyList-1.0.dtd"
        dom.appendChild(doc_type)

        plist_node = dom.createElement("plist")
        plist_node.setAttribute("version", "1.0")
        dom.appendChild(plist_node)

        plist_root = dom.createElement("dict")
        plist_node.appendChild(plist_root)
        temp_pairs = [(self, plist_root)]
        while temp_pairs:
            data, root = temp_pairs.pop(0)
            if isinstance(data, dict):
                for k, v in data.items():
                    k_node = dom.createElement("key")
                    text_node = dom.createTextNode(k)
                    k_node.appendChild(text_node)
                    root.appendChild(k_node)

                    if isinstance(v, dict):
                        v_node = dom.createElement("dict")
                        temp_pairs.append((v, v_node))
                    elif isinstance(v, list):
                        v_node = dom.createElement("array")
                        temp_pairs.append((v, v_node))
                    else:
                        v_node = self._to_dom_node(v, dom)
                    root.appendChild(v_node)
            elif isinstance(data, list):
                for v in data:
                    if isinstance(v, dict):
                        v_node = dom.createElement("dict")
                        temp_pairs.append((v, v_node))
                    elif isinstance(v, list):
                        v_node = dom.createElement("array")
                        temp_pairs.append((v, v_node))
                    else:
                        v_node = self._to_dom_node(v, dom)
                    root.appendChild(v_node)
            else:
                data_node = self._to_dom_node(data, dom)
                root.appendChild(data_node)

        if pretty:
            xml_content = dom.toprettyxml(encoding=encoding)
        else:
            xml_content = dom.toxml(encoding=encoding)
        return xml_content
Example #4
0
def xml_response(response_code, message):
    """
    Returns::

    <response>
        <code>100</code>
        <message>Alles gute.</message>
    </response>
    """
    doc = Document()
    doc.encoding = 'utf-8'
    res = doc.createElement('response')
    doc.appendChild(res)
    code = doc.createElement('code')
    code.appendChild(doc.createTextNode(str(response_code)))
    msg = doc.createElement('message')
    msg.appendChild(doc.createTextNode(message))
    res.appendChild(code)
    res.appendChild(msg)
    return doc.toxml('utf-8')
Example #5
0
File: views.py Project: whit/ella
def xml_response(response_code, message):
    """
    Returns::

    <response>
        <code>100</code>
        <message>Alles gute.</message>
    </response>
    """
    doc = Document()
    doc.encoding = 'utf-8'
    res = doc.createElement('response')
    doc.appendChild(res)
    code = doc.createElement('code')
    code.appendChild(doc.createTextNode(str(response_code)))
    msg = doc.createElement('message')
    msg.appendChild(doc.createTextNode(message))
    res.appendChild(code)
    res.appendChild(msg)
    return doc.toxml('utf-8')
Example #6
0
 def generateProjectXml(self, appname, bld):
     doc = Document()
     doc.encoding = "UTF-8"
     project = add(doc, doc, 'project', {'xmlns': "http://www.netbeans.org/ns/project/1"})
     add(doc, project, 'type', "org.netbeans.modules.cnd.makeproject")
     configuration = add(doc, project, 'configuration')
     data = add(doc, configuration, 'data', {'xmlns': "http://www.netbeans.org/ns/make-project/1"})
     add(doc, data, 'name', appname)
     add(doc, data, 'make-project-type', '1')
     add(doc, data, 'c-extensions', 'c,m')
     add(doc, data, 'cpp-extensions', 'cpp,cc,cxx,mm')
     add(doc, data, 'header-extensions', 'h,hh,hxx,inl')
     add(doc, data, 'sourceEncoding', 'UTF-8')
     add(doc, data, 'make-dep-projects')
     if self.__class__.version >= 70:
         sourceRootList = add(doc, data, 'sourceRootList')
         sourceRoot = add(doc, sourceRootList, 'sourceRootElem', '.')
         confList = add(doc, data, 'confList')
         for t in bld.env.ALL_TOOLCHAINS:
             for v in bld.env.ALL_VARIANTS:
                 elem = add(doc, confList, 'confElem')
                 add(doc, elem, 'name', '%s:%s' % (t, v))
                 add(doc, elem, 'type', '0')
     return doc
Example #7
0
    def generateConfigurationsXml(self, task_gens, bld, out):
        doc = Document()
        doc.encoding = "UTF-8"
        cd = add(doc, doc, 'configurationDescriptor', {'version':'%i'%self.__class__.version})
        lf = add(doc, cd, 'logicalFolder', {'name': 'root', 'displayName': 'root', 'projectFiles': 'true', 'kind': "ROOT"})
        self.subfolders = {}
        options = []
        for task_gen in task_gens:
            options.append(gather_includes_defines(task_gen))
            path = task_gen.target.split('.')
            root_folder = self
            root_folder.xml = lf
            for p in path[:-1]:
                root_folder = self.add_folder(p, doc, root_folder)
            for node in getattr(task_gen, 'source_nodes', []):
                self.add(doc, root_folder, node)

            #f, subs = categories[category]
            #project = project.split('.')
            #for subname in project:
            #	try:
            #		f, subs = subs[subname]
            #	except KeyError:
            #		f = add(doc, f, 'logicalFolder', {'name': subname, 'displayName': subname, 'projectFiles': 'true'})
            #		subs[subname] = (f, {})
            #		f, subs = subs[subname]
            #f.setAttribute('displayName', '['+project[-1]+']')
            #self.addSourceTree(doc, f, source, source.prefix)
        impfiles = add(doc, lf, 'logicalFolder', {'name': 'ExternalFiles', 'displayName': 'waf', 'projectFiles': 'false', 'kind':'IMPORTANT_FILES_FOLDER'})
        add(doc, impfiles, 'itemPath', sys.argv[0])
        #add(doc, cd, 'sourceFolderFilter')
        srl = add(doc, cd, 'sourceRootList')
        #add(doc, srl, 'Elem', '.')
        #add(doc, srl, 'Elem', './build/')
        add(doc, cd, 'projectmakefile', sys.argv[0])
        add(doc, cd, 'sourceFolderFilter', '^.*$')
        confs = add(doc, cd, 'confs')
        for toolchain in bld.env.ALL_TOOLCHAINS:
            bld_env = bld.all_envs[toolchain]
            if bld_env.SUB_TOOLCHAINS:
                env = bld.all_envs[bld_env.SUB_TOOLCHAINS[0]]
            else:
                env = bld_env
            platform_defines = env.SYSTEM_DEFINES
            platform_includes = env.SYSTEM_INCLUDES
            if env.SYSROOT:
                platform_includes += [os.path.join(env.SYSROOT, 'usr', 'include')]
            options.append((platform_includes, platform_defines))

            for variant in bld.env.ALL_VARIANTS:
                conf = add(doc, confs, 'conf', { 'name': '%s:%s'%(toolchain, variant), 'type': '0' })
                toolsSet = add(doc, conf, 'toolsSet')
                if self.__class__.version >= 70:
                    add(doc, toolsSet, 'remote-sources-mode', 'LOCAL_SOURCES')
                else:
                    add(doc, toolsSet, 'developmentServer', 'localhost')
                add(doc, toolsSet, 'compilerSet', 'default')
                if self.__class__.version < 70:
                    add(doc, toolsSet, 'platform', '4')
                mtype = add(doc, conf, 'makefileType')
                mtool = add(doc, mtype, 'makeTool')
                add(doc, mtool, 'buildCommandWorkingDir', '.')
                add(doc, mtool, 'buildCommand', '%s %s build:%s:%s'%(sys.executable, sys.argv[0], toolchain, variant))
                add(doc, mtool, 'cleanCommand', '%s %s clean:%s:%s'%(sys.executable, sys.argv[0], toolchain, variant))
                if env.ABI == 'mach_o':
                    add(doc, mtool, 'executablePath', os.path.join(bld_env.PREFIX, variant, getattr(Context.g_module, 'APPNAME', 'noname')+'.app'))
                else:
                    add(doc, mtool, 'executablePath', os.path.join(bld_env.PREFIX, variant, env.DEPLOY_BINDIR, env.cxxprogram_PATTERN%out.target))
                if self.__class__.version >= 70:
                    ctool = add(doc, mtool, 'cTool')
                    cincdir = add(doc, ctool, 'incDir')
                    cdefines = add(doc, ctool, 'preprocessorList')
                    cctool = add(doc, mtool, 'ccTool')
                    ccincdir = add(doc, cctool, 'incDir')
                    ccdefines = add(doc, cctool, 'preprocessorList')
                else:
                    ctool = add(doc, mtool, 'cCompilerTool')
                    cincdir = add(doc, ctool, 'includeDirectories')
                    cdefines = add(doc, ctool, 'preprocessorList')
                    cctool = add(doc, mtool, 'ccCompilerTool')
                    ccincdir = add(doc, cctool, 'includeDirectories')
                    ccdefines = add(doc, cctool, 'preprocessorList')
                add(doc, mtype, 'requiredProjects')
                includes=set([])
                defines = set([])
                for d in ['be_api(x)=', 'BE_EXPORT='] + env.DEFINES:
                    add(doc, cdefines, 'Elem', d)
                    add(doc, ccdefines, 'Elem', d)
                for tg_includes, tg_defines in options:
                    for i in tg_includes:
                        i = relpath(i, bld.srcnode)
                        if i not in includes:
                            includes.add(i)
                            add(doc, cincdir, 'directoryPath', i)
                            add(doc, ccincdir, 'directoryPath', i)
                    for d in tg_defines:
                        if d not in tg_defines:
                            defines.add(d)
                            add(doc, cdefines, 'Elem', d)
                            add(doc, ccdefines, 'Elem', d)

        return doc