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-11 18:14:04 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-01-11 18:14:04 +0400
commitb308e613126f8c89e954705aa512a3ef6a1f551d (patch)
tree4a875450b2ba9766fbdf4914e8cb003e8132497c /release/scripts/modules
parent98bdf0274b1052efe25b6216f488d2a40fa43d1c (diff)
parentcda5d1769d71832a6b04ed6c91bac101c482e5f7 (diff)
svn merge ^/trunk/blender -r43220:43278 --accept postpone
Diffstat (limited to 'release/scripts/modules')
-rw-r--r--release/scripts/modules/bpy/utils.py6
-rw-r--r--release/scripts/modules/rna_xml.py82
2 files changed, 78 insertions, 10 deletions
diff --git a/release/scripts/modules/bpy/utils.py b/release/scripts/modules/bpy/utils.py
index 6fd15c146f2..442d257b237 100644
--- a/release/scripts/modules/bpy/utils.py
+++ b/release/scripts/modules/bpy/utils.py
@@ -408,7 +408,7 @@ def smpte_from_frame(frame, fps=None, fps_base=None):
return smpte_from_seconds((frame * fps_base) / fps, fps)
-def preset_find(name, preset_path, display_name=False):
+def preset_find(name, preset_path, display_name=False, ext=".py"):
if not name:
return None
@@ -417,11 +417,11 @@ def preset_find(name, preset_path, display_name=False):
if display_name:
filename = ""
for fn in _os.listdir(directory):
- if fn.endswith(".py") and name == _bpy.path.display_name(fn):
+ if fn.endswith(ext) and name == _bpy.path.display_name(fn):
filename = fn
break
else:
- filename = name + ".py"
+ filename = name + ext
if filename:
filepath = _os.path.join(directory, filename)
diff --git a/release/scripts/modules/rna_xml.py b/release/scripts/modules/rna_xml.py
index 1a0cf4bab9d..634c74178fa 100644
--- a/release/scripts/modules/rna_xml.py
+++ b/release/scripts/modules/rna_xml.py
@@ -32,7 +32,13 @@ def build_property_typemap(skip_classes):
if issubclass(cls, skip_classes):
continue
- properties = cls.bl_rna.properties.keys()
+ ## to support skip-save we cant get all props
+ # properties = cls.bl_rna.properties.keys()
+ properties = []
+ for prop_id, prop in cls.bl_rna.properties.items():
+ if not prop.is_skip_save:
+ properties.append(prop_id)
+
properties.remove("rna_type")
property_typemap[attr] = properties
@@ -47,7 +53,8 @@ def rna2xml(fw=print_ln,
root_node="",
root_rna=None, # must be set
root_rna_skip=set(),
- ident_val=" ",
+ root_ident="",
+ ident_val=" ",
skip_classes=(bpy.types.Operator,
bpy.types.Panel,
bpy.types.KeyingSet,
@@ -173,10 +180,11 @@ def rna2xml(fw=print_ln,
# needs re-workign to be generic
if root_node:
- fw("<%s>\n" % root_node)
+ fw("%s<%s>\n" % (root_ident, root_node))
# bpy.data
if method == 'DATA':
+ ident = root_ident + ident_val
for attr in dir(root_rna):
# exceptions
@@ -192,16 +200,16 @@ def rna2xml(fw=print_ln,
ls = None
if type(ls) == list:
- fw("%s<%s>\n" % (ident_val, attr))
+ fw("%s<%s>\n" % (ident, attr))
for blend_id in ls:
- rna2xml_node(ident_val + ident_val, blend_id, None)
+ rna2xml_node(ident + ident_val, blend_id, None)
fw("%s</%s>\n" % (ident_val, attr))
# any attribute
elif method == 'ATTR':
- rna2xml_node("", root_rna, None)
+ rna2xml_node(root_ident, root_rna, None)
if root_node:
- fw("</%s>\n" % root_node)
+ fw("%s</%s>\n" % (root_ident, root_node))
def xml2rna(root_xml,
@@ -298,3 +306,63 @@ 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 _get_context_val(context, path):
+ path_full = "context." + path
+ try:
+ value = eval(path_full)
+ except:
+ import traceback
+ traceback.print_exc()
+ print("Error: %r could not be found" % path_full)
+
+ value = Ellipsis
+
+ return value
+
+def xml_file_run(context, filepath, rna_map):
+
+ 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]
+
+ value = _get_context_val(context, rna_path)
+
+ if value is not Ellipsis and value is not None:
+ print(" loading XML: %r" % rna_path)
+ xml2rna(xml_node, root_rna=value)
+
+
+def xml_file_write(context, filepath, rna_map):
+
+ 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,
+ root_rna=value,
+ method='ATTR',
+ root_ident=" ",
+ ident_val=" ")
+
+ fw("</bpy>\n")
+ file.close()