34 lines
808 B
Python
34 lines
808 B
Python
#!/home/oracle/p3/bin/python
|
|
|
|
import re
|
|
import fileinput
|
|
|
|
ifile = "1-3.txt"
|
|
odir = "./unpack/"
|
|
|
|
fc_cnt = sum(1 for line in fileinput.input(ifile))
|
|
with open(ifile) as f:
|
|
fc = f.read().splitlines()
|
|
|
|
i = 0
|
|
while i<fc_cnt-2:
|
|
l1 = fc[i]
|
|
l2 = fc[i+1]
|
|
l3 = fc[i+2]
|
|
if l1.startswith("~") and l1.endswith("~") and l2.startswith("~ ") and l2.endswith(".sql ~") and l3.startswith("~") and l3.endswith("~"):
|
|
# Line 2 contains the script name
|
|
sname = l2.replace("~","").replace(" ","")
|
|
scontents = ""
|
|
j = i + 4
|
|
while j<fc_cnt:
|
|
l = fc[j]
|
|
if l.startswith("~") and l.endswith("~"):
|
|
# End of script
|
|
with open(f"{odir}/{sname}", "w") as f:
|
|
f.write(scontents)
|
|
break
|
|
else:
|
|
# Line is part of current script body
|
|
j += 1
|
|
scontents = scontents + l.lstrip("\t") + "\n"
|
|
i += 2 |