File indexing completed on 2023-03-17 11:14:28
0001 from __future__ import print_function
0002 import re
0003 import os, sys, shutil
0004 import subprocess
0005 """
0006 A simple helper script that provided with no arguments dumps a list of
0007 top-level keys, and provided with any key from this list as an argument,
0008 dumps a list of sub-keys and saves corresponding configuration to local
0009 files.
0010 """
0011
0012
0013 sqlplusCmd = ['env',
0014 'sqlplus',
0015 '-S',
0016 'cms_trg_r/@cms_omds_adg'
0017 ]
0018
0019 if hash( sqlplusCmd[-1] ) != 1687624727082866629:
0020 print('Do not forget to plug password to this script')
0021 print('Exiting.')
0022 exit(0)
0023
0024 myre = re.compile(r'(ID)|(-{80})')
0025
0026
0027 if len(sys.argv) == 1:
0028 sqlplus = subprocess.Popen(sqlplusCmd, shell=False, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
0029 print('No args specified, querying and printing only top-level config keys:')
0030 for line in re.split('\n',sqlplus.communicate('select unique ID from CMS_TRG_L1_CONF.UGT_KEYS;')[0]):
0031 if myre.search(line) == None :
0032 print(line)
0033 sqlplus = subprocess.Popen(sqlplusCmd, shell=False, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
0034 print('No args specified, querying and printing only top-level Run Settings keys:')
0035 for line in re.split('\n',sqlplus.communicate('select unique ID from CMS_TRG_L1_CONF.UGT_RS_KEYS;')[0]):
0036 if myre.search(line) == None :
0037 print(line)
0038 print('Pick any of these keys as an argument next time you run this script')
0039 exit(0)
0040
0041
0042 key = sys.argv[1]
0043 rsKey = sys.argv[2]
0044
0045
0046 queryKey = "select UGT_KEY from CMS_TRG_L1_CONF.L1_TRG_CONF_KEYS where ID='{0}'".format(key)
0047 queryRsKey = "select UGT_RS_KEY from CMS_TRG_L1_CONF.L1_TRG_RS_KEYS where ID='{0}'".format(rsKey)
0048
0049 sqlplus = subprocess.Popen(sqlplusCmd, shell=False, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
0050 for line in re.split('\n',sqlplus.communicate(queryKey+';')[0]):
0051 print(line)
0052 if re.search('/v',line) :
0053 key=line
0054
0055 sqlplus = subprocess.Popen(sqlplusCmd, shell=False, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
0056 for line in re.split('\n',sqlplus.communicate(queryRsKey+';')[0]):
0057 print(line)
0058 if re.search('/v',line) :
0059 rsKey=line
0060
0061 print(key+":"+rsKey)
0062
0063 queryKeys = """
0064 select
0065 ALGOBX_MASK, ALGO_FINOR_MASK, ALGO_FINOR_VETO, ALGO_PRESCALE
0066 from
0067 CMS_TRG_L1_CONF.UGT_RS_KEYS
0068 where
0069 ID = '{0}'
0070 """.format(rsKey)
0071
0072 with open("menu.xml",'w') as f:
0073 sqlplus = subprocess.Popen(sqlplusCmd, shell=False, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
0074 query = """
0075 select
0076 CONF
0077 from
0078 CMS_TRG_L1_CONF.UGT_L1_MENU MENU
0079 inner join
0080 (
0081 select
0082 L1_MENU
0083 from
0084 CMS_TRG_L1_CONF.UGT_KEYS
0085 where
0086 ID = '{0}'
0087 ) TOP_KEYS
0088 on
0089 TOP_KEYS.L1_MENU = MENU.ID
0090 """.format(key)
0091 for line in re.split('\n',sqlplus.communicate('\n'.join(['set linesize 20000', 'set longchunksize 20000000 long 20000000 pages 0',query+';']))[0]):
0092 f.write('\n')
0093 f.write(line)
0094 f.close()
0095
0096
0097 batch = {
0098 'ALGOBX_MASK' : 'algobx_mask.xml',
0099 'ALGO_FINOR_MASK' : 'algo_finor_mask.xml',
0100 'ALGO_FINOR_VETO' : 'algo_finor_veto.xml',
0101 'ALGO_PRESCALE' : 'algo_prescale.xml'
0102 }
0103
0104
0105 for config,fileName in batch.items():
0106
0107 sqlplus = subprocess.Popen(sqlplusCmd, shell=False, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
0108 with open(fileName,'w') as f:
0109 query = """
0110 select
0111 CLOBS.CONF
0112 from
0113 CMS_TRG_L1_CONF.UGT_RS_CLOBS CLOBS, ({0}) KEY
0114 where
0115 CLOBS.ID = KEY.{1}
0116 """.format(queryKeys, config)
0117
0118 for line in re.split('\n',sqlplus.communicate('\n'.join(['set linesize 200', 'set longchunksize 200000 long 200000 pages 0',query+';']))[0]):
0119 f.write('\n')
0120 f.write(line)
0121 f.close()
0122
0123
0124 sqlplus = subprocess.Popen(sqlplusCmd, shell=False, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
0125 print('Following keys were found:')
0126 for line in re.split('\n',sqlplus.communicate(queryKeys+';')[0]):
0127 print(line)
0128
0129 print('Results are saved in ' + ' '.join(batch.values()) + ' files')
0130