Changed config.rkt to simple-ini.

This commit is contained in:
2026-06-09 23:47:11 +02:00
parent c3e48285b4
commit 736638f2a4
7 changed files with 145 additions and 169 deletions
+19 -16
View File
@@ -4,7 +4,7 @@
racket/file
racket/list
racket/path
"private/config.rkt"
"private/manager-ini.rkt"
"private/flac2opus-state.rkt"
"private/fingerprint.rkt"
"private/hash.rkt"
@@ -26,11 +26,11 @@
(define (manager-admin-relpath? relpath)
(member relpath manager-admin-relpaths))
(define (source-file-signature path config)
(define mode (manager-config-change-detection config))
(define (source-file-signature path ini)
(define mode (string-downcase (ini-ref/string ini 'manager 'change-detection "flac-taglib")))
(define hash-algorithm (string-downcase (ini-ref/string ini 'manager 'hash-algorithm "sha256")))
(cond [(member mode '("hash" "sha256" "full-hash" "full-sha256"))
(string-append "file:" (manager-config-hash-algorithm config) ":"
(file-digest path (manager-config-hash-algorithm config)))]
(string-append "file:" hash-algorithm ":" (file-digest path hash-algorithm))]
[(flac-path? path)
(cond [(member mode '("flac" "flac-streaminfo"))
(string-append "flac-streaminfo:" (flac-streaminfo-fingerprint path))]
@@ -103,7 +103,7 @@
(cons 'kbps kbps))
extra))
(define (process-one-source-file ks config target-dir path relpath target-relpath kbps convert-proc summary errors)
(define (process-one-source-file ks ini target-dir path relpath target-relpath kbps convert-proc summary errors)
(define target-path (target-path-for target-dir target-relpath))
(define old (flac2opus-state-get-file ks relpath #f))
(cond [(same-quick-state? old path target-path target-relpath kbps)
@@ -125,13 +125,13 @@
(cons (list (cons 'file relpath)
(cons 'message (exn-message e)))
errors)))])
(define signature (source-file-signature path config))
(define signature (source-file-signature path ini))
(cond [(same-signature-state? old signature target-path target-relpath kbps)
(info-alm "unchanged fingerprint: ~a" relpath)
(flac2opus-state-set-file! ks relpath
(state-info path target-relpath signature 'unchanged kbps '()))
(values (summary-inc summary2 'unchanged) errors)]
[(manager-config-dry-run? config)
[(ini-ref/bool ini 'manager 'dry-run #f)
(warn-alm "dry-run: would mirror ~a -> ~a" relpath target-relpath)
(flac2opus-state-set-file! ks relpath
(state-info path target-relpath signature 'dry-run kbps '()))
@@ -181,15 +181,18 @@
(unless (directory-exists? source-dir)
(raise-argument-error 'manage-flac2opus-tree "existing source directory" source-directory))
(make-directory* target-dir)
(define config (load-manager-config source-dir))
(setup-logging! (manager-config-log-file-opus config) (manager-config-display-log? config))
(define ini-file (manager-ini-file source-dir))
(define state-file (manager-state-file source-dir))
(define ini (load-manager-ini source-dir))
(setup-logging! (ini-ref/path ini source-dir 'opus-manager 'log-file ".flac2opus-manager.log")
(ini-ref/bool ini 'manager 'display-log #t))
(info-alm "flac2opus source directory: ~a" source-dir)
(info-alm "flac2opus target directory: ~a" target-dir)
(info-alm "state file: ~a" (manager-config-state-file config))
(info-alm "ini file: ~a" (manager-config-ini-file config))
(info-alm "change detection: ~a" (manager-config-change-detection config))
(info-alm "state file: ~a" state-file)
(info-alm "ini file: ~a" ini-file)
(info-alm "change detection: ~a" (ini-ref/string ini 'manager 'change-detection "flac-taglib"))
(info-alm "opus bitrate: ~a kbps" kbps)
(define ks (open-flac2opus-state (manager-config-state-file config)))
(define ks (open-flac2opus-state state-file))
(define files (find-source-files source-dir))
(define relpaths (map (lambda (p) (source-relpath-string source-dir p)) files))
(define target-relpaths (map target-relpath-for relpaths))
@@ -198,10 +201,10 @@
(for/fold ([summary summary0] [errors '()]) ([p (in-list files)]
[relpath (in-list relpaths)]
[target-relpath (in-list target-relpaths)])
(process-one-source-file ks config target-dir p relpath target-relpath kbps convert-proc summary errors)))
(process-one-source-file ks ini target-dir p relpath target-relpath kbps convert-proc summary errors)))
(define errors* (reverse errors))
(with-handlers ([exn:fail? (lambda (e) (err-alm "mail report failed: ~a" (exn-message e)) (void))])
(maybe-send-report-mail config summary errors*
(maybe-send-report-mail ini summary errors*
#:manager-name "FLAC to Opus manager"
#:result-label "converted/copied"))
(for ([line (in-list (summary->lines summary))]) (info-alm "summary: ~a" line))