diff --git a/python/BlackDynamite/runselector.py b/python/BlackDynamite/runselector.py index a87078c..1108df0 100755 --- a/python/BlackDynamite/runselector.py +++ b/python/BlackDynamite/runselector.py @@ -1,112 +1,114 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # -*- py-which-shell: "python"; -*- __all__ = [ "RunSelector" ] import copy import jobselector import base import run import job import sys import re class RunSelector(object): """ """ def selectRuns(self,run_constraints,job_constraints,sort_by = None,quiet=False,binary_operator = "and"): -# print 'AAAAAAAAA ' + binary_operator - if (type(run_constraints) == dict): if ("run_constraints" in run_constraints): run_constraints = run_constraints["run_constraints"] + elif "run_id" in run_constraints: + run_constraints = ['id = {0}'.format(run_constraints['run_id'])] else: run_constraints = [] if (type(job_constraints) == dict): if ("job_constraints" in job_constraints): job_constraints = job_constraints["job_constraints"] + elif "job_id" in job_constraints: + job_constraints = ['id = {0}'.format(job_constraints['job_id'])] else: job_constraints = [] myjob = job.Job(self.base) myjob.prepare() myjob.setConstraint(job_constraints) myrun = run.Run(self.base) myrun.prepare() myrun.setConstraint(run_constraints) if ("machine_name" in myrun.entries): if (len(myrun["machine_name"]) > 1): myrun["machine_name"] = myrun["machine_name"][0] condition_job, params_job = myjob.makeMatchingCondition(binary_operator) condition_run, params_run = myrun.makeMatchingCondition(binary_operator) condition = '' if condition_job: condition = '(' + condition_job + ')' if (condition and condition_run): condition += ' and ' if (condition_run): condition += '(' + condition_run + ')' if (condition): condition += ' and ' condition += " runs.job_id = jobs.id " params = params_job + params_run if (not type(sort_by) == list and sort_by is not None): sort_by = [sort_by] order_condition = "" if (sort_by is not None): order_condition = " ORDER BY (" for cond in sort_by: order_condition += cond + "," order_condition = order_condition[:len(order_condition)-1] + ")" # print ("order condition: " + order_condition) request = "SELECT * FROM {0}.jobs,{0}.runs ".format(self.base.schema) request += " WHERE " + condition request += order_condition # print (condition) # print (request) # print (params) curs = self.base.performRequest(request, params) run_list = self.buildJoinedList(myjob,myrun,curs) #run_list = self.getMatchedObjectList(myrun,myjob,order_condition) if (not quiet): print ("Selected runs are: " + str([r[0].id for r in run_list])) print ("Selected jobs are: " + str([r[0]["job_id"] for r in run_list])) return run_list def buildJoinedList(self, job_object, run_object, curs): coljob_info = self.base.getColumnProperties(job_object) colrun_info = self.base.getColumnProperties(run_object) run_list = [] for entries in curs: jobj = copy.deepcopy(job_object) robj = copy.deepcopy(run_object) ncoljob = len(coljob_info) ncolrun = len(colrun_info) for i in range(0,ncoljob): col_name = coljob_info[i][0] jobj[col_name] = entries[i] jobj.id = jobj["id"] for i in range(0,ncolrun): col_name = colrun_info[i][0] robj[col_name] = entries[i+ncoljob] robj.id = robj["id"] run_list.append([robj,jobj]) return run_list def __init__ (self,base): self.base = base