From 59e56bb76ecdc11d610e56bd1c04de16d9295f8b Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Tue, 7 Jul 2020 12:27:10 +0530 Subject: fix file open anti-pattern --- app/dock_docker.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'app') diff --git a/app/dock_docker.py b/app/dock_docker.py index e1b17d1..54f413c 100644 --- a/app/dock_docker.py +++ b/app/dock_docker.py @@ -26,9 +26,9 @@ def email(zipArchive): msg.attach(MIMEText(body, 'plain')) filename = "Curie_Web_Results_Job_ID_" + str(jobID) + ".zip" - attachment = open((str(zipArchive) + ".zip"), "rb") p = MIMEBase('application', 'octet-stream') - p.set_payload((attachment).read()) + with open((str(zipArchive) + ".zip"), "rb") as attachment: + p.set_payload((attachment).read()) encoders.encode_base64(p) p.add_header('Content-Disposition', "attachment; filename= %s" % filename) msg.attach(p) @@ -78,15 +78,12 @@ with tempfile.TemporaryDirectory() as directory: # copy(t,os.getcwd()) # copy(r,os.getcwd()) # copy(c, os.getcwd()) - file = open(receptor_name,"wb") - file.write(targetB) - file.close() - file = open(ligand_name,"wb") - file.write(ligandB) - file.close() - file = open("config.txt","wb") - file.write(configB) - file.close() + with open(receptor_name,"wb") as file: + file.write(targetB) + with open(ligand_name,"wb") as file: + file.write(ligandB) + with open("config.txt","wb") as file: + file.write(configB) os.system("docker run --rm -v ${PWD}:/results -w /results -u $(id -u ${USER}):$(id -g ${USER}) navanchauhan/curie-cli -r %s -l %s -c config.txt -dpi" % (receptor_name,ligand_name)) #copy("report.pdf",f) z = "Curie_Web_Result_"+str(jobID) -- cgit v1.2.3