[Work][Python]Improve Spec SERT work flow
Environment: python 3.7
Key technique: BeautifulSoap
The SERT™ suite was created by the Standard Performance Evaluation Corporation (SPEC), the world’s leading organization for benchmarking expertise. The SPECpower Committee designed, implemented, and delivered the SERT suite, a next-generation tool set for measuring and evaluating the energy efficiency of servers. The SERT suite was created with the input from leaders of various global energy-efficiency programs and their stakeholders in order to accomodate their regional program requirements, as well as provide both summarized and detailed reports for use by potential customers
Task:
Due to we use Three-phase electrical power for testing SERT. We need revise all default-range and range value from listeners.xml. All value Multiply by three. It will take 0.5 hrs manual effort and make mistake easily. It we can revise value by script and this issue can be solved.
Solution:
from bs4 import BeautifulSoup as bsfileForReading = open("listeners.xml", 'r')
xmlString = fileForReading.read()
fileForReading.close()soup = bs(xmlString,'lxml')l=len(soup.findAll('range'))
tmp=''
tmp1=0
for i in range(l):
tmp=soup.findAll('range')[i].contents[0]
tmp1=float(tmp)*1.7
soup.findAll('range')[i].contents[0].replaceWith(str(tmp1))
l=len(soup.findAll('default-range'))
tmp=''
tmp1=0
for i in range(l):
tmp=soup.findAll('default-range')[i].contents[0]
tmp1=float(tmp)*1.7
soup.findAll('default-range')[i].contents[0].replaceWith(str(tmp1))fileForWriting = open("new_listeners.xml", 'w')
fileForWriting.write(str(soup))
fileForWriting.close()
Output:
Reference: