math_vis: remove use of register_module
[blender-addons.git] / system_demo_mode / config.py
blob24e25be5f9ff263a853d5d191c9a96f60832fcab
1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 # <pep8 compliant>
21 import os
24 def blend_list(path):
25 for dirpath, dirnames, filenames in os.walk(path):
26 # skip '.git'
27 dirnames[:] = [d for d in dirnames if not d.startswith(".")]
28 for filename in filenames:
29 if filename.lower().endswith(".blend"):
30 filepath = os.path.join(dirpath, filename)
31 yield filepath
34 def generate(dirpath, random_order, **kwargs):
35 files = list(blend_list(dirpath))
36 if random_order:
37 import random
38 random.shuffle(files)
39 else:
40 files.sort()
42 config = []
43 for f in files:
44 defaults = kwargs.copy()
45 defaults["file"] = f
46 config.append(defaults)
48 return config, dirpath
51 def as_string(dirpath, random_order, exit, **kwargs):
52 """ Config loader is in demo_mode.py
53 """
54 cfg, dirpath = generate(dirpath, random_order, **kwargs)
56 # hint for reader, can be used if files are not found.
57 cfg_str = [
58 "# generated file\n",
59 "\n",
60 "# edit the search path so other systems may find the files below\n",
61 "# based on name only if the absolute paths cant be found\n",
62 "# Use '//' for current blend file path.\n",
63 "\n",
64 "search_path = %r\n" % dirpath,
65 "\n",
66 "exit = %r\n" % exit,
67 "\n",
70 # All these work but use nicest formatting!
71 if 0: # works but not nice to edit.
72 cfg_str += ["config = %r" % cfg]
73 elif 0:
74 import pprint
75 cfg_str += ["config = %s" % pprint.pformat(cfg, indent=0, width=120)]
76 elif 0:
77 cfg_str += [("config = %r" % cfg).replace("{", "\n {")]
78 else:
79 import pprint
81 def dict_as_kw(d):
82 return "dict(%s)" % ", ".join(("%s=%s" % (k, pprint.pformat(v))) for k, v in sorted(d.items()))
83 ident = " "
84 cfg_str += ["config = [\n"]
85 for cfg_item in cfg:
86 cfg_str += ["%s%s,\n" % (ident, dict_as_kw(cfg_item))]
87 cfg_str += ["%s]\n\n" % ident]
89 return "".join(cfg_str), dirpath