-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparse_config_xml.py
30 lines (23 loc) · 1.04 KB
/
parse_config_xml.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import re
import time
import pandas as pd
import requests
from config import JENKINS_USER_ID, JENKINS_USER_TOKEN, JENKINS_PROJECT
if __name__ == '__main__':
df = pd.read_excel('jenkins_report.xlsx')
data = df.to_dict('records')
data = [d for d in data if d['project'] == JENKINS_PROJECT]
for d in data:
if d['class'] != 'FreeStyleProject':
continue
resp = requests.get(f"{d['url']}/config.xml", auth=(JENKINS_USER_ID, JENKINS_USER_TOKEN))
resp_text = resp.text
if '401 Unauthorized' in resp_text:
raise Exception('HTTP ERROR 401 Unauthorized')
d['python_script'] = re.findall(r'qa_project/.*\.py', resp_text) or ''
d['triggers'] = re.findall(r'<spec>(.*?)</spec>', resp_text) or ''
time.sleep(0.1) # Slow down the access rate to mitigate server load.
df = pd.DataFrame(data)
columns = ['class', 'folder', 'project', 'url', 'name', 'triggers', 'python_script']
df = df.reindex(columns=columns)
df.to_excel(f'{JENKINS_PROJECT}.xlsx', index=False)