-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixer.py
76 lines (50 loc) · 1.45 KB
/
fixer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import os
from cairosvg import svg2svg
def splitter(text, filters):
splitted = []
counter = 0
for letterindex in range(len(text)):
if text[letterindex] in filters:
splitted.append(text[counter:letterindex])
splitted.append(text[letterindex])
counter = letterindex+1
return splitted
def fix_file(file):
try: # acommodating for all of the broken symlinks
fileobject =open(file, "r+")
fileobject.close()
except FileNotFoundError:
return None
else:
try:
svg2svg(url=file)
except :
fileobject = open(file, 'r')
filedsmnld = fileobject.readlines()
fileobject.close()
filedsmnld = ''.join(filedsmnld)
filedsmnld = splitter(filedsmnld, [" ", "\n"])
newfile = open(file, "w")
in_svgtag = False
for i in range(len(filedsmnld)):
if filedsmnld[i] == "<svg":
in_svgtag = True
if filedsmnld[i][-1] == '>'and in_svgtag:
filedsmnld.insert(i, 'xmlns:osb="http://www.openswatchbook.org/uri/2009/osb" ')
break # just in case
filedsmnld = ''.join(filedsmnld)
newfile.write(filedsmnld)
newfile.close()
def main(path):
for filename in os.listdir(path):
if path == ".":
if os.path.isdir(filename):
main(filename + "/")
elif filename.endswith(".svg")and path != ".":
fix_file(path + filename)
else:
if os.path.isdir(path + filename):
main(path + filename + "/")
elif filename.endswith(".svg")and path != ".":
fix_file(path + filename)
main(".")