Worker: blender-render command, make the blendfile parameter optional

Only include the `blendfile` parameter if it is not empty. This makes it
possible to pass a Python script that loads/constructs the blend file,
instead of loading one directly.
This commit is contained in:
Sybren A. Stüvel 2024-02-25 23:09:11 +01:00
parent 72d5cfa07c
commit 81968610ed
3 changed files with 34 additions and 4 deletions

View File

@ -8,6 +8,7 @@ bugs in actually-released versions.
- Add MQTT support. Flamenco Manager can now send internal events to an MQTT broker.
- Simplify the preview video filename when a complex set of frames rendered ([#104285](https://projects.blender.org/studio/flamenco/issues/104285)). Instead of `video-1, 4, 10.mp4` it is now simply `video-1-10.mp4`.
- Make the `blendfile` parameter of a `blender-render` command optional. This makes it possible to pass, for example, a Python file that loads/constructs the blend file, instead of loading one straight from disk.
## 3.4 - released 2024-01-12

View File

@ -101,7 +101,12 @@ func (ce *CommandExecutor) cmdBlenderRenderCommand(
cliArgs := make([]string, 0)
cliArgs = append(cliArgs, parameters.argsBefore...)
cliArgs = append(cliArgs, parameters.blendfile)
if parameters.blendfile != "" {
// Only include the blendfile if the parameter is not empty. This makes it
// possible to pass a Python script that loads/constructs the blend file,
// instead of loading one explicitly here.
cliArgs = append(cliArgs, parameters.blendfile)
}
cliArgs = append(cliArgs, parameters.args...)
execCmd := ce.cli.CommandContext(ctx, parameters.exe, cliArgs...)
if execCmd == nil {
@ -132,9 +137,9 @@ func cmdBlenderRenderParams(logger zerolog.Logger, cmd api.Command) (BlenderPara
logger.Warn().Interface("command", cmd).Msg("invalid 'argsBefore' parameter")
return parameters, NewParameterInvalidError("argsBefore", cmd, "cannot convert to list of strings")
}
if parameters.blendfile, ok = cmdParameter[string](cmd, "blendfile"); !ok || parameters.blendfile == "" {
logger.Warn().Interface("command", cmd).Msg("missing 'blendfile' parameter")
return parameters, NewParameterMissingError("blendfile", cmd)
if parameters.blendfile, ok = cmdParameter[string](cmd, "blendfile"); !ok {
logger.Warn().Interface("command", cmd).Msg("invalid 'blendfile' parameter")
return parameters, NewParameterInvalidError("blendfile", cmd, "cannot convert to string")
}
if parameters.args, ok = cmdParameterAsStrings(cmd, "args"); !ok {
logger.Warn().Interface("command", cmd).Msg("invalid 'args' parameter")

View File

@ -79,6 +79,30 @@ func TestCmdBlenderCliArgsInExeParameter(t *testing.T) {
assert.Equal(t, ErrNoExecCmd, err, "nil *exec.Cmd should result in ErrNoExecCmd")
}
func TestCmdBlenderNoBlendfile(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
ce, mocks := testCommandExecutor(t, mockCtrl)
taskID := "1d54c6fe-1242-4c8f-bd63-5a09e358d7b6"
cmd := api.Command{
Name: "blender",
Parameters: map[string]interface{}{
"exe": "/path/to/blender",
"argsBefore": []string{"--background"},
"blendfile": "", // Empty blendfile should be skipped.
"args": []string{"--render-output", "/frames"},
},
}
cliArgs := []string{"--background", "--render-output", "/frames"}
mocks.cli.EXPECT().CommandContext(gomock.Any(), "/path/to/blender", cliArgs).Return(nil)
err := ce.cmdBlenderRender(context.Background(), zerolog.Nop(), taskID, cmd)
assert.Equal(t, ErrNoExecCmd, err, "nil *exec.Cmd should result in ErrNoExecCmd")
}
func TestProcessLineBlender(t *testing.T) {
ctx := context.Background()
mockCtrl := gomock.NewController(t)