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

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-03-29 10:19:48 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-03-29 10:19:48 +0400
commit58c2bec4eb2d8c4f2a29a37179fbd3d050814f79 (patch)
tree502f144e8fcad2b68b822e710573ddfdd8fab102 /system_demo_mode/config.py
parent1d838454afb884cf7b288afc7b6915c779230ecb (diff)
work in progress addon: demo mode, use for easy setup for looping over blend files, rendering, playing, switching screens.
Diffstat (limited to 'system_demo_mode/config.py')
-rw-r--r--system_demo_mode/config.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/system_demo_mode/config.py b/system_demo_mode/config.py
new file mode 100644
index 00000000..6ef731fc
--- /dev/null
+++ b/system_demo_mode/config.py
@@ -0,0 +1,71 @@
+import os
+
+def blend_list(path):
+ for dirpath, dirnames, filenames in os.walk(path):
+
+ # skip '.svn'
+ if dirpath.startswith("."):
+ continue
+
+ for filename in filenames:
+ if filename.lower().endswith(".blend"):
+ filepath = os.path.join(dirpath, filename)
+ yield filepath
+
+
+def generate(dirpath, random_order, **kwargs):
+
+ # incase file is selected!
+ if not os.path.exists(dirpath) or not os.path.isdir(dirpath):
+ dirpath = os.path.dirname(dirpath)
+
+ files = list(blend_list(dirpath))
+ if random_order:
+ import random
+ random.shuffle(files)
+ else:
+ files.sort()
+
+ config = []
+ for f in files:
+ defaults = kwargs.copy()
+ defaults["file"] = f
+ config.append(defaults)
+
+ return config, dirpath
+
+
+def as_string(dirpath, random_order, **kwargs):
+ cfg, dirpath = generate(dirpath, random_order, **kwargs)
+
+ # hint for reader, can be used if files are not found.
+ cfg_str = []
+ cfg_str += ["# generated file\n"]
+ cfg_str += ["\n"]
+ cfg_str += ["# edit the search path so other systems may find the files below\n"]
+ cfg_str += ["# based on name only if the absolute paths cant be found\n"]
+ cfg_str += ["\n"]
+ cfg_str += ["search_path = %r\n" % dirpath]
+ cfg_str += ["\n"]
+
+
+ # All these work but use nicest formatting!
+ if 0: # works but not nice to edit.
+ cfg_str += ["config = %r" % cfg]
+ elif 0:
+ import pprint
+ cfg_str += ["config = %s" % pprint.pformat(cfg, indent=0, width=120)]
+ elif 0:
+ cfg_str += [("config = %r" % cfg).replace("{", "\n {")]
+ else:
+ import pprint
+ def dict_as_kw(d):
+ return "dict(%s)" % ", ".join(("%s=%s" % (k, pprint.pformat(v))) for k, v in sorted(d.items()))
+ ident = " "
+ cfg_str += ["config = [\n"]
+ for cfg_item in cfg:
+ cfg_str += ["%s%s,\n" % (ident, dict_as_kw(cfg_item))]
+ cfg_str += ["%s]\n\n" % ident]
+
+
+ return "".join(cfg_str), dirpath