-
Notifications
You must be signed in to change notification settings - Fork 0
/
rp_xml_update_and_zip.py
49 lines (35 loc) · 1.33 KB
/
rp_xml_update_and_zip.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import xml.etree.ElementTree as ET
import os
import zipfile
import sys
def update_xml_file(xml_file):
tree = ET.parse(xml_file)
root = tree.getroot()
testsuites = root.findall('testsuite')
if 'file' in testsuites[0].attrib and testsuites[0].attrib['failures'] != "0":
return
elif 'file' in testsuites[0].attrib:
root.remove(testsuites[0])
parent_testsuite = testsuites[1]
for testsuite in testsuites[2:]:
parent_testsuite.append(testsuite)
root.remove(testsuite)
tree.write(xml_file, encoding='utf-8', xml_declaration=True)
def create_zip_file(directory):
# Get all the xml files starting with "junit"
xml_files = [os.path.join(directory, filename) for filename in os.listdir(directory) if filename.startswith('junit')]
if not xml_files:
return None
# Process each XML file
for xml_file in xml_files:
update_xml_file(xml_file)
# Create a zip file and add the updated XML files
zip_file = os.path.join(directory, 'periodic-job.zip')
with zipfile.ZipFile(zip_file, 'w') as zipf:
for modified_file in xml_files:
zipf.write(modified_file, os.path.basename(modified_file))
return zip_file
# Directory path containing junit xml files
directory = sys.argv[1]
zip_file = create_zip_file(directory)
print(zip_file)