This repository was archived by the owner on Aug 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsvg.py
More file actions
37 lines (31 loc) · 1.23 KB
/
svg.py
File metadata and controls
37 lines (31 loc) · 1.23 KB
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
import glob, os
import config
from common import memoize, wrap_output
@wrap_output(list)
def list_all(collection = None):
if collection:
for i in glob.glob(os.path.join(config.svgdir, collection, "*.svg")):
yield os.path.join(collection, os.path.basename(i)[:-4])
else:
for i in glob.glob(os.path.join(config.svgdir, "*.svg")):
yield os.path.basename(i)[:-4]
@wrap_output(list)
def list_collections():
for i in glob.glob(os.path.join(config.svgdir, "*")):
if not i.endswith(".svg"):
yield os.path.basename(i)
@memoize
def get(name, color=None):
with open(os.path.join(config.svgdir, f"{name}.svg"), "r") as f:
if not color:
return f.read()
return (f.read() #EW!
.replace("style=\"fill:#", f"style=\"fill:#{color};")
.replace("style='fill:#", f"style='fill:#{color};")
.replace("fill=\"#", f"fill=\"#{color}\" asdasd=\"")
.replace("fill='#", f"fill='#{color}' asdasd='")
.replace("<svg", f"<svg fill=\"#{color}\"")
)
def store(name, data):
with open(os.path.join(config.svgdir, f"{name}.svg"), "wb" if type(data) is bytes else "w") as f:
return f.write(data)