Skip to content

Instantly share code, notes, and snippets.

@mrmeszaros
Created November 23, 2022 14:28
Show Gist options
  • Save mrmeszaros/6384ae6769ce17e07bc9412cb8464244 to your computer and use it in GitHub Desktop.
Save mrmeszaros/6384ae6769ce17e07bc9412cb8464244 to your computer and use it in GitHub Desktop.
Find Numix SVGs with arcs that QtSvg cannot render properly
#!/usr/bin/env python
from re import finditer
from glob import iglob
from os.path import basename, splitext
from collections import defaultdict
def main():
num = r"((\d+(\.\d*)?)|(\.\d+))"
signed = rf"[+-]?{num}"
flag = r"[01]"
# The problem lies in not having a separator (space or +/- sign) after a flag
# and the bad parsing code consuming more than one 0/1 character for a flag
pattern = rf"(?P<start>[aA]\s*{num}\s+{num}\s*{signed}\s+{flag})(?P<sep1>\s*)(?P<flag2>{flag})(?P<sep2>\s*[+-]?)(?P<end>{num}\s*{signed})"
issues_dict = defaultdict(list)
for file_path in iglob("icons/circle/48/*.svg"):
file_name = splitext(basename(file_path))[0]
with open(file_path, "r") as file:
for line in file:
for match in finditer(pattern, line):
if len(match['sep1']) < 1 or len(match['sep2']) < 1:
issues_dict[file_name].append(match)
for file_name in sorted(issues_dict):
print(file_name)
for match in issues_dict[file_name]:
print(f" -> {match.group()}")
print(f" {match['start']}{match['sep1'] or ' '}{match['flag2']}{match['sep2'] or ' '}{match['end']}")
print(f"{sum(len(matches) for matches in issues_dict.values())} issues in {len(issues_dict)} files to fix")
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment