1 # SPDX-FileCopyrightText: 2011-2023 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
12 # -----------------------------------------------------------------------------
15 def round_float_32(f
):
16 from struct
import pack
, unpack
17 return unpack("f", pack("f", f
))[0]
21 f_round
= round_float_32(f
)
23 f_str_frac
= f_str
.partition(".")[2]
26 for i
in range(1, len(f_str_frac
)):
28 f_test_round
= round_float_32(f_test
)
29 if f_test_round
== f_round
:
30 return "%.*f" % (i
, f_test
)
35 from pprint
import pformat
36 # Float's are originally 32 bit, regular pretty print
37 # shows them with many decimal places (not so pretty).
43 # -----------------------------------------------------------------------------
44 # Configuration Generation
47 for dirpath
, dirnames
, filenames
in os
.walk(path
):
49 dirnames
[:] = [d
for d
in dirnames
if not d
.startswith(".")]
50 for filename
in filenames
:
51 if filename
.lower().endswith(".blend"):
52 filepath
= os
.path
.join(dirpath
, filename
)
56 def generate(dirpath
, random_order
, **kwargs
):
57 files
= list(blend_list(dirpath
))
66 defaults
= kwargs
.copy()
68 config
.append(defaults
)
70 return config
, dirpath
73 def as_string(dirpath
, random_order
, exit
, **kwargs
):
74 """ Config loader is in demo_mode.py
76 cfg
, dirpath
= generate(dirpath
, random_order
, **kwargs
)
78 # hint for reader, can be used if files are not found.
82 "# edit the search path so other systems may find the files below\n",
83 "# based on name only if the absolute paths cannot be found\n",
84 "# Use '//' for current blend file path.\n",
86 "search_path = %r\n" % dirpath
,
92 # Works, but custom formatting looks better.
93 # `cfg_str.append("config = %s" % pprint.pformat(cfg, indent=4, width=120))`.
96 return "dict(%s)" % ", ".join(("%s=%s" % (k
, repr_pretty(v
))) for k
, v
in sorted(d
.items()))
99 cfg_str
.append("config = [\n")
101 cfg_str
.append("%s%s,\n" % (ident
, dict_as_kw(cfg_item
)))
102 cfg_str
.append("%s]\n\n" % ident
)
104 return "".join(cfg_str
), len(cfg
), dirpath