less copy protection, more size visualization
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

25 lignes
711 B

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