1414
1515import validators
1616import cherrypy
17+ import cx_Oracle
1718
1819from cmstoolbox import sitereadiness
1920from cmstoolbox .webtools import get_json
2021
2122from . import workflowinfo
2223from . import serverconfig
2324
25+ def errors_from_list (workflows ):
26+ """
27+ :param list workflows: A list of workflows that are in assistance-manual
28+ :returns: The errors for the workflows
29+ :rtype: dict
30+ """
31+ indict = {}
32+
33+ for workflow in workflows :
34+ base = workflowinfo .WorkflowInfo (workflow )
35+ prep_id = base .get_prep_id ()
36+ for wkf in set (workflowinfo .PrepIDInfo (prep_id ).get_workflows ()):
37+ indict .update (
38+ workflowinfo .WorkflowInfo (wkf ).get_errors (get_unreported = True )
39+ )
40+
41+ return indict
42+
43+
2444def open_location (data_location ):
2545 """
2646 This function assumes that the contents of the location is in JSON format.
@@ -30,8 +50,19 @@ def open_location(data_location):
3050 :returns: information in the JSON file
3151 :rtype: dict
3252 """
53+ config_dict = serverconfig .config_dict ()
54+
55+ if 'oracle' in config_dict :
56+ oracle_db_conn = cx_Oracle .connect (* config_dict ['oracle' ]) # pylint:disable=c-extension-no-member
57+ oracle_cursor = oracle_db_conn .cursor ()
58+ oracle_cursor .execute (
59+ "SELECT NAME FROM CMS_UNIFIED_ADMIN.workflow WHERE lower(STATUS) LIKE '%manual%'" )
60+ wkfs = [row for row , in oracle_cursor ]
61+ oracle_db_conn .close ()
62+ cherrypy .log ('Number of workflows from database: %i' % len (wkfs ))
63+ return errors_from_list (wkfs )
64+
3365 raw = None
34- indict = {}
3566
3667 if os .path .isfile (data_location ):
3768 with open (data_location , 'r' ) as input_file :
@@ -41,7 +72,7 @@ def open_location(data_location):
4172 components = urlparse .urlparse (data_location )
4273
4374 # Anything we need for the Shibboleth cookie could be in the config file
44- cookie_stuff = serverconfig . config_dict () ['data' ]
75+ cookie_stuff = config_dict ['data' ]
4576
4677 raw = get_json (components .netloc , components .path ,
4778 use_https = True ,
@@ -56,16 +87,10 @@ def open_location(data_location):
5687 if not (keys and isinstance (raw [keys [0 ]], list )):
5788 return raw
5889
59- for workflow , statuses in raw .iteritems ():
60- if True in ['manual' in status for status in statuses ]:
61- base = workflowinfo .WorkflowInfo (workflow )
62- prep_id = base .get_prep_id ()
63- for wkf in set (workflowinfo .PrepIDInfo (prep_id ).get_workflows ()):
64- indict .update (
65- workflowinfo .WorkflowInfo (wkf ).get_errors (get_unreported = True )
66- )
67-
68- return indict
90+ return errors_from_list ([
91+ workflow for workflow , statuses in raw .iteritems ()
92+ if True in ['manual' in status for status in statuses ]
93+ ])
6994
7095
7196def get_list_info (status_list ):
0 commit comments