1
0

no errors

This commit is contained in:
dtb 2023-07-20 00:46:51 -04:00
parent 5cd709a449
commit 61a28b8a0f

View File

@ -10,36 +10,40 @@ class File:
"verbatim", "stub" "verbatim", "stub"
] ]
content = "" 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() 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: if "\t" in "." + name:
attributes = name.split("\t")[1].split(",") attributes = name.split("\t")[1].split(",")
name = name.split("\t")[0] name = name.split("\t")[0]
else: attributes = default_attributes else: attributes = []
if len(name) > 1 and name[1] != "/": continue if len(name) <= 1 or name[1] != "/": continue
for s in part[len(name)+1:].split("\n\n")[0].split("\n"): content = part.split("\n\n")[0].split("\n")
substitutions = dict()
if(len(content) > 1):
for s in content[1:]:
s = s.split("\t") s = s.split("\t")
if len(s) == 2: substitutions[s[0]] = s[1] if len(s) == 2: substitutions[s[0]] = s[1]
content = part[len(substitutions)+2:] content = part[len(content)+2:]
if attributes.index("append") > attributes.index("replace"): file = File(attributes = attributes, content = content,
substitutions = substitutions)
if file.attributes.index("append") > file.attributes.index("replace"):
if not(name in files): if not(name in files):
sys.stderr.write(sys.argv[0] + ": " + name + ": " sys.stderr.write(sys.argv[0] + ": " + name + ": "
+ "appending to nothing\n") + "appending to nothing\n")
else: else:
content = files[name].content + content file.content = files[name].content + file.content
files += {name: File(attributes = attributes, content = content, files[name] = file
substitutions = substitutions)}
for name in files: for name in files:
if name == "./cleanup.sh": continue if name == "./cleanup.sh":
continue
attributes = files[name].attributes attributes = files[name].attributes
directory = "/".join(name.split("/")[:-1]) directory = "/".join(name.split("/")[:-1])
if attributes.index("stub") > attributes.index("verbatim"): if attributes.index("stub") > attributes.index("verbatim"):
@ -59,20 +63,20 @@ for name in files:
while True: while True:
instance = content.find(s, i) instance = content.find(s, i)
if instance == -1: break if instance == -1: break
intances += [instance] instances += [instance]
i = instance + len(s) i = instance + len(s)
if len(instances) == 0: continue if len(instances) == 0: continue
for i in intances.reverse(): for i in reversed(instances):
content = (content[:i] + substitutions[s] content = (content[:i]
+ files[name].substitutions[s]
+ content[i+len(s):]) + content[i+len(s):])
files[name].content = content files[name].content = content
if not(os.path.isdir(directory)): if not(os.path.isdir(directory)):
os.makedirs(directory) os.makedirs(directory)
files["./cleanup.sh"].content += "rm -r -- " + directory + "\n" files["./cleanup.sh"].content += "rm -r -- " + directory + "\n"
else if directory == ".": elif directory == ".":
files["./cleanup.sh"].content += "rm -- " + name + "\n" files["./cleanup.sh"].content += "rm -- " + name + "\n"
with open(name, "w") as fd: with open(name, "w") as fd: fd.write(files[name].content)
fd.write(f)
if len(files["./cleanup.sh"].content.split("\n")) > 2: if len(files["./cleanup.sh"].content.split("\n")) > 2:
with open("./cleanup.sh", "w") as fd: with open("./cleanup.sh", "w") as fd:
fd.write(files["./cleanup.sh"].content) fd.write(files["./cleanup.sh"].content)