less copy protection, more size visualization
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

34 řádky
1.0 KiB

  1. import sys
  2. import re
  3. from xml.etree import ElementTree
  4. from pathlib import Path
  5. import os
  6. for path in Path(sys.argv[1]).rglob("*.svg"):
  7. if path.name.startswith("z_"):
  8. print("Renamed {0}".format(path))
  9. renamed = path.with_name(path.name[2:])
  10. if os.path.exists(renamed):
  11. os.unlink(renamed)
  12. os.rename(path, renamed)
  13. for path in Path(sys.argv[1]).rglob('*.svg'):
  14. tree = ElementTree.ElementTree()
  15. parsed = tree.parse(path)
  16. if "width" not in parsed.attrib:
  17. print(f"Rewriting {path}")
  18. width, height = parsed.attrib["viewBox"].split(" ")[-2:]
  19. # I'd rather avoid mangling the XML files by parsing them first
  20. # XML is awful and we never should have invented it :(
  21. with open(path, "r", encoding="utf-8") as file:
  22. data = file.read()
  23. data = re.sub('viewBox="0 0', f'width="{width}" height="{height}" viewBox="0 0', data)
  24. with open(path, "w", encoding="utf-8") as file:
  25. file.write(data)