Compare commits
2 Commits
v0.1.1
...
24f9b2b779
Author | SHA1 | Date | |
---|---|---|---|
24f9b2b779 | |||
6d1a24cefb |
@ -6,6 +6,11 @@ pipeline:
|
|||||||
- GOOS=linux GOARCH=amd64 go build -o "dist/adept-linux-amd64-${CI_COMMIT_TAG}"
|
- GOOS=linux GOARCH=amd64 go build -o "dist/adept-linux-amd64-${CI_COMMIT_TAG}"
|
||||||
- GOOS=windows GOARCH=amd64 go build -o "dist/adept-windows-amd64-${CI_COMMIT_TAG}.exe"
|
- GOOS=windows GOARCH=amd64 go build -o "dist/adept-windows-amd64-${CI_COMMIT_TAG}.exe"
|
||||||
|
|
||||||
|
test:
|
||||||
|
image: golang:1.16
|
||||||
|
commands:
|
||||||
|
- go test -v ./...
|
||||||
|
|
||||||
gitea_release:
|
gitea_release:
|
||||||
image: plugins/gitea-release
|
image: plugins/gitea-release
|
||||||
settings:
|
settings:
|
||||||
|
17
Makefile
Normal file
17
Makefile
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
BINARY_NAME=adept
|
||||||
|
|
||||||
|
all: build test
|
||||||
|
|
||||||
|
build:
|
||||||
|
go build -o ${BINARY_NAME} adept.go
|
||||||
|
|
||||||
|
test:
|
||||||
|
go test -v ./...
|
||||||
|
|
||||||
|
run:
|
||||||
|
go build -o ${BINARY_NAME} adept.go
|
||||||
|
./${BINARY_NAME}
|
||||||
|
|
||||||
|
clean:
|
||||||
|
go clean
|
||||||
|
rm ${BINARY_NAME}
|
27
adept.go
27
adept.go
@ -1,12 +1,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
"git.metaunix.net/BitGoblin/adept/config"
|
"git.metaunix.net/BitGoblin/adept/config"
|
||||||
"git.metaunix.net/BitGoblin/adept/transcoder"
|
"git.metaunix.net/BitGoblin/adept/transcoder"
|
||||||
|
"git.metaunix.net/BitGoblin/adept/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -18,13 +21,23 @@ func main() {
|
|||||||
for {
|
for {
|
||||||
ingestFiles := r.SearchIngest()
|
ingestFiles := r.SearchIngest()
|
||||||
|
|
||||||
for _, i := range ingestFiles {
|
if len(ingestFiles) < 1 {
|
||||||
// archive file
|
log.Println("There were no files found in ingest to transcode; skipping run.")
|
||||||
r.ArchiveFile(i.Name())
|
} else {
|
||||||
// transcode file
|
for _, i := range ingestFiles {
|
||||||
transcoder.Transcode(i.Name())
|
// check if the file is open in another program (e.g. still being written to)
|
||||||
// clean up source file
|
if util.IsFileLocked(filepath.Join(viper.GetString("transcoder.repository"), "ingest", i.Name())) {
|
||||||
r.CleanupFile(i.Name())
|
log.Printf("%s appears to be open in another program; skipping it for this run.", i.Name())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// archive file
|
||||||
|
r.ArchiveFile(i.Name())
|
||||||
|
// transcode file
|
||||||
|
transcoder.Transcode(i.Name())
|
||||||
|
// clean up source file
|
||||||
|
r.CleanupFile(i.Name())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// sleep for X minutes - specified in the adept.toml config file
|
// sleep for X minutes - specified in the adept.toml config file
|
||||||
|
19
util/env_test.go
Normal file
19
util/env_test.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestResolveTilde(t *testing.T) {
|
||||||
|
resolvedPath := ResolveTilde("~")
|
||||||
|
|
||||||
|
if resolvedPath == "~" {
|
||||||
|
t.Logf("ResolveTilde returned '%s'; it should have expanded to an absolute path.", resolvedPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResolveTildePath(t *testing.T) {
|
||||||
|
resolvedPath := ResolveTilde("~/test")
|
||||||
|
|
||||||
|
if resolvedPath == "~/test" {
|
||||||
|
t.Logf("ResolveTilde returned '%s'; it should have expanded to an absolute path.", resolvedPath)
|
||||||
|
}
|
||||||
|
}
|
12
util/file.go
12
util/file.go
@ -1,6 +1,7 @@
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -8,3 +9,14 @@ import (
|
|||||||
func FilenameWithoutExtension(filename string) string {
|
func FilenameWithoutExtension(filename string) string {
|
||||||
return strings.TrimSuffix(filename, path.Ext(filename))
|
return strings.TrimSuffix(filename, path.Ext(filename))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsFileLocked(filepath string) bool {
|
||||||
|
cmd := exec.Command("/usr/bin/lsof", filepath)
|
||||||
|
stdout, _ := cmd.Output()
|
||||||
|
|
||||||
|
if strings.Contains(string(stdout), filepath) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
11
util/file_test.go
Normal file
11
util/file_test.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestFilenameWithoutExtension(t *testing.T) {
|
||||||
|
filename := FilenameWithoutExtension("testfile.txt")
|
||||||
|
|
||||||
|
if filename != "testfile" {
|
||||||
|
t.Logf("FilenameWithoutExtension returned '%s'; it should be 'testfile'.", filename)
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user