代码拉取完成,页面将自动刷新
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
from Log import Log
import xml.dom.minidom
import re
class StringsXmlFileUtil:
'android strings.xml file util'
@staticmethod
def writeToFile(keys, values,directory,additional):
if not os.path.exists(directory):
os.makedirs(directory)
Log.info("Creating android file:" + directory + "/strings.xml")
fo = open(directory + "/strings.xml", "wb")
stringEncoding = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n"
fo.write(stringEncoding)
for x in range(len(keys)):
if values[x] is None or values[x] == '' :
Log.error("Key:" + keys[x] + "\'s value is None. Index:" + str(x + 1))
continue
key = keys[x].strip()
value = re.sub(r'(%\d\$)(@)', r'\1s', values[x])
content = " <string name=\"" + key + "\">" + value + "</string>\n"
fo.write(content);
if additional is not None:
fo.write(additional)
fo.write("</resources>");
fo.close()
@staticmethod
def getKeysAndValues(path):
if path is None:
Log.error('file path is None')
return
dom = xml.dom.minidom.parse(path)
root = dom.documentElement
itemlist = root.getElementsByTagName('string')
keys = []
values = []
for index in range(len(itemlist)):
item = itemlist[index]
key = item.getAttribute("name")
value = item.firstChild.data
Log.info("key:" + key + " value:" + value)
keys.append(key)
values.append(value)
return (keys,values)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。