Sybren A. Stüvel 9f5e4cc0cc License: license all code under "GPL-3.0-or-later"
The add-on code was copy-pasted from other addons and used the GPL v2
license, whereas by accident the LICENSE text file had the GNU "Affero" GPL
license v3 (instead of regular GPL v3).

This is now all streamlined, and all code is licensed as "GPL v3 or later".

Furthermore, the code comments just show a SPDX License Identifier
instead of an entire license block.
2022-03-07 15:26:46 +01:00

40 lines
1.1 KiB
Go

package api_impl
// SPDX-License-Identifier: GPL-3.0-or-later
import (
"git.blender.org/flamenco/internal/manager/config"
"git.blender.org/flamenco/internal/manager/persistence"
"git.blender.org/flamenco/pkg/api"
)
type VariableReplacer interface {
ExpandVariables(valueToExpand string, audience config.VariableAudience, platform string) string
}
// replaceTaskVariables performs variable replacement for worker tasks.
func replaceTaskVariables(replacer VariableReplacer, task api.AssignedTask, worker persistence.Worker) api.AssignedTask {
repl := func(value string) string {
return replacer.ExpandVariables(value, "workers", worker.Platform)
}
for cmdIndex, cmd := range task.Commands {
for key, value := range cmd.Parameters {
switch v := value.(type) {
case string:
task.Commands[cmdIndex].Parameters[key] = repl(v)
case []string:
replaced := make([]string, len(v))
for idx := range v {
replaced[idx] = repl(v[idx])
}
task.Commands[cmdIndex].Parameters[key] = replaced
default:
continue
}
}
}
return task
}