forked from ldo/render-useful
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathext-files
More file actions
executable file
·131 lines (126 loc) · 3.49 KB
/
ext-files
File metadata and controls
executable file
·131 lines (126 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
#+
# This script displays information about a specified .blend file,
# namely external image, library, font and sound files that it
# depends on. Invoke it as follows:
#
# ext-files [options...] blendfile
#
# where the valid options are
#
# --blender=blender
# specifies the path to the Blender executable. Defaults to
# searching for the name “blender” in your PATH.
# --paths-only
# specifies that only the file paths are to be printed,
# one to a line. Otherwise more details about the dependencies
# are printed in JSON format.
#
# Copyright 2015 by Lawrence D'Oliveiro <ldo@geek-central.gen.nz>.
# Licensed under CC-BY-SA <http://creativecommons.org/licenses/by-sa/4.0/>.
#-
blender=blender
paths_only=
for ((;;)); do
if [ "${1:0:2}" != "--" ]; then
break
fi
opt="${1:2:${#1}}"
shift
val="${opt#*=}"
opt="${opt%%=*}"
if [ "$opt" = "blender" ]; then
blender="$val"
elif [ "$opt" = "paths-only" ]; then
paths_only=1
else
echo "$0: bad option $opt" 1>&2
exit 3
fi
done
if [ -z "$(type -p "$blender")" ]; then
echo "$0: no such executable “$blender”" 1>&2
exit 3
fi
if [ $# != 1 ]; then
echo $'Usage:\n\t'"$0" $'<blendfile>\n' 1>&2
exit 3
fi
blendfile="$1"
export RENDER_paths_only="$paths_only"
exec "$blender" 5>&1 1>/dev/null -b "$blendfile" -P <(cat <<'EOD'
import sys
import os
import json
import bpy
out = os.fdopen(5, "w")
# use a different fd from stdout, only way it seems to avoid
# output being polluted by Blender’s messages
paths_only = os.getenv("RENDER_paths_only", "") != ""
if not paths_only :
out.write("{")
first_cat = True
#end if
for \
category, match, mismatch, extra \
in \
(
("images", {"type" : "IMAGE"}, {}, ("filepath_raw",)),
("libraries", {}, {}, ()),
("fonts", {}, {"filepath" : "<builtin>"}, ()),
("sounds", {}, {}, ()),
) \
:
if not paths_only :
if first_cat :
first_cat = False
else :
out.write(",")
#end if
out.write("\n %s:\n [" % json.dumps(category))
first_item = True
#end if
for item in getattr(bpy.data, category) :
if (
item.packed_file == None
and
not any(getattr(item, k) == mismatch[k] for k in mismatch)
and
all(getattr(item, k) == match[k] for k in match)
) :
if paths_only :
out.write(item.filepath + "\n")
else :
if first_item :
first_item = False
else :
out.write(",")
#end if
out.write("\n {")
first_attr = True
for attr in ("name", "filepath") + extra :
if first_attr :
first_attr = False
else :
out.write(",")
#end if
out.write \
(
"\n %s: %s"
%
(json.dumps(attr), json.dumps(getattr(item, attr)))
)
#end for
out.write("\n }")
#end if
#end if
#end for
if not paths_only :
out.write("\n ]")
#end if
#end for
if not paths_only :
out.write("\n}\n")
#end if
EOD
)