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 keys:')
0029 for line in re.split('\n',sqlplus.communicate('select unique ID from CMS_TRG_L1_CONF.EMTF_KEYS;')[0]):
0030 if myre.search(line) == None :
0031 print(line)
0032 print('Pick any of these keys as an argument next time you run this script')
0033 exit(0)
0034
0035
0036 key = sys.argv[1]
0037
0038 sqlplus = subprocess.Popen(sqlplusCmd,
0039 shell=False,
0040 stdout=subprocess.PIPE,
0041 stdin=subprocess.PIPE
0042 )
0043
0044
0045 queryKey = "select EMTF_KEY from CMS_TRG_L1_CONF.L1_TRG_CONF_KEYS where ID='{0}'".format(key)
0046
0047 for line in re.split('\n',sqlplus.communicate(queryKey+';')[0]):
0048 print(line)
0049 if re.search('/v',line) :
0050 key=line
0051
0052 print(key)
0053
0054 queryKeys = """
0055 select
0056 INFRA_KEYS.MTF7 as MTF7, INFRA_KEYS.AMC13 as AMC13, TOP_KEYS.HW as HW, TOP_KEYS.ALGO as ALGO
0057 from
0058 CMS_TRG_L1_CONF.EMTF_INFRA_KEYS INFRA_KEYS
0059 inner join
0060 (
0061 select
0062 HW, INFRA, ALGO
0063 from
0064 CMS_TRG_L1_CONF.EMTF_KEYS
0065 where
0066 ID = '{0}'
0067 ) TOP_KEYS
0068 on
0069 TOP_KEYS.INFRA = INFRA_KEYS.ID
0070 """.format(key)
0071
0072
0073 batch = {
0074 'HW' : 'hw.xml',
0075 'ALGO' : 'algo.xml',
0076 'MTF7' : 'mtf7.xml',
0077 'AMC13' : 'amc13.xml'
0078 }
0079
0080
0081 for config,fileName in batch.items():
0082
0083 sqlplus = subprocess.Popen(sqlplusCmd, shell=False, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
0084 with open(fileName,'w') as f:
0085 query = """
0086 select
0087 CLOBS.CONF
0088 from
0089 CMS_TRG_L1_CONF.EMTF_CLOBS CLOBS, ({0}) KEY
0090 where
0091 CLOBS.ID = KEY.{1}
0092 """.format(queryKeys, config)
0093
0094 for line in re.split('\n',sqlplus.communicate('\n'.join(['set linesize 200', 'set longchunksize 200000 long 200000 pages 0',query+';']))[0]):
0095 f.write('\n')
0096 f.write(line)
0097 f.close()
0098
0099 sqlplus = subprocess.Popen(sqlplusCmd, shell=False, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
0100 print('Following keys were found:')
0101 for line in re.split('\n',sqlplus.communicate(queryKeys+';')[0]):
0102 print(line)
0103
0104
0105 print('Results are saved in ' + ' '.join(batch.values()) + ' files')
0106