Skip to content
Snippets Groups Projects
Commit aa591e04 authored by George Marchment's avatar George Marchment
Browse files

Added check to not try and rewrite the same thing (it was creating an error)

parent ab4dba41
No related branches found
No related tags found
No related merge requests found
Pipeline #14513 failed with stage
in 2 minutes and 19 seconds
......@@ -675,17 +675,30 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
new = exe.get_code(get_OG = True).replace(emited.get_code(), emited.get_emits().get_origins()[0].get_code())
#to_replace.append((exe.get_code(get_OG = True), f"{exe.get_gives()[0].get_code()} = {emited.get_emits().get_origins()[0].get_code()}"))
to_replace.append((exe.get_code(get_OG = True), new))
#This dictionnary is used to check if the replacement has already been done (in the case of dupliactes in new)
dico_replace = {}
for r in to_replace:
old, new = r
temp_code = code
#Case of channel = channel
if(new.find("=")!=-1):
if(new.split("=")[0].strip()==new.split("=")[1].strip()):
new = ''
#code = code.replace(old, new)
code = replace_group1(code, fr"({re.escape(old)})[^\w]", new)
if(temp_code==code):
raise Exception("Something went wrong: The code hasn't changed")
need_to_replace = True
try:
t = dico_replace[old]
if(t==new):
need_to_replace = False
else:
raise Exception("This shouldn't happen")
except:
dico_replace[old]= new
if(need_to_replace):
temp_code = code
#Case of channel = channel
if(new.find("=")!=-1):
if(new.split("=")[0].strip()==new.split("=")[1].strip()):
new = ''
#code = code.replace(old, new)
code = replace_group1(code, fr"({re.escape(old)})[^\w]", new)
if(temp_code==code):
raise Exception("Something went wrong: The code hasn't changed")
return code
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment