-
Notifications
You must be signed in to change notification settings - Fork 0
/
yakumo.py
47 lines (46 loc) · 1.31 KB
/
yakumo.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
import json
import re
import os
class Yakumo:
def __init__(self,config):
conf=json.loads(config)
root=conf["root"]
files=conf["files"]
self.files=[root+file for file in files]
self.main=root+conf["main"]
self.start=conf["split"]["start"]
self.end=conf["split"]["end"]
self.root=root
def hasamare(self,text,start,end):
def reEscape(text):
escapes=["\\"]
escapes.extend(list("*+.?{}()[]^$-|/"))
for escape in escapes:
text=text.replace(escape,("\\")+escape)
return text
c=(reEscape(start)+r'(.+)'+reEscape(end))
str= re.findall(c,text)
return str
def build(self):
files={}
with open(self.main) as f:
main=f.read()
while True:
hasa=self.hasamare(main,self.start,self.end)
if len(hasa)==0:
break
hasa=hasa[0]
path=self.root+hasa
if path in self.files:
if not path in files:
with open(path) as file:
files[path]=file.read()
main=main.replace(self.start+hasa+self.end,files[path],)
return main
def build(configPath,outPath):
with open(configPath) as f:
yakumo=Yakumo(f.read())
if not os.path.isdir(os.path.dirname(outPath)):
os.makedirs(os.path.dirname(outPath))
with open(outPath,"w") as f:
f.write(yakumo.build())