I have a file with sections for different environments as follows:
#developmentsectionstart
# development environment only
context 'environment => development' do
let(:trusted_facts) do
super().merge('pp_apptier' => 'development')
end
#developmentsectionend
#trainingsectionstart
# training environment only
context 'environment => training' do
let(:trusted_facts) do
super().merge('pp_apptier' => 'training')
end
#trainingsectionend
I need to be able to delete sections based on environments entered by the user which I put in a list.
e.g. envlist
is the list entered by user and allenvlist
are all the environments in the file.
I need to remove all sections not entered by the user e.g. test, stress & training
i.e. everything from #trainingsectionstart
to #trainingsectionend
etc.
I tried passing the environments entered by the user as a variable into re.sub
.
Not working.
envlist = ['development','qa','production']
allenvlist = ['development','test','qa','stress','training','production']
new_env_list =[]
for element in allenvlist:
if element not in envlist:
new_env_list.append(element)
for i in range(0,len(new_env_list)):
sectionstart = '#'+new_env_list[i]+'start'
sectionend = '#'+new_env_list[i]+'end'
newdata = re.sub(r'sectionstart.*?sectionend','', filedata, flags=re.DOTALL)