no errors
This commit is contained in:
parent
5cd709a449
commit
61a28b8a0f
@ -10,36 +10,40 @@ class File:
|
||||
"verbatim", "stub"
|
||||
]
|
||||
content = ""
|
||||
def __init__(self, **kwargs):
|
||||
if "attributes" in kwargs:
|
||||
self.attributes += kwargs["attributes"]
|
||||
del(kwargs["attributes"])
|
||||
for key in kwargs:
|
||||
if key == "attributes": self.attributes+=kwargs["key"]
|
||||
else: setattr(self, key, kwargs[key])
|
||||
files = {"./cleanup.sh": File(attributes=["verbatim"], content="#!/bin/sh\n")}
|
||||
for part in sys.stdin.read().split("\n\n\n").reverse():
|
||||
name = part.split("\n")[0]
|
||||
substitutions = dict()
|
||||
def __init__(self, **kwargs):
|
||||
for key in kwargs:
|
||||
if key == "attributes":
|
||||
self.attributes += kwargs[key]
|
||||
else:
|
||||
setattr(self, key, kwargs[key])
|
||||
files = {"./cleanup.sh": File(attributes=["verbatim"], content="#!/bin/sh\n")}
|
||||
for part in reversed(sys.stdin.read().split("\n\n\n")):
|
||||
name = "." + part.split("\n")[0]
|
||||
if "\t" in "." + name:
|
||||
attributes = name.split("\t")[1].split(",")
|
||||
name = name.split("\t")[0]
|
||||
else: attributes = default_attributes
|
||||
if len(name) > 1 and name[1] != "/": continue
|
||||
for s in part[len(name)+1:].split("\n\n")[0].split("\n"):
|
||||
s = s.split("\t")
|
||||
if len(s) == 2: substitutions[s[0]] = s[1]
|
||||
content = part[len(substitutions)+2:]
|
||||
if attributes.index("append") > attributes.index("replace"):
|
||||
else: attributes = []
|
||||
if len(name) <= 1 or name[1] != "/": continue
|
||||
content = part.split("\n\n")[0].split("\n")
|
||||
substitutions = dict()
|
||||
if(len(content) > 1):
|
||||
for s in content[1:]:
|
||||
s = s.split("\t")
|
||||
if len(s) == 2: substitutions[s[0]] = s[1]
|
||||
content = part[len(content)+2:]
|
||||
file = File(attributes = attributes, content = content,
|
||||
substitutions = substitutions)
|
||||
if file.attributes.index("append") > file.attributes.index("replace"):
|
||||
if not(name in files):
|
||||
sys.stderr.write(sys.argv[0] + ": " + name + ": "
|
||||
+ "appending to nothing\n")
|
||||
else:
|
||||
content = files[name].content + content
|
||||
files += {name: File(attributes = attributes, content = content,
|
||||
substitutions = substitutions)}
|
||||
file.content = files[name].content + file.content
|
||||
files[name] = file
|
||||
for name in files:
|
||||
if name == "./cleanup.sh": continue
|
||||
if name == "./cleanup.sh":
|
||||
continue
|
||||
attributes = files[name].attributes
|
||||
directory = "/".join(name.split("/")[:-1])
|
||||
if attributes.index("stub") > attributes.index("verbatim"):
|
||||
@ -59,20 +63,20 @@ for name in files:
|
||||
while True:
|
||||
instance = content.find(s, i)
|
||||
if instance == -1: break
|
||||
intances += [instance]
|
||||
instances += [instance]
|
||||
i = instance + len(s)
|
||||
if len(instances) == 0: continue
|
||||
for i in intances.reverse():
|
||||
content = (content[:i] + substitutions[s]
|
||||
for i in reversed(instances):
|
||||
content = (content[:i]
|
||||
+ files[name].substitutions[s]
|
||||
+ content[i+len(s):])
|
||||
files[name].content = content
|
||||
if not(os.path.isdir(directory)):
|
||||
os.makedirs(directory)
|
||||
files["./cleanup.sh"].content += "rm -r -- " + directory + "\n"
|
||||
else if directory == ".":
|
||||
elif directory == ".":
|
||||
files["./cleanup.sh"].content += "rm -- " + name + "\n"
|
||||
with open(name, "w") as fd:
|
||||
fd.write(f)
|
||||
with open(name, "w") as fd: fd.write(files[name].content)
|
||||
if len(files["./cleanup.sh"].content.split("\n")) > 2:
|
||||
with open("./cleanup.sh", "w") as fd:
|
||||
fd.write(files["./cleanup.sh"].content)
|
||||
|
Loading…
Reference in New Issue
Block a user