1. ## Set the contentprof_path to the .contentprof file you want to edit
  2. ## Set the new_size to any value you want. If its a size tag,
  3. ## it'll be a number, if it's style tag, it'll be regular, bold or italic
  4. import BeautifulSoup
  5. import os.path
  6. #parse the .contentproj file for spritefont paths
  7. contentprof_path = r"C:\path\to\GameContent.contentproj"
  8. #pull out the dir name
  9. directory = os.path.split(contentprof_path)[0]
  10. #the new font size
  11. new_size = 16
  12. #the tag to change
  13. tag_to_change = "size"
  14. #----------------------------------------------------------------------
  15. def ParseXMLtoStoneSoup(path):
  16. """loads a given xml file path into a BeautifulStoneSoup object"""
  17. with open(path) as f:
  18. contentprof_content = f.read()
  19. soup = BeautifulSoup.BeautifulStoneSoup(contentprof_content)
  20. return soup
  21. #----------------------------------------------------------------------
  22. def changeTag(soup, tag, newValue):
  23. """changes a given tag's string to newValue"""
  24. #find the size tag
  25. foundTag = soup.find(tag)
  26. #change the value, convert to string
  27. foundTag.setString(str(newValue).lower())
  28. soup = ParseXMLtoStoneSoup(contentprof_path)
  29. #look for all the tags 'compile'
  30. compileTags = soup.findAll("compile")
  31. #save all the spritefont file names
  32. spriteFonts = []
  33. for tag in compileTags:
  34. spriteFonts.append(directory+ r"\\" + tag['include'])
  35. #you can check for path validity however you would like
  36. #print "Here are the relevant spritefonts."
  37. #for path in spriteFonts:
  38. #print path
  39. ##now we've got the filepaths, time to open each up and edit the proper tags
  40. for path in spriteFonts:
  41. #load one font into BeautifulStoneSoup
  42. spriteFontSoup = ParseXMLtoStoneSoup(path)
  43. changeTag(spriteFontSoup, tag_to_change, new_size)
  44. #save the new file
  45. with open(path, 'w') as f:
  46. f.write(spriteFontSoup.prettify())
  47. print "changed", path
  48. print "Done!"