I am trying to convert a JTE template into a JTE v2 template in python. However, I need to figure out how to update the line above the search pattern...
Jenkins file
libraries {
merge = true
nexus {
merge = true
}
sonarqube {
merge = true
}
}
git {
merge = true
checkout {
override = true
shallow = false
}
}
and I need to convert it into a format like this ...
@merge libraries {
@merge nexus {
}
@merge sonarqube {
}
}
@merge git {
@override checkout {
shallow = false
}
}
I basicaly have to go through the file line by line and search for merge or override and append it to the begining of the previous line and remove the line containing the match...
a_file = open("jenkins.groovy", "r")
lines = a_file.readlines()
a_file.close()
new_file = open("jenkins_patched.groovy", "w")
for line in lines:
if line.strip("\n") != "merge" or line.strip("\n") != "override":
new_file.write(line)
new_file.close()
But, how does one ammend the previous line in the file ?