Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from xml.etree import ElementTree as ET
- from xml.dom import minidom
- import re, os
- projectFile = "../.project"
- classpathFile = "../.classpath"
- linksToAdd = [
- ["DWCMResources", "2", "PROJECT_LOC/dwcm/resources"],
- ["DWCMSrc", "2", "PROJECT_LOC/dwcm/src"],
- ["Archangel", "2", "PROJECT_LOC/dwcm/lib/archangel/Java"],
- ["ArchangelResources", "2", "PROJECT_LOC/dwcm/lib/archangel/resources"],
- ["ModDivisionCore", "2", "PROJECT_LOC/dwcm/lib/modDivisionCore/Java"],
- ["ModDivisionResources", "2", "PROJECT_LOC/dwcm/lib/modDivisionCore/resources"],
- ### ["ColoredLightApi", "2", "PROJECT_LOC/dwcm/lib/ColoredLightAPI/src"],
- ["Vanilla", "2", "PROJECT_LOC/dwcm/decompiledVanilla"]
- ]
- classpathToAdd = [
- "src/main/java",
- "DWCMSrc", "DWCMResources",
- ### "DalekModSrc", "DalekModResources",
- "Archangel", "ArchangelResources",
- "ModDivisionCore", "ModDivisionResources",
- "Vanilla", "src/main/resources"
- ]
- ### Because fuck you ElementTree
- def outputPretty(fileName, xml):
- text = minidom.parseString(ET.tostring(xml)).toprettyxml()
- # filtered = filter(lambda x: not re.match(r'^\s*$', x), s)
- filtered = os.linesep.join([s for s in text.splitlines() if s.strip()])
- f = open(fileName, 'w')
- f.write(filtered)
- f.close()
- ### PROJECT
- print "Parsing",projectFile
- doc = ET.parse(projectFile)
- root = doc.getroot()
- linkedResources = root.find('linkedResources')
- linksPresent = []
- for link in linkedResources.findall('link'):
- linkName = link.find("name").text
- print "Found linked resource:",linkName
- linksPresent.append(linkName)
- for neededLink in linksToAdd:
- linkName = neededLink[0]
- if linkName not in linksPresent:
- newLink = ET.Element("link")
- name = ET.SubElement(newLink, "name")
- name.text = linkName
- type = ET.SubElement(newLink, "type")
- type.text = neededLink[1]
- locationURI = ET.SubElement(newLink, "locationURI")
- locationURI.text = neededLink[2]
- print "Inserting link:",linkName
- linkedResources.append(newLink)
- else:
- print "Skipping link insertion:",linkName
- print " Writing",projectFile
- outputPretty(projectFile, root)
- ### CLASSPATH
- print "Parsing",classpathFile
- doc = ET.parse(classpathFile)
- root = doc.getroot()
- newRoot = ET.Element("classpath")
- for newEntry in classpathToAdd:
- print " Adding classpath entry:",newEntry
- newNode = ET.Element("classpathentry")
- newNode.set("kind", "src")
- newNode.set("path", newEntry)
- newRoot.append(newNode)
- entries = root.findall('classpathentry')
- for existing in entries:
- kind = existing.get("kind")
- path = existing.get("path")
- if kind == "src" and path in classpathToAdd:
- pass # Skip the ones we are already adding
- else:
- newRoot.append(existing)
- print " Writing",classpathFile
- outputPretty(classpathFile, newRoot)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement