Fix CI and main app location

This commit is contained in:
kayos@tcp.direct 2024-05-08 02:40:56 -07:00
parent 532a31ffdf
commit 63a5cf0052
Signed by: kayos
GPG Key ID: 4B841471B4BEE979
5 changed files with 107 additions and 5 deletions

View File

@ -14,9 +14,9 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.21
- name: go vet -v ./...
run: go vet -v ./...
go-version: 1.22
- name: go vet ./...
run: go vet ./...
- name: go test -v ./...
run: go test -v ./...
- name: go build -v ./...

1
.gitignore vendored
View File

@ -1,3 +1,2 @@
.idea
keepr
assets/

BIN
cmd/keepr/keepr Executable file

Binary file not shown.

103
cmd/keepr/main.go Normal file
View File

@ -0,0 +1,103 @@
package main
import (
"os"
"path/filepath"
"runtime"
"strings"
"sync/atomic"
"time"
"github.com/rs/zerolog"
"kr.dev/walk"
"git.tcp.direct/kayos/keepr/internal/collect"
"git.tcp.direct/kayos/keepr/internal/config"
"git.tcp.direct/kayos/keepr/internal/util"
)
var (
log *zerolog.Logger
basepath = "/"
)
func init() {
if runtime.GOOS == "windows" {
// TODO: fix this garbage
basepath = "C:\\"
}
}
func main() {
config.KeeprInit()
log = config.GetLogger()
var lastpath = ""
target := strings.TrimSuffix(strings.TrimPrefix(strings.TrimSpace(config.Source), "/"), "/")
cripwalk := walk.New(os.DirFS(basepath), target)
_, output := filepath.Split(strings.TrimSuffix(config.Output, "/"))
log.Trace().Msgf("output is %s", output)
for cripwalk.Next() {
if err := cripwalk.Err(); err != nil {
log.Fatal().Caller().Str("caller", lastpath).Msg(err.Error())
continue
}
lastpath = cripwalk.Path()
slog := log.With().Str("caller", cripwalk.Path()).Logger()
switch {
case cripwalk.Entry() == nil:
slog.Trace().Msg("nil")
continue
case cripwalk.Entry().IsDir():
if strings.Contains(cripwalk.Path(), output) {
slog.Info().Msg("skiping directory entirely")
cripwalk.SkipDir()
}
continue
// slog.Trace().Msg("directory")
default:
if strings.Contains(cripwalk.Path(), config.Output) {
log.Trace().Msg("skipping file in destination")
cripwalk.SkipDir()
continue
}
sample, err := collect.Process(cripwalk.Entry(), util.APath(cripwalk.Path(), config.Relative))
if err != nil {
slog.Warn().Caller().Str("caller", cripwalk.Path()).Err(err).Msgf("failed to process")
continue
}
if sample == nil {
slog.Trace().Msgf("skipping unknown file")
continue
}
slog.Info().Interface("sample", sample).Msg("processed")
}
}
if config.StatsOnly {
log.Info().Msg("Printing stats")
collect.Library.TempoStats()
collect.Library.KeyStats()
collect.Library.DrumStats()
collect.Library.TypeStats()
return
}
var errs []error
errs = append(errs, collect.Library.SymlinkTempos())
errs = append(errs, collect.Library.SymlinkKeys())
errs = append(errs, collect.Library.SymlinkDrums())
errs = append(errs, collect.Library.SymlinkMelodicLoops())
errs = append(errs, collect.Library.SymlinkMIDIs())
errs = append(errs, collect.Library.SymlinkArtists())
errs = append(errs, collect.Library.SymlinkGenres())
errs = append(errs, collect.Library.SymlinkSources())
errs = append(errs, collect.Library.SymlinkCreationDates())
errs = append(errs, collect.Library.SymlinkSoftwares())
for !atomic.CompareAndSwapInt32(&collect.Backlog, 0, -1) {
time.Sleep(1 * time.Second)
print(".")
}
log.Info().Errs("errs", errs).Msg("fin.")
}

2
go.mod
View File

@ -1,6 +1,6 @@
module git.tcp.direct/kayos/keepr
go 1.22
go 1.20
require (
git.tcp.direct/kayos/common v0.9.7