forked from NPowl/Regatron-Custom-Device
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdodo.py
136 lines (102 loc) · 5.05 KB
/
dodo.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
from pathlib import Path
from doit.tools import result_dep
import shutil
import os
import xml.etree.ElementTree as ET
cwd = Path.cwd()
output_path = cwd / 'output'
file_list = []
#Write the release version to file
version = "1.0.4.11"
f= open("version.txt",'w')
f.write(version)
f.close()
# Load the custom device XML from a file
cd_xml = cwd / "G5 Regatron Custom Device" / "Custom Device G5 Regatron Custom Device.xml"
cd_xml_tree = ET.parse(cd_xml)
cd_xml_root = cd_xml_tree.getroot()
# Find the Version element and modify its text
version_element = cd_xml_root.find("Version")
if version_element is not None:
version_element.text = version # Modify the version here
# Save the modified XML back to the file
cd_xml_tree.write(cd_xml, encoding="utf-8", xml_declaration=True)
ET.register_namespace("i", "http://www.w3.org/2001/XMLSchema-instance")
ET.register_namespace("z", "http://schemas.microsoft.com/2003/10/Serialization/")
ET.register_namespace("", "http://schemas.datacontract.org/2004/07/NationalInstruments.PackageBuilder.Engine")
ET.register_namespace("d8p1","http://schemas.datacontract.org/2004/07/NationalInstruments.PackageBuilder.Plugins.LabVIEWNXG")
# Load the custom device package builder XML from file
package_xml = cwd / "G5 Regatron Custom Device" / "Regatron Custom Device.pbs"
package_xml_tree = ET.parse(package_xml)
package_xml_root = package_xml_tree.getroot()
# Define the namespaces
namespaces = {
"z": "http://schemas.microsoft.com/2003/10/Serialization/",
"default": "http://schemas.datacontract.org/2004/07/NationalInstruments.PackageBuilder.Engine"
}
# Find the Version element using namespaces
version_elements = package_xml_root.findall(".//default:Version", namespaces)
version_elements[0].text = version # set the new version
version_elements[1].text = version
# Save the modified XML back to the file
package_xml_tree.write(package_xml, encoding="utf-8", xml_declaration=True)
#create output folder structure:
folder_list = [
output_path,
output_path / 'build',
output_path / 'package',
]
for path in folder_list:
try:
os.mkdir(path)
except:
nothing = 0
#print("%s already exists" % (path))
def getListOfFiles(dirName):
# create a list of file and sub directories
# names in the given directory
listOfFile = os.listdir(dirName)
allFiles = list()
# Iterate over all the entries
for entry in listOfFile:
# Create full path
fullPath = os.path.join(dirName, entry)
# If entry is a directory then get the list of files in this directory
if os.path.isdir(fullPath):
allFiles = allFiles + getListOfFiles(fullPath)
else:
allFiles.append(fullPath)
return allFiles
###########################################################################
# This task builds the labview CSB-Interface-App.vi application and #
# Then it builds the nipm package based application, build_stm32, gen_dbc #
# and gen_manual tasks #
###########################################################################
def task_build_custom_device():
labiew_app_build_command_config = r'LabVIEWCLI -OperationName ExecuteBuildSpec -ProjectPath "C:\Git\Regatron-Custom-Device\G5 Regatron Custom Device\G5 Regatron Custom Device Custom Device.lvproj" -TargetName "My Computer" -BuildSpecName "Configuration Release" -LabVIEWPath "C:\Program Files\National Instruments\LabVIEW 2021\LabVIEW.exe"'
labiew_app_build_command_engine_windows = r'LabVIEWCLI -OperationName ExecuteBuildSpec -ProjectPath "C:\Git\Regatron-Custom-Device\G5 Regatron Custom Device\G5 Regatron Custom Device Custom Device.lvproj" -TargetName "My Computer" -BuildSpecName "Engine Release" -LabVIEWPath "C:\Program Files\National Instruments\LabVIEW 2021\LabVIEW.exe"'
labiew_app_build_command_engine_linux = r'LabVIEWCLI -OperationName ExecuteBuildSpec -ProjectPath "C:\Git\Regatron-Custom-Device\G5 Regatron Custom Device\G5 Regatron Custom Device Custom Device.lvproj" -TargetName "RT PXI Target - Linux x64" -BuildSpecName "Engine Release" -LabVIEWPath "C:\Program Files\National Instruments\LabVIEW 2021\LabVIEW.exe"'
dep_files = getListOfFiles(cwd / 'G5 Regatron Custom Device')
def clean_folder():
files = getListOfFiles(cwd / 'output')
for file in files:
print("Deleted File %s" % (file))
os.remove(file)
return{
"actions": [
clean_folder,
labiew_app_build_command_config,
labiew_app_build_command_engine_windows,
labiew_app_build_command_engine_linux,
],
"file_dep": dep_files,
"verbosity": 2,
}
def task_build_package():
packge_builder_command = r'"C:\Program Files\National Instruments\Package Builder\nipbcli" -o "C:\Git\Regatron-Custom-Device\G5 Regatron Custom Device\Regatron Custom Device.pbs" -b=packages'
return{
"actions": [
packge_builder_command
],
"uptodate": [result_dep('build_custom_device')]
}