91 lines
2.7 KiB
Python
91 lines
2.7 KiB
Python
import os
|
|
import glob
|
|
import shutil
|
|
from xml.dom import minidom
|
|
|
|
def fixed_writexml(self, writer, indent="", addindent="", newl=""):
|
|
# indent = current indentation
|
|
# addindent = indentation to add to higher levels
|
|
# newl = newline string
|
|
writer.write(indent+"<" + self.tagName)
|
|
|
|
attrs = self._get_attributes()
|
|
a_names = attrs.keys()
|
|
#a_names.sort()
|
|
|
|
for a_name in a_names:
|
|
writer.write(" %s=\"" % a_name)
|
|
minidom._write_data(writer, attrs[a_name].value)
|
|
writer.write("\"")
|
|
if self.childNodes:
|
|
if len(self.childNodes) == 1 \
|
|
and self.childNodes[0].nodeType == minidom.Node.TEXT_NODE:
|
|
writer.write(">")
|
|
self.childNodes[0].writexml(writer, "", "", "")
|
|
writer.write("</%s>%s" % (self.tagName, newl))
|
|
return
|
|
writer.write(">%s" % (newl))
|
|
for node in self.childNodes:
|
|
if node.nodeType is not minidom.Node.TEXT_NODE:
|
|
node.writexml(writer, indent+addindent, addindent, newl)
|
|
writer.write("%s</%s>%s" % (indent, self.tagName, newl))
|
|
else:
|
|
writer.write("/>%s" % (newl))
|
|
minidom.Element.writexml = fixed_writexml
|
|
|
|
def getFiles(dirPath, postfix):
|
|
fs = glob.glob(dirPath + "\\" + postfix)
|
|
return fs
|
|
|
|
def rootDir():
|
|
path = os.path.abspath(os.path.dirname(__file__))
|
|
return path
|
|
|
|
def dirdir(path, postfix):
|
|
fs = getFiles(path, postfix)
|
|
ps = os.listdir(path)
|
|
for p in ps:
|
|
if os.path.isdir(path + '\\' + p):
|
|
fs.extend(dirdir(path + '\\' + p, postfix))
|
|
return fs
|
|
|
|
def modifyToolset(f, toolset):
|
|
if (os.path.exists(f)):
|
|
dom = minidom.parse(f25)
|
|
root = dom.documentElement
|
|
pgs = root.getElementsByTagName('PropertyGroup')
|
|
for pg in pgs:
|
|
if pg.getAttribute('Label') == 'Configuration':
|
|
tss = pg.getElementsByTagName('PlatformToolset')
|
|
txt = dom.createTextNode(toolset)
|
|
for ts in tss:
|
|
if ts.firstChild.nodeType == ts.firstChild.TEXT_NODE:
|
|
ts.firstChild.replaceWholeText(toolset)
|
|
xmlF= open(f, 'w', encoding='utf-8')
|
|
dom.writexml(xmlF, indent = '', addindent = ' '*4, newl = '\n', encoding = 'utf-8')
|
|
|
|
def modifySubVer(f, sub):
|
|
if (os.path.exists(f)):
|
|
dom = minidom.parse(f)
|
|
root = dom.documentElement
|
|
pg = dom.createElement('PropertyGroup')
|
|
pg.setAttribute('Label', 'UserMacros')
|
|
rv = dom.createElement('RVER')
|
|
txt = dom.createTextNode(sub)
|
|
rv.appendChild(txt)
|
|
pg.appendChild(rv)
|
|
root.insertBefore(pg, root.firstChild)
|
|
xmlF= open(f, 'w', encoding='utf-8')
|
|
dom.writexml(xmlF, indent = '', addindent = ' '*4, newl = '\n', encoding = 'utf-8')
|
|
|
|
|
|
if __name__ == "__main__":
|
|
fs = dirdir(rootDir(), '*23.vcxproj')
|
|
for f in fs:
|
|
pr = os.path.split(f)
|
|
f24 = pr[0] + '\\' + pr[1].replace('23', '24')
|
|
f25 = pr[0] + '\\' + pr[1].replace('23', '25')
|
|
shutil.copy(f, f24)
|
|
shutil.copy(f, f25)
|
|
modifyToolset(f24, 'v142')
|
|
modifyToolset(f25, 'v143') |