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