Skip to content

Commit

Permalink
adding interface to the sql approach
Browse files Browse the repository at this point in the history
  • Loading branch information
Galithil committed Aug 18, 2016
1 parent b8f379e commit 0438ef8
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions scripts/project_summary_upload_LIMS.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
from optparse import OptionParser
from LIMS2DB.utils import formatStack
from statusdb.db.utils import *
from genologics_sql.utils import get_session
from genologics_sql.queries import get_last_modified_projectids
from genologics_sql.utils import *
from genologics_sql.tables import Project as DBProject
from LIMS2DB.classes import ProjectSQL

from pprint import pprint

Expand Down Expand Up @@ -103,6 +105,8 @@ def main(options):
proj_db = couch['projects']
samp_db = couch['samples']
mainlims = Lims(BASEURI, USERNAME, PASSWORD)
lims_db = get_session()

mainlog = logging.getLogger('psullogger')
mainlog.setLevel(level=logging.INFO)
mfh = logging.handlers.RotatingFileHandler(options.logfile, maxBytes=209715200, backupCount=5)
Expand All @@ -111,13 +115,17 @@ def main(options):
mainlog.addHandler(mfh)

if options.project_name:
proj = mainlims.get_projects(name = options.project_name)
if not proj:
mainlog.warn('No project named {man_name} in Lims'.format(
man_name = options.project_name))
else:
if options.old:
proj = mainlims.get_projects(name = options.project_name)
if not proj:
mainlog.warn('No project named {man_name} in Lims'.format(
man_name = options.project_name))
P = PSUL(proj[0], samp_db, proj_db, options.upload, options.project_name, output_f, mainlog)
P.handle_project()
else:
host=get_configuration()['url']
pj_id=lims_db.query(DBProject.luid).filter(DBProject.name == options.project_name).scalar()
P = ProjectSQL(lims_db, mainlog, pj_id, host, couch)
else :
projects=create_projects_list(options, mainlims, mainlog)
masterProcess(options,projects, mainlims, mainlog)
Expand Down Expand Up @@ -189,14 +197,26 @@ def processPSUL(options, queue, logqueue):
open(lockfile,'w').close()
except:
proclog.error("cannot create lockfile {}".format(lockfile))
try:
proj=mylims.get_projects(name=projname)[0]
P = PSUL(proj, samp_db, proj_db, options.upload, options.project_name, options.output_f, proclog)
P.handle_project()
except :
error=sys.exc_info()
stack=traceback.extract_tb(error[2])
proclog.error("{0}:{1}\n{2}".format(error[0], error[1], formatStack(stack)))
if options.old:
try:
proj=mylims.get_projects(name=projname)[0]
P = PSUL(proj, samp_db, proj_db, options.upload, options.project_name, options.output_f, proclog)
P.handle_project()
except :
error=sys.exc_info()
stack=traceback.extract_tb(error[2])
proclog.error("{0}:{1}\n{2}".format(error[0], error[1], formatStack(stack)))
else:
try:
db_session=get_session()
pj_id=db.session.query(DBProject.luid).filter(DBProject.name == projname).scalar()
host=get_configuration()['url']
P = ProjectSQL(db_session, proclog, pj_id, host, couch)
P.save()
except :
error=sys.exc_info()
stack=traceback.extract_tb(error[2])
proclog.error("{0}:{1}\n{2}".format(error[0], error[1], formatStack(stack)))

try:
os.remove(lockfile)
Expand Down Expand Up @@ -335,6 +355,7 @@ def emit(self, record):
parser.add_option("-j", "--hours", dest = "hours",type='int', help = ("only handle projects modified in the last X hours"), default=None)
parser.add_option("-k", "--control", dest = "control", action="store_true", help = ("only perform a dry-run"), default=False)
parser.add_option("-i", "--input", dest = "input", help = ("path to the input file containing projects to update"), default=None)
parser.add_option("--old", dest = "old", help = ("use the old version of psul, via the API"), action="store_true", default=False)

(options, args) = parser.parse_args()
main(options)
Expand Down

0 comments on commit 0438ef8

Please sign in to comment.