24
24
from pathlib import Path
25
25
26
26
import click
27
- from paths import Branch , get_chip_root , get_data_model_path , get_documentation_file_path , get_in_progress_defines
28
27
29
- # Use the get_in_progress_defines() function to fetch the in-progress defines
30
- CURRENT_IN_PROGRESS_DEFINES = get_in_progress_defines ()
31
-
32
- # Replace hardcoded paths with dynamic paths using paths.py functions
33
- DEFAULT_CHIP_ROOT = get_chip_root ()
34
- DEFAULT_OUTPUT_DIR_1_3 = get_data_model_path (Branch .V1_3 )
35
- DEFAULT_OUTPUT_DIR_IN_PROGRESS = get_data_model_path (Branch .IN_PROGRESS )
36
- DEFAULT_OUTPUT_DIR_TOT = get_data_model_path (Branch .MASTER )
37
- DEFAULT_DOCUMENTATION_FILE = get_documentation_file_path ()
28
+ DEFAULT_CHIP_ROOT = os .path .abspath (
29
+ os .path .join (os .path .dirname (__file__ ), '..' , '..' ))
30
+ DEFAULT_OUTPUT_DIR_1_3 = os .path .abspath (
31
+ os .path .join (DEFAULT_CHIP_ROOT , 'data_model' , '1.3' ))
32
+ DEFAULT_OUTPUT_DIR_IN_PROGRESS = os .path .abspath (
33
+ os .path .join (DEFAULT_CHIP_ROOT , 'data_model' , 'in_progress' ))
34
+ DEFAULT_OUTPUT_DIR_TOT = os .path .abspath (
35
+ os .path .join (DEFAULT_CHIP_ROOT , 'data_model' , 'master' ))
36
+ DEFAULT_DOCUMENTATION_FILE = os .path .abspath (
37
+ os .path .join (DEFAULT_CHIP_ROOT , 'docs' , 'spec_clusters.md' ))
38
+
39
+ # questions
40
+ # is energy-calendar still in?
41
+ # is heat-pump out? wasn't in 0.7
42
+ # location-cluster - is this define gone now?
43
+ # queuedpreset - is this define gone now?
44
+ CURRENT_IN_PROGRESS_DEFINES = ['aliro' , 'atomicwrites' , 'battery-storage' , 'device-location' , 'e2e-jf' , 'energy-calendar' , 'energy-drlc' ,
45
+ 'energy-management' , 'heat-pump' , 'hrap-1' , 'hvac' , 'matter-fabric-synchronization' , 'metering' , 'secondary-net' ,
46
+ 'service-area-cluster' , 'solar-power' , 'tcp' , 'water-heater' , 'wifiSetup' ]
38
47
39
48
40
49
def get_xml_path (filename , output_dir ):
@@ -81,6 +90,7 @@ def make_asciidoc(target: str, include_in_progress: str, spec_dir: str, dry_run:
81
90
'--include-in-progress' ,
82
91
type = click .Choice (['All' , 'None' , 'Current' ]), default = 'All' )
83
92
def main (scraper , spec_root , output_dir , dry_run , include_in_progress ):
93
+ # Clusters need to be scraped first because the cluster directory is passed to the device type directory
84
94
if not output_dir :
85
95
output_dir_map = {'All' : DEFAULT_OUTPUT_DIR_TOT , 'None' : DEFAULT_OUTPUT_DIR_1_3 , 'Current' : DEFAULT_OUTPUT_DIR_IN_PROGRESS }
86
96
output_dir = output_dir_map [include_in_progress ]
@@ -93,28 +103,30 @@ def main(scraper, spec_root, output_dir, dry_run, include_in_progress):
93
103
94
104
def scrape_clusters (scraper , spec_root , output_dir , dry_run , include_in_progress ):
95
105
src_dir = os .path .abspath (os .path .join (spec_root , 'src' ))
96
- sdm_clusters_dir = os .path .abspath (os .path .join (src_dir , 'service_device_management' ))
106
+ sdm_clusters_dir = os .path .abspath (
107
+ os .path .join (src_dir , 'service_device_management' ))
97
108
app_clusters_dir = os .path .abspath (os .path .join (src_dir , 'app_clusters' ))
98
109
dm_clusters_dir = os .path .abspath (os .path .join (src_dir , 'data_model' ))
99
- media_clusters_dir = os .path .abspath (os . path . join ( app_clusters_dir , 'media' ))
100
-
101
- clusters_output_dir = os .path .join (output_dir , 'clusters' )
110
+ media_clusters_dir = os .path .abspath (
111
+ os . path . join ( app_clusters_dir , 'media' ))
112
+ clusters_output_dir = os .path .abspath ( os . path . join (output_dir , 'clusters' ) )
102
113
103
114
if not os .path .exists (clusters_output_dir ):
104
115
os .makedirs (clusters_output_dir )
105
116
106
- print ('Generating main spec to get file include list - this may take a few minutes' )
117
+ print ('Generating main spec to get file include list - this make take a few minutes' )
107
118
main_out = make_asciidoc ('pdf' , include_in_progress , spec_root , dry_run )
108
- print ('Generating cluster spec to get file include list - this may take a few minutes' )
119
+ print ('Generating cluster spec to get file include list - this make take a few minutes' )
109
120
cluster_out = make_asciidoc ('pdf-appclusters-book' , include_in_progress , spec_root , dry_run )
110
121
111
122
def scrape_cluster (filename : str ) -> None :
112
123
base = Path (filename ).stem
113
124
if base not in main_out and base not in cluster_out :
114
- print (f'Skipping file: { base } as it is not compiled into the asciidoc' )
125
+ print (f'skipping file: { base } as it is not compiled into the asciidoc' )
115
126
return
116
127
xml_path = get_xml_path (filename , clusters_output_dir )
117
- cmd = [scraper , 'cluster' , '-i' , filename , '-o' , xml_path , '-nd' ]
128
+ cmd = [scraper , 'cluster' , '-i' , filename , '-o' ,
129
+ xml_path , '-nd' ]
118
130
if include_in_progress == 'All' :
119
131
cmd .extend (['--define' , 'in-progress' ])
120
132
elif include_in_progress == 'Current' :
@@ -138,29 +150,33 @@ def scrape_all_clusters(dir: str, exclude_list: list[str] = []) -> None:
138
150
tree = ElementTree .parse (f'{ xml_path } ' )
139
151
root = tree .getroot ()
140
152
cluster = next (root .iter ('cluster' ))
153
+ # If there's no cluster ID table, this isn't a cluster
141
154
try :
142
155
next (cluster .iter ('clusterIds' ))
143
156
except StopIteration :
157
+ # If there's no cluster ID table, this isn't a cluster just some kind of intro adoc
144
158
print (f'Removing file { xml_path } as it does not include any cluster definitions' )
145
159
os .remove (xml_path )
146
160
continue
147
161
148
162
149
163
def scrape_device_types (scraper , spec_root , output_dir , dry_run , include_in_progress ):
150
- device_type_dir = os .path .abspath (os .path .join (spec_root , 'src' , 'device_types' ))
151
- device_types_output_dir = os .path .abspath (os .path .join (output_dir , 'device_types' ))
164
+ device_type_dir = os .path .abspath (
165
+ os .path .join (spec_root , 'src' , 'device_types' ))
166
+ device_types_output_dir = os .path .abspath (
167
+ os .path .join (output_dir , 'device_types' ))
152
168
clusters_output_dir = os .path .abspath (os .path .join (output_dir , 'clusters' ))
153
169
154
170
if not os .path .exists (device_types_output_dir ):
155
171
os .makedirs (device_types_output_dir )
156
172
157
- print ('Generating device type library to get file include list - this may take a few minutes' )
173
+ print ('Generating device type library to get file include list - this make take a few minutes' )
158
174
device_type_output = make_asciidoc ('pdf-devicelibrary-book' , include_in_progress , spec_root , dry_run )
159
175
160
176
def scrape_device_type (filename : str ) -> None :
161
177
base = Path (filename ).stem
162
178
if base not in device_type_output :
163
- print (f'Skipping file: { filename } as it is not compiled into the asciidoc' )
179
+ print (f'skipping file: { filename } as it is not compiled into the asciidoc' )
164
180
return
165
181
xml_path = get_xml_path (filename , device_types_output_dir )
166
182
cmd = [scraper , 'devicetype' , '-c' , '-cls' , clusters_output_dir ,
0 commit comments