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ů.
 
 
 

31 řádky
936 B

  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. os.rename(path, path.with_name(path.name[2:]))
  10. for path in Path(sys.argv[1]).rglob('*.svg'):
  11. tree = ElementTree.ElementTree()
  12. parsed = tree.parse(path)
  13. if "width" not in parsed.attrib:
  14. print(f"Rewriting {path}")
  15. width, height = parsed.attrib["viewBox"].split(" ")[-2:]
  16. # I'd rather avoid mangling the XML files by parsing them first
  17. # XML is awful and we never should have invented it :(
  18. with open(path, "r", encoding="utf-8") as file:
  19. data = file.read()
  20. data = re.sub('viewBox="0 0', f'width="{width}" height="{height}" viewBox="0 0', data)
  21. with open(path, "w", encoding="utf-8") as file:
  22. file.write(data)