Skip to content

Commit

Permalink
feat(proxy): implement tidy up (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Dec 26, 2023
1 parent 5f54e8a commit 9354a8d
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 230 deletions.
5 changes: 2 additions & 3 deletions src/app/proxy/controller-full.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ type FullController struct {
controller
}

func (c *FullController) OnNewShrinkItem(item *nav.TraverseItem,
positional []string,
func (c *FullController) OnNewShrinkItem(
item *nav.TraverseItem,
thirdPartyCL cobrass.ThirdPartyCommandLine,
) error {
_ = item
_ = positional
_ = thirdPartyCL

return nil
Expand Down
6 changes: 1 addition & 5 deletions src/app/proxy/controller-sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ type SamplerController struct {
controller
}

func (c *SamplerController) OnNewShrinkItem(item *nav.TraverseItem,
positional []string,
) error {
_ = positional

func (c *SamplerController) OnNewShrinkItem(item *nav.TraverseItem) error {
// create a master path info here and pass into the sequences
// to replace the individual properties on the step
//
Expand Down
142 changes: 85 additions & 57 deletions src/app/proxy/controller-sampler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ var (
backyardWorldsPlanet9Scan01First4 []string
backyardWorldsPlanet9Scan01First6 []string

backyardWorldsPlanet9Scan01Last4 []string

profilesConfigData proxy.ProfilesConfigMap
samplerConfigData *proxy.MsSamplerConfig
)
Expand Down Expand Up @@ -67,6 +69,13 @@ func init() {
}...,
)

backyardWorldsPlanet9Scan01Last4 = []string{
"03_Backyard-Worlds-Planet-9_s01.jpg",
"04_Backyard-Worlds-Planet-9_s01.jpg",
"05_Backyard-Worlds-Planet-9_s01.jpg",
"06_Backyard-Worlds-Planet-9_s01.jpg",
}

profilesConfigData = proxy.ProfilesConfigMap{
"blur": clif.ChangedFlagsMap{
"strip": "true",
Expand Down Expand Up @@ -319,7 +328,7 @@ var _ = Describe("SamplerController", Ordered, func() {
args: []string{
"--sample",
"--no-files", "4",
"--files-gb", "*Backyard Worlds*",
"--files-gb", "*Backyard-Worlds*",
"--gaussian-blur", "0.51",
"--interlace", "line",
},
Expand All @@ -338,7 +347,7 @@ var _ = Describe("SamplerController", Ordered, func() {
args: []string{
"--sample",
"--no-files", "4",
"--files-gb", "*Backyard Worlds*",
"--files-gb", "*Backyard-Worlds*",
"--profile", "adaptive",
"--gaussian-blur", "0.51",
"--interlace", "line",
Expand All @@ -350,6 +359,65 @@ var _ = Describe("SamplerController", Ordered, func() {
},
}),

Entry(nil, &samplerTE{
controllerTE: controllerTE{
given: "run(last) transparent with profile",
should: "sample(last) with glob filter using the defined profile",
relative: backyardWorldsPlanet9Scan01,
args: []string{
"--sample",
"--last",
"--no-files", "4",
"--files-gb", "*Backyard-Worlds*",
"--profile", "adaptive",
"--gaussian-blur", "0.51",
"--interlace", "line",
},
expected: backyardWorldsPlanet9Scan01Last4,
intermediate: "nasa/exo/Backyard Worlds - Planet 9/sessions/scan-01",
supplement: "adaptive/TRASH",
inputs: backyardWorldsPlanet9Scan01Last4,
},
}),

Entry(nil, &samplerTE{
controllerTE: controllerTE{
given: "profile without no-files in args",
should: "sample(first) with glob filter, using no-files from config",
relative: backyardWorldsPlanet9Scan01,
args: []string{
"--sample",
"--files-gb", "*Backyard-Worlds*",
"--profile", "adaptive",
},
expected: backyardWorldsPlanet9Scan01First2,
intermediate: "nasa/exo/Backyard Worlds - Planet 9/sessions/scan-01",
supplement: "adaptive/TRASH",
inputs: backyardWorldsPlanet9Scan01First2,
},
}),

Entry(nil, &samplerTE{
controllerTE: controllerTE{
given: "profile",
should: "sample with regex filter using the defined profile",
relative: backyardWorldsPlanet9Scan01,
args: []string{
"--sample",
"--no-files", "4",
"--strip",
"--interlace", "plane",
"--quality", "85",
"--files-rx", "Backyard-Worlds",
"--profile", "adaptive",
},
expected: backyardWorldsPlanet9Scan01First4,
intermediate: "nasa/exo/Backyard Worlds - Planet 9/sessions/scan-01",
supplement: "adaptive/TRASH",
inputs: backyardWorldsPlanet9Scan01First4,
},
}),

Entry(nil, &samplerTE{
controllerTE: controllerTE{
given: "run transparent with scheme with single profile",
Expand All @@ -358,7 +426,7 @@ var _ = Describe("SamplerController", Ordered, func() {
args: []string{
"--sample",
"--no-files", "4",
"--files-gb", "*Backyard Worlds*",
"--files-gb", "*Backyard-Worlds*",
"--scheme", "singleton",
"--gaussian-blur", "0.51",
"--interlace", "line",
Expand All @@ -378,7 +446,7 @@ var _ = Describe("SamplerController", Ordered, func() {
args: []string{
"--sample",
"--no-files", "4",
"--files-gb", "*Backyard Worlds*",
"--files-gb", "*Backyard-Worlds*",
"--gaussian-blur", "0.51",
"--interlace", "line",
},
Expand All @@ -398,7 +466,7 @@ var _ = Describe("SamplerController", Ordered, func() {
args: []string{
"--sample",
"--no-files", "4",
"--files-gb", "*Backyard Worlds*",
"--files-gb", "*Backyard-Worlds*",
"--profile", "adaptive",
"--gaussian-blur", "0.51",
"--interlace", "line",
Expand All @@ -419,7 +487,7 @@ var _ = Describe("SamplerController", Ordered, func() {
args: []string{
"--sample",
"--no-files", "4",
"--files-gb", "*Backyard Worlds*",
"--files-gb", "*Backyard-Worlds*",
"--scheme", "singleton",
"--gaussian-blur", "0.51",
"--interlace", "line",
Expand All @@ -432,63 +500,23 @@ var _ = Describe("SamplerController", Ordered, func() {
},
}),

XEntry(nil, &samplerTE{
controllerTE: controllerTE{
given: "profile",
should: "sample(last) with glob filter using the defined profile",
relative: backyardWorldsPlanet9Scan01,
args: []string{
"--sample",
"--last",
"--no-files", "4",
"--files-gb", "*Energy-Explorers*",
"--profile", "adaptive",
},
expected: backyardWorldsPlanet9Scan01First4,
},
}),

XEntry(nil, &samplerTE{
controllerTE: controllerTE{
given: "profile without no-files in args",
should: "sample(first) with glob filter, using no-files from config",
relative: backyardWorldsPlanet9Scan01,
args: []string{
"--sample",
"--files-gb", "*Energy-Explorers*",
"--profile", "adaptive",
},
expected: backyardWorldsPlanet9Scan01First2,
},
}),

XEntry(nil, &samplerTE{
controllerTE: controllerTE{
given: "profile",
should: "sample with regex filter using the defined profile",
relative: backyardWorldsPlanet9Scan01,
args: []string{
"--strip", "--interlace", "plane", "--quality", "85", "--profile", "adaptive",
},
},
}),

// override config with explicitly defined args on command line
// ie they should be present in args as opposed to relying on presence
// in config. Here we are testing that command line overrides config
// ...

// ===

XEntry(nil, &samplerTE{
Entry(nil, &samplerTE{
controllerTE: controllerTE{
given: "scheme",
should: "sample all profiles in the scheme",
relative: backyardWorldsPlanet9Scan01,
args: []string{
"--strip", "--interlace", "plane", "--quality", "85", "--scheme", "blur-sf",
"--sample",
"--no-files", "4",
"--strip",
"--interlace", "plane",
"--quality", "85",
"--scheme", "blur-sf",
},
expected: backyardWorldsPlanet9Scan01First6,
expected: backyardWorldsPlanet9Scan01First6,
intermediate: "nasa/exo/Backyard Worlds - Planet 9/sessions/scan-01",
supplement: "blur-sf/TRASH",
inputs: backyardWorldsPlanet9Scan01First4,
},
}),
)
Expand Down
2 changes: 1 addition & 1 deletion src/app/proxy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (c *controller) Run(item *nav.TraverseItem, sequence Sequence) error {

iterator.RunAll(each, while)

return c.shared.fileManager.Tidy()
return c.shared.fileManager.Tidy(&c.private.pi)
}

func (c *controller) Reset() {}
65 changes: 21 additions & 44 deletions src/app/proxy/enter-shrink.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package proxy
import (
"fmt"
"path"
"path/filepath"
"strings"

"github.com/pkg/errors"
Expand All @@ -27,26 +26,16 @@ func (e *ShrinkEntry) LookAheadOptionsFn(o *nav.TraverseOptions) {
o.Callback = &nav.LabelledTraverseCallback{
Label: "LookAhead: Shrink Entry Callback",
Fn: func(item *nav.TraverseItem) error {
// TODO: get the journal filename from path-finder
//
withoutExt := FilenameWithoutExtension(item.Extension.Name) + ".journal.txt"
pathWithoutExt := filepath.Join(item.Extension.Parent, withoutExt)

// TODO(put this back in): only create file if not exits
//
// file, err := os.Create(pathWithoutExt) // TODO: use vfs

// ??? if err == nil {
// defer file.Close()
// }
journalPath := e.FileManager.Finder.JournalFile(item)
err := e.FileManager.Create(journalPath)

fmt.Printf(
"---> 💧💧 SHRINK-JOURNAL-FILE(disabled!!): (create journal:%v) '%v'\n",
pathWithoutExt,
"---> 💧💧 SHRINK-JOURNAL-FILE: (create journal:%v) '%v'\n",
journalPath,
item.Path,
)

return nil
return err
},
}

Expand Down Expand Up @@ -88,14 +77,10 @@ func (e *ShrinkEntry) PrincipalOptionsFn(o *nav.TraverseOptions) {
item.Path,
)

positional := []string{
fmt.Sprintf("'%v'", item.Path),
}

controller := e.Registry.Get()
defer e.Registry.Put(controller)

return controller.OnNewShrinkItem(item, positional)
return controller.OnNewShrinkItem(item)
},
}
}
Expand All @@ -104,11 +89,7 @@ func (e *ShrinkEntry) createFinder() *PathFinder {
finder := &PathFinder{
Scheme: e.Inputs.Root.ProfileFam.Native.Scheme,
ExplicitProfile: e.Inputs.Root.ProfileFam.Native.Profile,
behaviours: strategies{
output: &inlineOutputStrategy{},
deletion: &inlineDeletionStrategy{},
},
arity: 1,
arity: 1,
}

if finder.Scheme != "" {
Expand All @@ -118,14 +99,12 @@ func (e *ShrinkEntry) createFinder() *PathFinder {

if e.Inputs.ParamSet.Native.OutputPath != "" {
finder.Output = e.Inputs.ParamSet.Native.OutputPath
finder.behaviours.output = &ejectOutputStrategy{}
} else {
finder.transparentInput = true
}

if e.Inputs.ParamSet.Native.TrashPath != "" {
finder.Trash = e.Inputs.ParamSet.Native.TrashPath
finder.behaviours.deletion = &ejectOutputStrategy{}
}

return finder
Expand All @@ -145,18 +124,20 @@ func (e *ShrinkEntry) ConfigureOptions(o *nav.TraverseOptions) {
e.EntryBase.ConfigureOptions(o)

finder := e.createFinder()
e.FileManager = &FileManager{
vfs: e.Vfs,
Finder: finder,
}

e.Registry = NewControllerRegistry(&SharedControllerInfo{
Type: ControllerTypeSamplerEn, // TODO: to come from an arg !!!
Options: e.Options,
program: e.Program,
profiles: e.ProfilesCFG,
sampler: e.SamplerCFG,
Inputs: e.Inputs,
finder: finder,
fileManager: &FileManager{
vfs: e.Vfs,
finder: finder,
},
Type: ControllerTypeSamplerEn, // TODO: to come from an arg !!!
Options: e.Options,
program: e.Program,
profiles: e.ProfilesCFG,
sampler: e.SamplerCFG,
Inputs: e.Inputs,
finder: finder,
fileManager: e.FileManager,
})
}

Expand Down Expand Up @@ -200,14 +181,10 @@ func (e *ShrinkEntry) resumeFn(item *nav.TraverseItem) error {
item.Path,
)

positional := []string{
fmt.Sprintf("'%v'", item.Path),
}

controller := e.Registry.Get()
defer e.Registry.Put(controller)

return controller.OnNewShrinkItem(item, positional)
return controller.OnNewShrinkItem(item)
}

func (e *ShrinkEntry) run(_ configuration.ViperConfig) error {
Expand Down
Loading

0 comments on commit 9354a8d

Please sign in to comment.