Fixed 10 Anti-Pattern issues

This commit is contained in:
Navan Chauhan 2020-07-07 12:40:28 +05:30
parent bb73018258
commit 3b6482cb0a
4 changed files with 17 additions and 21 deletions

View File

@ -8,7 +8,7 @@ mycursor.execute(sql_select_Query)
records = mycursor.fetchall() records = mycursor.fetchall()
def email(zi): def email(zipArchive):
import smtplib import smtplib
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText from email.mime.text import MIMEText
@ -26,9 +26,9 @@ def email(zi):
msg.attach(MIMEText(body, 'plain')) msg.attach(MIMEText(body, 'plain'))
filename = "Curie_Web_Results_Job_ID_" + str(jobID) + ".zip" filename = "Curie_Web_Results_Job_ID_" + str(jobID) + ".zip"
attachment = open((str(zi) + ".zip"), "rb")
p = MIMEBase('application', 'octet-stream') 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) encoders.encode_base64(p)
p.add_header('Content-Disposition', "attachment; filename= %s" % filename) p.add_header('Content-Disposition', "attachment; filename= %s" % filename)
msg.attach(p) msg.attach(p)

View File

@ -8,7 +8,7 @@ mycursor.execute(sql_select_Query)
records = mycursor.fetchall() records = mycursor.fetchall()
def email(zi): def email(zipArchive):
import smtplib import smtplib
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText from email.mime.text import MIMEText
@ -25,10 +25,10 @@ def email(zi):
body = "Attached Zip contains the docked files, PLIP report and PyMOL Visualisations. If the ZIP file does not contain these files, please report this issue by replying to this email. Job was submitted on {} with the description {}".format(date, description) body = "Attached Zip contains the docked files, PLIP report and PyMOL Visualisations. If the ZIP file does not contain these files, please report this issue by replying to this email. Job was submitted on {} with the description {}".format(date, description)
msg.attach(MIMEText(body, 'plain')) msg.attach(MIMEText(body, 'plain'))
filename = "Curie_Web_Results_Job_ID_" + str(jobID) + ".zip" filename = "Curie_Web_Results_Job_ID_" + str(jobID) + ".zip"
attachment = open((str(zi) + ".zip"), "rb")
p = MIMEBase('application', 'octet-stream') 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) encoders.encode_base64(p)
p.add_header('Content-Disposition', "attachment; filename= %s" % filename) p.add_header('Content-Disposition', "attachment; filename= %s" % filename)
msg.attach(p) msg.attach(p)

View File

@ -105,9 +105,8 @@ def dock_upload():
target.save(secure_filename(target.filename)) target.save(secure_filename(target.filename))
ligand.save(secure_filename(ligand.filename)) ligand.save(secure_filename(ligand.filename))
buffer = "center_x="+cx+"\ncenter_y="+cy+"\ncenter_z="+cz+"\nsize_x="+sx+"\nsize_y="+sy+"\nsize_z="+sz buffer = "center_x="+cx+"\ncenter_y="+cy+"\ncenter_z="+cz+"\nsize_x="+sx+"\nsize_y="+sy+"\nsize_z="+sz
f = open("config.txt","w") with open("config.txt","w") as f:
f.write(buffer) f.write(buffer)
f.close()
ligandB = convertToBinaryData(secure_filename(ligand.filename)) ligandB = convertToBinaryData(secure_filename(ligand.filename))
receptor = convertToBinaryData(secure_filename(target.filename)) receptor = convertToBinaryData(secure_filename(target.filename))
config = convertToBinaryData("config.txt") config = convertToBinaryData("config.txt")

View File

@ -27,9 +27,9 @@ def email(compressedFile):
msg.attach(MIMEText(body, 'plain')) msg.attach(MIMEText(body, 'plain'))
filename = "Curie_Web_Results_Job_ID_" + str(jobID) + ".zip" filename = "Curie_Web_Results_Job_ID_" + str(jobID) + ".zip"
attachment = open((str(compressedFile) + ".zip"), "rb")
p = MIMEBase('application', 'octet-stream') p = MIMEBase('application', 'octet-stream')
p.set_payload((attachment).read()) with open((str(zi) + ".zip"), "rb") as attachment:
p.set_payload((attachment).read())
encoders.encode_base64(p) encoders.encode_base64(p)
p.add_header('Content-Disposition', "attachment; filename= %s" % filename) p.add_header('Content-Disposition', "attachment; filename= %s" % filename)
msg.attach(p) msg.attach(p)
@ -79,15 +79,12 @@ from shutil import make_archive
with tempfile.TemporaryDirectory() as directory: with tempfile.TemporaryDirectory() as directory:
print('The created temporary directory is %s' % directory) print('The created temporary directory is %s' % directory)
os.chdir(directory) os.chdir(directory)
file = open(receptor_name,"wb") with open(receptor_name,"wb") as file:
file.write(targetB) file.write(targetB)
file.close() with open(ligand_name,"wb") as file:
file = open(ligand_name,"wb") file.write(ligandB)
file.write(ligandB) with open("config.txt","wb") as file:
file.close() file.write(configB)
file = open("config.txt","wb")
file.write(configB)
file.close()
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)) 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))
z = "Curie_Web_Result_"+str(jobID) z = "Curie_Web_Result_"+str(jobID)
zi = os.path.join(f,z) zi = os.path.join(f,z)