Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-01-10 19:08:12 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-01-10 19:08:12 +0400
commit057d6e881575a0415c7cec7778d5e8f89e8f9110 (patch)
tree1a4086ecba4ae8e5d62422259969ffc46cf9d652 /release/scripts/modules/rna_xml.py
parent278179e0c07ac1bc615f77a6a91a51422efe4e4f (diff)
initial support for XML presets, these have the advantage...
- missing attributes are ignored and don't error out like they would on a script when the API changes. - don't run code (secure to run from untrusted sources). use xml presets for themes.
Diffstat (limited to 'release/scripts/modules/rna_xml.py')
-rw-r--r--release/scripts/modules/rna_xml.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/release/scripts/modules/rna_xml.py b/release/scripts/modules/rna_xml.py
index 1a0cf4bab9d..2b53ddcd941 100644
--- a/release/scripts/modules/rna_xml.py
+++ b/release/scripts/modules/rna_xml.py
@@ -298,3 +298,40 @@ def xml2rna(root_xml,
pass
rna2xml_node(root_xml, root_rna)
+
+
+
+# -----------------------------------------------------------------------------
+# Utility function used by presets.
+# The idea is you can run a preset like a script with a few args.
+#
+# This roughly matches the operator 'bpy.ops.script.python_file_run'
+
+def xml_file_run(context, filepath, rna_map):
+
+ import rna_xml
+ import xml.dom.minidom
+
+ xml_nodes = xml.dom.minidom.parse(filepath)
+ bpy_xml = xml_nodes.getElementsByTagName("bpy")[0]
+
+ for rna_path, xml_tag in rna_map:
+
+ # first get xml
+ # TODO, error check
+ xml_node = bpy_xml.getElementsByTagName(xml_tag)[0]
+
+ # now get
+ rna_path_full = "context." + rna_path
+ try:
+ value = eval(rna_path_full)
+ except:
+ import traceback
+ traceback.print_exc()
+ print("Error: %r could not be found" % rna_path_full)
+
+ value = Ellipsis
+
+ if value is not Ellipsis and value is not None:
+ print("Loading XML: %r" % rna_path_full)
+ rna_xml.xml2rna(xml_node, root_rna=value)