Darktable: Set explicit cache and config path, log exact commands #2076

This commit is contained in:
Michael Mayer 2022-03-02 12:20:02 +01:00
parent 6453aa76b3
commit 3d9cb51641
18 changed files with 79 additions and 29 deletions

View file

@ -86,7 +86,7 @@ func AuthenticatedRequestWithBody(r http.Handler, method, path, body string, ses
func TestMain(m *testing.M) {
log = logrus.StandardLogger()
log.SetLevel(logrus.DebugLevel)
log.SetLevel(logrus.TraceLevel)
c := config.TestConfig()
service.SetConfig(c)

View file

@ -10,7 +10,7 @@ import (
func TestMain(m *testing.M) {
log = logrus.StandardLogger()
log.SetLevel(logrus.DebugLevel)
log.SetLevel(logrus.TraceLevel)
if err := os.Remove(".test.db"); err == nil {
log.Debugln("removed .test.db")

View file

@ -145,6 +145,9 @@ func backupAction(ctx *cli.Context) error {
cmd.Stdout = &out
cmd.Stderr = &stderr
// Log exact command for debugging in trace mode.
log.Trace(cmd.String())
// Run backup command.
if err := cmd.Run(); err != nil {
if stderr.String() != "" {

View file

@ -129,6 +129,8 @@ func configAction(ctx *cli.Context) error {
// External Tools.
fmt.Printf("%-25s %t\n", "raw-presets", conf.RawPresets())
fmt.Printf("%-25s %s\n", "darktable-bin", conf.DarktableBin())
fmt.Printf("%-25s %s\n", "darktable-cache-path", conf.DarktableCachePath())
fmt.Printf("%-25s %s\n", "darktable-config-path", conf.DarktableConfigPath())
fmt.Printf("%-25s %s\n", "darktable-blacklist", conf.DarktableBlacklist())
fmt.Printf("%-25s %s\n", "rawtherapee-bin", conf.RawtherapeeBin())
fmt.Printf("%-25s %s\n", "rawtherapee-blacklist", conf.RawtherapeeBlacklist())

View file

@ -179,6 +179,9 @@ func restoreAction(ctx *cli.Context) error {
}
}()
// Log exact command for debugging in trace mode.
log.Trace(cmd.String())
// Run backup command.
if err := cmd.Run(); err != nil {
if stderr.String() != "" {

View file

@ -13,7 +13,7 @@ import (
func TestMain(m *testing.M) {
log = logrus.StandardLogger()
log.SetLevel(logrus.DebugLevel)
log.SetLevel(logrus.TraceLevel)
c := TestConfig()

View file

@ -35,7 +35,7 @@ func (c *Config) CreateDirectories() error {
if fs.FileExists(path) {
result = fmt.Errorf("%s is a file, not a folder: please check your configuration", sanitize.Log(path))
} else {
result = fmt.Errorf("cannot create %s: please check configuration and permissions", sanitize.Log(path))
result = fmt.Errorf("cannot create %s, check config and permissions", sanitize.Log(path))
}
log.Debug(err)

View file

@ -146,7 +146,7 @@ func TestConfig_CreateDirectories2(t *testing.T) {
if err2 == nil {
t.Fatal("error expected")
}
assert.Contains(t, err2.Error(), "please check configuration and permissions")
assert.Contains(t, err2.Error(), "check config and permissions")
})
t.Run("storage path error", func(t *testing.T) {
@ -163,7 +163,7 @@ func TestConfig_CreateDirectories2(t *testing.T) {
if err2 == nil {
t.Fatal("error expected")
}
assert.Contains(t, err2.Error(), "please check configuration and permissions")
assert.Contains(t, err2.Error(), "check config and permissions")
})
t.Run("originals path not found", func(t *testing.T) {
@ -188,7 +188,7 @@ func TestConfig_CreateDirectories2(t *testing.T) {
if err2 == nil {
t.Fatal("error expected")
}
assert.Contains(t, err2.Error(), "please check configuration and permissions")
assert.Contains(t, err2.Error(), "check config and permissions")
})
t.Run("import path not found", func(t *testing.T) {
@ -213,7 +213,7 @@ func TestConfig_CreateDirectories2(t *testing.T) {
if err2 == nil {
t.Fatal("error expected")
}
assert.Contains(t, err2.Error(), "please check configuration and permissions")
assert.Contains(t, err2.Error(), "check config and permissions")
})
t.Run("sidecar path error", func(t *testing.T) {
@ -230,7 +230,7 @@ func TestConfig_CreateDirectories2(t *testing.T) {
if err2 == nil {
t.Fatal("error expected")
}
assert.Contains(t, err2.Error(), "please check configuration and permissions")
assert.Contains(t, err2.Error(), "check config and permissions")
})
t.Run("cache path error", func(t *testing.T) {
@ -247,7 +247,7 @@ func TestConfig_CreateDirectories2(t *testing.T) {
if err2 == nil {
t.Fatal("error expected")
}
assert.Contains(t, err2.Error(), "please check configuration and permissions")
assert.Contains(t, err2.Error(), "check config and permissions")
})
t.Run("config path error", func(t *testing.T) {
@ -264,7 +264,7 @@ func TestConfig_CreateDirectories2(t *testing.T) {
if err2 == nil {
t.Fatal("error expected")
}
assert.Contains(t, err2.Error(), "please check configuration and permissions")
assert.Contains(t, err2.Error(), "check config and permissions")
})
t.Run("temp path error", func(t *testing.T) {
@ -281,7 +281,7 @@ func TestConfig_CreateDirectories2(t *testing.T) {
if err2 == nil {
t.Fatal("error expected")
}
assert.Contains(t, err2.Error(), "please check configuration and permissions")
assert.Contains(t, err2.Error(), "check config and permissions")
})
}
*/

View file

@ -1,5 +1,12 @@
package config
import (
"os"
"path/filepath"
"github.com/photoprism/photoprism/pkg/sanitize"
)
// RawPresets tests if RAW converter presents should be used (may reduce performance).
func (c *Config) RawPresets() bool {
return c.options.RawPresets
@ -15,6 +22,28 @@ func (c *Config) DarktableBlacklist() string {
return c.options.DarktableBlacklist
}
// DarktableConfigPath returns the darktable config directory.
func (c *Config) DarktableConfigPath() string {
dir := filepath.Join(c.ConfigPath(), "darktable")
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
log.Errorf("darktable: cannot create config directory %s, check permissions", sanitize.Log(dir))
return c.ConfigPath()
}
return dir
}
// DarktableCachePath returns the darktable cache directory.
func (c *Config) DarktableCachePath() string {
dir := filepath.Join(c.CachePath(), "darktable")
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
log.Errorf("darktable: cannot create cache directory %s, check permissions", sanitize.Log(dir))
return c.ConfigPath()
}
return dir
}
// DarktableEnabled tests if Darktable is enabled for RAW conversion.
func (c *Config) DarktableEnabled() bool {
return !c.DisableDarktable()

View file

@ -11,7 +11,7 @@ import (
func TestMain(m *testing.M) {
log = logrus.StandardLogger()
log.SetLevel(logrus.DebugLevel)
log.SetLevel(logrus.TraceLevel)
if err := os.Remove(".test.db"); err == nil {
log.Debugln("removed .test.db")

View file

@ -15,7 +15,7 @@ import (
func TestMain(m *testing.M) {
log = logrus.StandardLogger()
log.SetLevel(logrus.DebugLevel)
log.SetLevel(logrus.TraceLevel)
ServiceURL = "https://hub-int.photoprism.app/v1/hello"

View file

@ -162,6 +162,9 @@ func (c *Convert) ToJson(f *MediaFile) (jsonName string, err error) {
cmd.Stdout = &out
cmd.Stderr = &stderr
// Log exact command for debugging in trace mode.
log.Trace(cmd.String())
// Run convert command.
if err := cmd.Run(); err != nil {
if stderr.String() != "" {
@ -199,21 +202,25 @@ func (c *Convert) JpegConvertCommand(f *MediaFile, jpegName string, xmpName stri
} else if c.conf.DarktableEnabled() && c.darktableBlacklist.Ok(fileExt) {
var args []string
// Only one instance of darktable-cli allowed due to locking if presets are loaded.
if c.conf.RawPresets() {
useMutex = true
args = []string{"--width", size, "--height", size, f.FileName()}
// Set RAW, XMP, and JPEG filenames.
if xmpName != "" {
args = []string{f.FileName(), xmpName, jpegName}
} else {
useMutex = false
args = []string{"--apply-custom-presets", "false", "--width", size, "--height", size, f.FileName()}
args = []string{f.FileName(), jpegName}
}
if xmpName != "" {
args = append(args, xmpName, jpegName)
// Set RAW to JPEG conversion options.
if c.conf.RawPresets() {
useMutex = true // can run one instance only with presets enabled
args = append(args, "--width", size, "--height", size, "--hq", "true", "--upscale", "false")
} else {
args = append(args, jpegName)
useMutex = false // --apply-custom-presets=false disables locking
args = append(args, "--apply-custom-presets", "false", "--width", size, "--height", size, "--hq", "true", "--upscale", "false")
}
// Set Darktable core storage paths.
args = append(args, "--core", "--configdir", c.conf.DarktableConfigPath(), "--cachedir", c.conf.DarktableCachePath(), "--library", ":memory:")
result = exec.Command(c.conf.DarktableBin(), args...)
} else if c.conf.RawtherapeeEnabled() && c.rawtherapeeBlacklist.Ok(fileExt) {
jpegQuality := fmt.Sprintf("-j%d", c.conf.JpegQuality())
@ -320,6 +327,9 @@ func (c *Convert) ToJpeg(f *MediaFile) (*MediaFile, error) {
log.Infof("%s: converting %s to %s", filepath.Base(cmd.Path), fileName, fs.FormatJpeg)
// Log exact command for debugging in trace mode.
log.Trace(cmd.String())
// Run convert command.
if err := cmd.Run(); err != nil {
if stderr.String() != "" {
@ -494,6 +504,9 @@ func (c *Convert) ToAvc(f *MediaFile, encoderName string) (file *MediaFile, err
log.Infof("%s: transcoding %s to %s", encoderName, fileName, fs.FormatAvc)
// Log exact command for debugging in trace mode.
log.Trace(cmd.String())
// Run convert command.
start := time.Now()
if err = cmd.Run(); err != nil {

View file

@ -10,7 +10,7 @@ import (
func TestMain(m *testing.M) {
log = logrus.StandardLogger()
log.SetLevel(logrus.DebugLevel)
log.SetLevel(logrus.TraceLevel)
if err := os.Remove(".test.db"); err == nil {
log.Debugln("removed .test.db")

View file

@ -10,7 +10,7 @@ import (
func TestMain(m *testing.M) {
log = logrus.StandardLogger()
log.SetLevel(logrus.DebugLevel)
log.SetLevel(logrus.TraceLevel)
if err := os.Remove(".test.db"); err == nil {
log.Debugln("removed .test.db")

View file

@ -10,7 +10,7 @@ import (
func TestMain(m *testing.M) {
log = logrus.StandardLogger()
log.SetLevel(logrus.DebugLevel)
log.SetLevel(logrus.TraceLevel)
if err := os.Remove(".test.db"); err == nil {
log.Debugln("removed .test.db")

View file

@ -10,7 +10,7 @@ import (
func TestMain(m *testing.M) {
log = logrus.StandardLogger()
log.SetLevel(logrus.DebugLevel)
log.SetLevel(logrus.TraceLevel)
db := entity.InitTestDb(os.Getenv("PHOTOPRISM_TEST_DRIVER"), os.Getenv("PHOTOPRISM_TEST_DSN"))
defer db.Close()

View file

@ -13,7 +13,7 @@ var logBuffer bytes.Buffer
func TestMain(m *testing.M) {
log = logrus.StandardLogger()
log.Out = &logBuffer
log.SetLevel(logrus.DebugLevel)
log.SetLevel(logrus.TraceLevel)
code := m.Run()

View file

@ -10,7 +10,7 @@ import (
func TestMain(m *testing.M) {
log = logrus.StandardLogger()
log.SetLevel(logrus.DebugLevel)
log.SetLevel(logrus.TraceLevel)
if err := os.Remove(".test.db"); err == nil {
log.Debugln("removed .test.db")