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