forked from NREL/OpenStudio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a python script to concat all natvis files into a single one (f…
…or use with Visual Studio Code, on mac for example)
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,6 @@ test_fails.txt | |
*.sublime-project | ||
cmake-build-debug | ||
|
||
developer/msvc/Visualizers/all_concat.natvis | ||
.vscode/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
""" | ||
This small snippet will open all the *.natvis files and concat them into a | ||
single one to be able to use them in Visual Studio Code (for Mac for eg) | ||
vscode-cpptools expects only one visualizerFile currently | ||
""" | ||
|
||
import xml.etree.ElementTree as ET | ||
import glob as gb | ||
|
||
OUT_FILENAME = 'all_concat.natvis' | ||
|
||
|
||
def concat_all_natvis_files(): | ||
""" | ||
Main function | ||
""" | ||
natvis_files = gb.glob('*.natvis') | ||
if OUT_FILENAME in natvis_files: | ||
natvis_files.remove(OUT_FILENAME) | ||
|
||
# In order to avoid the ns0 prefix the default namespace should be set | ||
schema = 'http://schemas.microsoft.com/vstudio/debugger/natvis/2010' | ||
# before reading the XML data. | ||
ET.register_namespace('', schema) | ||
|
||
# Open the file first found | ||
print("Opening first: {}".format(natvis_files[0])) | ||
tree = ET.parse(natvis_files[0]) | ||
root = tree.getroot() | ||
|
||
ori_n_child = len(root) | ||
total_n_child = ori_n_child | ||
|
||
# Loop on the rest | ||
for fname in natvis_files[1:]: | ||
tree2 = ET.parse(fname) | ||
root2 = tree2.getroot() | ||
n_child = len(root2) | ||
print("Parsing '{}', {} children".format(fname, n_child)) | ||
total_n_child += n_child | ||
# Append each child or root2 to the first root | ||
for child in root2.iter(): | ||
root.append(child) | ||
|
||
final_n_child = len(root) | ||
if final_n_child == total_n_child: | ||
print("\nOK: Started with {}, Ended with {} children as " | ||
"expected".format(ori_n_child, final_n_child)) | ||
else: | ||
print("\nProblem: Started with {}, Ended with {} children, " | ||
"expected {}".format(ori_n_child, final_n_child, total_n_child)) | ||
|
||
print("\nSaving to {}".format(OUT_FILENAME)) | ||
tree.write(OUT_FILENAME, encoding='utf-8', xml_declaration=True) | ||
|
||
|
||
# If run from a terminal | ||
if __name__ == '__main__': | ||
concat_all_natvis_files() |