[Bf-blender-cvs] [4dcaac6d330] master: Cleanup: comment printing when loading XML

Campbell Barton noreply at git.blender.org
Wed Feb 2 11:10:36 CET 2022


Commit: 4dcaac6d33026759faad186542b6cfae0d87e4e9
Author: Campbell Barton
Date:   Wed Feb 2 21:05:16 2022 +1100
Branches: master
https://developer.blender.org/rB4dcaac6d33026759faad186542b6cfae0d87e4e9

Cleanup: comment printing when loading XML

This printed text when the theme was changes from the quick setup.
Also use a context manager for opening a file.

===================================================================

M	release/scripts/modules/rna_xml.py

===================================================================

diff --git a/release/scripts/modules/rna_xml.py b/release/scripts/modules/rna_xml.py
index 7f7b273c42b..aa8841c5efe 100644
--- a/release/scripts/modules/rna_xml.py
+++ b/release/scripts/modules/rna_xml.py
@@ -298,7 +298,7 @@ def xml2rna(
                         del value_xml_split
                     tp_name = 'ARRAY'
 
-#                print("  %s.%s (%s) --- %s" % (type(value).__name__, attr, tp_name, subvalue_type))
+                    # print("  %s.%s (%s) --- %s" % (type(value).__name__, attr, tp_name, subvalue_type))
                 try:
                     setattr(value, attr, value_xml_coerce)
                 except ValueError:
@@ -340,7 +340,6 @@ def xml2rna(
 
                     else:
                         # print(elems)
-
                         if len(elems) == 1:
                             # sub node named by its type
                             child_xml_real, = elems
@@ -376,7 +375,6 @@ def _get_context_val(context, path):
 
 
 def xml_file_run(context, filepath, rna_map):
-
     import xml.dom.minidom
 
     xml_nodes = xml.dom.minidom.parse(filepath)
@@ -391,27 +389,25 @@ def xml_file_run(context, filepath, rna_map):
         value = _get_context_val(context, rna_path)
 
         if value is not Ellipsis and value is not None:
-            print("  loading XML: %r -> %r" % (filepath, rna_path))
+            # print("  loading XML: %r -> %r" % (filepath, rna_path))
             xml2rna(xml_node, root_rna=value)
 
 
 def xml_file_write(context, filepath, rna_map, *, skip_typemap=None):
-
-    file = open(filepath, "w", encoding="utf-8")
-    fw = file.write
-
-    fw("<bpy>\n")
-
-    for rna_path, _xml_tag in rna_map:
-        # xml_tag is ignored, we get this from the rna
-        value = _get_context_val(context, rna_path)
-        rna2xml(fw,
+    with open(filepath, "w", encoding="utf-8") as file:
+        fw = file.write
+        fw("<bpy>\n")
+
+        for rna_path, _xml_tag in rna_map:
+            # xml_tag is ignored, we get this from the rna
+            value = _get_context_val(context, rna_path)
+            rna2xml(
+                fw=fw,
                 root_rna=value,
                 method='ATTR',
                 root_ident="  ",
                 ident_val="  ",
                 skip_typemap=skip_typemap,
-                )
+            )
 
-    fw("</bpy>\n")
-    file.close()
+        fw("</bpy>\n")



More information about the Bf-blender-cvs mailing list