diff --git a/scripts/project_summary_upload_LIMS.py b/scripts/project_summary_upload_LIMS.py index e7c2622..fb3abca 100755 --- a/scripts/project_summary_upload_LIMS.py +++ b/scripts/project_summary_upload_LIMS.py @@ -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 @@ -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) @@ -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) @@ -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) @@ -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)