Skip to content

Commit

Permalink
round of code cleanup (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthchirp committed Apr 10, 2019
1 parent a12fd99 commit 7be86ec
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 99 deletions.
3 changes: 0 additions & 3 deletions bin/dimple2ispyb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
import ConfigParser
import logging
import os
import pickle
import pipes
import re
import sys
import time
import traceback
from datetime import datetime
from logging.handlers import RotatingFileHandler

Expand Down
6 changes: 1 addition & 5 deletions bin/em_put_movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@

import datetime
import logging
import os
import string
import sys
import time
from datetime import datetime
from logging.handlers import RotatingFileHandler

from ispyb.core import core
from ispyb.dbconnection import DBConnection
Expand Down Expand Up @@ -93,7 +89,7 @@ def exit(code, message=None):

result = None
if visitid is not None or opts.movieid is not None:
# EMMovieId, blsessionId,blsampleId,movieFile,p_NOImages,frameLength,totalExposure,magnification,samplePixSize,dosePerFrame,totalDose,runStatus,comments,runDirectory,binning,particleDiameter,pixelSize,boxSize,minResolution,maxResolution, minDefocus, maxDefocus, defocusStepSize, amountAstigmatism, extractSize, starttime, endtime
# EMMovieId, blsessionId,blsampleId,movieFile,p_NOImages,frameLength,totalExposure,magnification,samplePixSize,dosePerFrame,totalDose,runStatus,comments,runDirectory,binning,particleDiameter,pixelSize,boxSize,minResolution,maxResolution, minDefocus, maxDefocus, defocusStepSize, amountAstigmatism, extractSize, starttime, endtime

# Store a movie data collection ...
params = mxacquisition.get_data_collection_params()
Expand Down
20 changes: 5 additions & 15 deletions bin/legacy/em_put_particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,21 @@
# python em_put_particle.py --movieid=1 --x=123.4 --y=50.02

import logging
import os
import string
import sys
import time
from logging.handlers import RotatingFileHandler

import cx_Oracle

if __name__ == '__main__' :

from ispyb_api.dbconnection import dbconnection
from ispyb_api.core import core
from ispyb_api.mxacquisition import mxacquisition
from ispyb_api.em import em

from datetime import datetime

def exit(code, message=None):
dbconnection.disconnect()
if not message is None:
print(message)
sys.exit(code)

logging.info("test")

import optparse
parser = optparse.OptionParser()
parser.add_option("--particleid", dest="particleid", help="Id for particle", metavar="INTEGER")
Expand All @@ -44,17 +34,17 @@ def exit(code, message=None):
(opts, args) = parser.parse_args()

cursor = None
if opts.db is None or opts.db == "prod":
if opts.db is None or opts.db == "prod":
cursor = dbconnection.connect_to_prod()
elif opts.db == "dev":
cursor = dbconnection.connect_to_dev()
elif opts.db == "test":
cursor = dbconnection.connect_to_test()
else:
exit(1, "ERROR: Invalid database")

if opts.particleid is None and opts.dcid is None:
exit(1, "ERROR: Both movieid and particleid are None.")

p_id = em.put_particle(cursor, opts.particleid, opts.dcid, opts.x, opts.y)
exit(0, "--particleid=%d" % p_id)
21 changes: 6 additions & 15 deletions bin/legacy/em_put_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,21 @@
# python em_put_sample.py --proposal=em1234 --x=123.4 --y=50.02

import logging
import os
import string
import sys
import time
from logging.handlers import RotatingFileHandler

import cx_Oracle

if __name__ == '__main__' :

from ispyb_api.dbconnection import dbconnection
from ispyb_api.core import core
from ispyb_api.mxacquisition import mxacquisition

from datetime import datetime

def exit(code, message=None):
dbconnection.disconnect()
if not message is None:
print(message)
sys.exit(code)

logging.info("test")

import optparse
parser = optparse.OptionParser()
parser.add_option("--sampleid", dest="sampleid", help="Id for sample", metavar="INTEGER")
Expand All @@ -43,22 +34,22 @@ def exit(code, message=None):
(opts, args) = parser.parse_args()

cursor = None
if opts.db is None or opts.db == "prod":
if opts.db is None or opts.db == "prod":
cursor = dbconnection.connect_to_prod()
elif opts.db == "dev":
cursor = dbconnection.connect_to_dev()
elif opts.db == "test":
cursor = dbconnection.connect_to_test()
else:
exit(1, "ERROR: Invalid database")


params = core.get_sample_params()
if not opts.sampleid is None:
params['id'] = int(opts.sampleid)
params['name'] = opts.longname
params['code'] = opts.shortname
params['comments'] = opts.comments

s_id = core.put_sample(cursor, params.values())
exit(0, "--sampleid=%d" % s_id)
16 changes: 5 additions & 11 deletions bin/legacy/put_dcgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@
# python put_dcgroup.py --movieid=1 --x=123.4 --y=50.02

import logging
import os
import string
import sys
import time
from logging.handlers import RotatingFileHandler

import cx_Oracle

if __name__ == '__main__' :

Expand All @@ -29,9 +23,9 @@ def exit(code, message=None):
if not message is None:
print(message)
sys.exit(code)

logging.info("test")

import optparse
parser = optparse.OptionParser()
parser.add_option("--id", dest="id", help="Id for d.c.group", metavar="INTEGER")
Expand All @@ -49,15 +43,15 @@ def exit(code, message=None):
(opts, args) = parser.parse_args()

cursor = None
if opts.db is None or opts.db == "prod":
if opts.db is None or opts.db == "prod":
cursor = dbconnection.connect_to_prod()
elif opts.db == "dev":
cursor = dbconnection.connect_to_dev()
elif opts.db == "test":
cursor = dbconnection.connect_to_test()
else:
exit(1, "ERROR: Invalid database")

# Find the id for a given visit
visitid = core.retrieve_visit_id(cursor, opts.visit)
if visitid is None:
Expand All @@ -81,7 +75,7 @@ def exit(code, message=None):
params['actual_sample_barcode'] = opts.actual_sample_barcode
params['comments'] = opts.comments
dcg_id = mxacquisition.put_data_collection_group(cursor, params.values())

if dcg_id is None:
exit(1, "ERROR: dc_group is None.") # exit code 1 - indicates error
exit(0, "--dcg_id=%d" % dcg_id)
19 changes: 6 additions & 13 deletions bin/legacy/put_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@
# python put_program.py --....

import logging
import os
import string
import sys
import time
from logging.handlers import RotatingFileHandler

import cx_Oracle

# AutoProcProgram.processingStatus:
# AutoProcProgram.processingStatus:
# no row = didn't run
# NULL (None) = running
# 0 = failed
Expand All @@ -25,7 +19,6 @@
if __name__ == '__main__' :

from ispyb_api.dbconnection import dbconnection
from ispyb_api.core import core
from ispyb_api.mxdatareduction import mxdatareduction

from datetime import datetime
Expand All @@ -35,9 +28,9 @@ def exit(code, message=None):
if not message is None:
print(message)
sys.exit(code)

logging.info("test")

import optparse
parser = optparse.OptionParser()
parser.add_option("--id", dest="id", help="Id for program run", metavar="INTEGER")
Expand All @@ -53,7 +46,7 @@ def exit(code, message=None):
(opts, args) = parser.parse_args()

cursor = None
if opts.db is None or opts.db == "prod":
if opts.db is None or opts.db == "prod":
cursor = dbconnection.connect_to_prod()
elif opts.db == "dev":
cursor = dbconnection.connect_to_dev()
Expand Down Expand Up @@ -84,9 +77,9 @@ def exit(code, message=None):
# params['filename3'] = ''
# params['filepath3'] = ''
# params['filetype3'] = ''

p_id = mxdatareduction.put_program(cursor, params.values())

if p_id is None:
exit(1, "ERROR: p_id is None.") # exit code 1 - indicates error
exit(0, "--p_id=%d" % p_id)
13 changes: 3 additions & 10 deletions bin/legacy/tomo2ispyb.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
#!/usr/bin/env python

import logging
import os
import pipes
import re
import sys
import time
import traceback
from datetime import datetime
# from datetime import datetime

from ispyb_api.core import core
from ispyb_api.dbconnection import dbconnection
Expand Down Expand Up @@ -36,7 +29,7 @@ def store_dc(cursor, parentid):
#params['frames'] = parentid
#params['comments'] = parentid
return tomo.insert_dc(cursor, params.values())

def store_recon(cursor, parentid):
'''Populate dict and store tomography reconstruction'''
params = tomo.get_recon_params()
Expand All @@ -50,7 +43,7 @@ def store_recon(cursor, parentid):
#params['histogram'] = parentid
#params['report'] = parentid
return tomo.insert_recon(cursor, params.values())


cursor = dbconnection.connect_to_prod()

Expand Down
1 change: 0 additions & 1 deletion bin/mxdatareduction2ispyb.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import os
import sys
from datetime import datetime

import ispyb
from ispyb.xmltools import mx_data_reduction_to_ispyb, xml_file_to_dict
Expand Down
4 changes: 1 addition & 3 deletions ispyb/connector/mysqlsp/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import absolute_import, division, print_function

import os
import sys
import threading
import traceback

Expand Down Expand Up @@ -47,7 +45,7 @@ def __del__(self):
def disconnect(self):
'''Release the connection previously created.'''
if hasattr(self, 'conn') and self.conn is not None:
self.conn.close()
self.conn.close()
self.conn = None

def get_data_area_package(self):
Expand Down
2 changes: 1 addition & 1 deletion ispyb/interface/shipping.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import abc
from __future__ import absolute_import, division, print_function

from ispyb.interface.dataarea import DataArea

Expand Down
2 changes: 0 additions & 2 deletions ispyb/model/integration.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import absolute_import, division, print_function

import collections

import ispyb.model
import ispyb.model.processingprogram

Expand Down
5 changes: 0 additions & 5 deletions ispyb/sp/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
#

import copy
import datetime
import os
import string
import sys
import time

import ispyb.interface.core
from ispyb.strictordereddict import StrictOrderedDict
Expand Down
4 changes: 0 additions & 4 deletions ispyb/sp/mxscreening.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
#

import copy
import datetime
import os
import sys
import time

import ispyb.interface.screening
from ispyb.strictordereddict import StrictOrderedDict
Expand Down
6 changes: 1 addition & 5 deletions ispyb/sp/shipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
#

import copy
import datetime
import os
import sys
import time

import ispyb.interface.shipping
from ispyb.strictordereddict import StrictOrderedDict
Expand Down Expand Up @@ -49,6 +45,6 @@ def upsert_dewar(self, values):
def retrieve_dewars_for_proposal_code_number(self, proposal_code, proposal_number, auth_login=None):
'''Get a result-set with the dewars associated with shipments in a given proposal specified by proposal code, proposal_number'''
return self.get_connection().call_sp_retrieve(
procname='retrieve_dewars_for_proposal_code_number_v2',
procname='retrieve_dewars_for_proposal_code_number_v2',
args=(proposal_code, proposal_number, auth_login)
)
Loading

0 comments on commit 7be86ec

Please sign in to comment.