Skip to content

Commit

Permalink
feat(proxy): implement sampling non transparency mode (#82)
Browse files Browse the repository at this point in the history
ref(proxy): implement sampling non transparent (#82)

ref(proxy): consolidate path info (#82)
  • Loading branch information
plastikfan committed Dec 24, 2023
1 parent 1848646 commit 71b28fd
Show file tree
Hide file tree
Showing 12 changed files with 216 additions and 126 deletions.
5 changes: 2 additions & 3 deletions src/app/command/shrink-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/snivilised/cobrass/src/assistant"
"github.com/snivilised/cobrass/src/store"
xi18n "github.com/snivilised/extendio/i18n"
"github.com/snivilised/extendio/xfs/utils"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -166,7 +165,7 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob
defaultOutputPath,
),
&paramSet.Native.OutputPath, func(s string, f *pflag.Flag) error {
if f.Changed && !utils.FolderExists(s) {
if f.Changed && !b.Vfs.DirectoryExists(s) {
return i18n.NewOutputPathDoesNotExistError(s)
}

Expand All @@ -186,7 +185,7 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob
defaultTrashPath,
),
&paramSet.Native.TrashPath, func(s string, f *pflag.Flag) error {
if f.Changed && !utils.FolderExists(s) {
if f.Changed && !b.Vfs.DirectoryExists(s) {
return i18n.NewOutputPathDoesNotExistError(s)
}

Expand Down
3 changes: 2 additions & 1 deletion src/app/proxy/controller-registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ func NewControllerRegistry(shared *SharedControllerInfo) *ControllerRegistry {
case ControllerTypeSamplerEn:
return &SamplerController{
controller: controller{
shared: shared,
shared: shared,
private: &privateControllerInfo{},
},
}
}
Expand Down
21 changes: 14 additions & 7 deletions src/app/proxy/controller-sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,27 @@ func (c *SamplerController) OnNewShrinkItem(item *nav.TraverseItem,
) error {
_ = positional

profileName := c.shared.Inputs.Root.ProfileFam.Native.Profile
schemeName := c.shared.Inputs.Root.ProfileFam.Native.Scheme
// create a master path info here and pass into the sequences
// to replace the individual properties on the step
//
pi := &pathInfo{
item: item,
scheme: c.shared.Inputs.Root.ProfileFam.Native.Scheme,
profile: c.shared.Inputs.Root.ProfileFam.Native.Profile,
origin: item.Extension.Parent,
}

var sequence Sequence

switch {
case profileName != "":
sequence = c.profileSequence(profileName, item.Path)
case pi.profile != "":
sequence = c.profileSequence(pi)

case schemeName != "":
sequence = c.schemeSequence(schemeName, item.Path)
case pi.scheme != "":
sequence = c.schemeSequence(pi)

default:
sequence = c.adhocSequence(item.Path)
sequence = c.adhocSequence(pi)
}

return c.Run(item, sequence)
Expand Down
97 changes: 97 additions & 0 deletions src/app/proxy/controller-sampler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ func init() {
"adaptive-blur": proxy.MsSchemeConfig{
Profiles: []string{"adaptive", "blur"},
},
"singleton": proxy.MsSchemeConfig{
Profiles: []string{"adaptive"},
},
},
}
}
Expand Down Expand Up @@ -163,6 +166,8 @@ type controllerTE struct {
given string
should string
args []string
outputFlag string
trashFlag string
profile string
relative string
expected []string
Expand Down Expand Up @@ -246,6 +251,16 @@ var _ = Describe("SamplerController", Ordered, func() {
}
args := options
args = append(args, entry.args...)
if entry.outputFlag != "" {
output := helpers.Path(root, entry.outputFlag)
args = append(args, "--output")
args = append(args, output)
}
if entry.trashFlag != "" {
trash := helpers.Path(root, entry.trashFlag)
args = append(args, "--trash")
args = append(args, trash)
}

bootstrap := command.Bootstrap{
Vfs: vfs,
Expand Down Expand Up @@ -335,6 +350,88 @@ var _ = Describe("SamplerController", Ordered, func() {
},
}),

Entry(nil, &samplerTE{
controllerTE: controllerTE{
given: "run transparent with scheme with single profile",
should: "sample(first) with glob filter, result file takes place of input",
relative: backyardWorldsPlanet9Scan01,
args: []string{
"--sample",
"--no-files", "4",
"--files-gb", "*Backyard Worlds*",
"--scheme", "singleton",
"--gaussian-blur", "0.51",
"--interlace", "line",
},
expected: backyardWorldsPlanet9Scan01First4,
intermediate: "nasa/exo/Backyard Worlds - Planet 9/sessions/scan-01",
supplement: "singleton/TRASH",
inputs: backyardWorldsPlanet9Scan01First4,
},
}),

Entry(nil, &samplerTE{
controllerTE: controllerTE{
given: "run non transparent adhoc",
should: "sample(first) with glob filter, input moved to alternative location",
relative: backyardWorldsPlanet9Scan01,
args: []string{
"--sample",
"--no-files", "4",
"--files-gb", "*Backyard Worlds*",
"--gaussian-blur", "0.51",
"--interlace", "line",
},
trashFlag: "discard",
expected: backyardWorldsPlanet9Scan01First4,
intermediate: "discard",
supplement: "ADHOC/TRASH",
inputs: backyardWorldsPlanet9Scan01First4,
},
}),

Entry(nil, &samplerTE{
controllerTE: controllerTE{
given: "run non transparent with profile",
should: "sample(first) with glob filter, input moved to alternative location",
relative: backyardWorldsPlanet9Scan01,
args: []string{
"--sample",
"--no-files", "4",
"--files-gb", "*Backyard Worlds*",
"--profile", "adaptive",
"--gaussian-blur", "0.51",
"--interlace", "line",
},
trashFlag: "discard",
expected: backyardWorldsPlanet9Scan01First4,
intermediate: "discard",
supplement: "adaptive/TRASH",
inputs: backyardWorldsPlanet9Scan01First4,
},
}),

Entry(nil, &samplerTE{
controllerTE: controllerTE{
given: "run non transparent scheme single with profile",
should: "sample(first) with glob filter, input moved to alternative location",
relative: backyardWorldsPlanet9Scan01,
args: []string{
"--sample",
"--no-files", "4",
"--files-gb", "*Backyard Worlds*",
"--scheme", "singleton",
"--gaussian-blur", "0.51",
"--interlace", "line",
},
trashFlag: "discard",
expected: backyardWorldsPlanet9Scan01First4,
intermediate: "discard",
supplement: "singleton/TRASH",
inputs: backyardWorldsPlanet9Scan01First4,
},
}),

XEntry(nil, &samplerTE{
controllerTE: controllerTE{
given: "profile",
Expand Down
62 changes: 32 additions & 30 deletions src/app/proxy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,42 @@ import (
//

type controller struct {
shared *SharedControllerInfo
local localControllerInfo
shared *SharedControllerInfo
private *privateControllerInfo
}

func (c *controller) profileSequence(
name, itemPath string,
pi *pathInfo,
) Sequence {
changed := c.shared.Inputs.ParamSet.Native.ThirdPartySet.LongChangedCL
cl := c.composeProfileCL(name, changed)
cl := c.composeProfileCL(pi.profile, changed)
step := &magickStep{
shared: c.shared,
thirdPartyCL: cl,
sourcePath: itemPath,
profile: name,
// outputPath: ,
sourcePath: pi.item.Path,
profile: pi.profile,
outputPath: c.shared.Inputs.ParamSet.Native.OutputPath,
// journalPath: ,
}

return Sequence{step}
}

func (c *controller) schemeSequence(
name, itemPath string,
pi *pathInfo,
) Sequence {
changed := c.shared.Inputs.ParamSet.Native.ThirdPartySet.LongChangedCL
schemeCfg, _ := c.shared.sampler.Scheme(name) // scheme already validated
schemeCfg, _ := c.shared.sampler.Scheme(pi.scheme) // scheme already validated
sequence := make(Sequence, 0, len(schemeCfg.Profiles))

for _, current := range schemeCfg.Profiles {
cl := c.composeProfileCL(current, changed)
step := &magickStep{
shared: c.shared,
thirdPartyCL: cl,
sourcePath: itemPath,
scheme: name,
sourcePath: pi.item.Path,
profile: current,
// outputPath: ,
outputPath: c.shared.Inputs.ParamSet.Native.OutputPath,
// journalPath: ,
}

Expand All @@ -61,14 +60,14 @@ func (c *controller) schemeSequence(
}

func (c *controller) adhocSequence(
itemPath string,
pi *pathInfo,
) Sequence {
changed := c.shared.Inputs.ParamSet.Native.ThirdPartySet.LongChangedCL
step := &magickStep{
shared: c.shared,
thirdPartyCL: changed,
sourcePath: itemPath,
// outputPath: ,
sourcePath: pi.item.Path,
outputPath: c.shared.Inputs.ParamSet.Native.OutputPath,
// journalPath: ,
}

Expand All @@ -90,26 +89,29 @@ func (c *controller) composeProfileCL(

func (c *controller) Run(item *nav.TraverseItem, sequence Sequence) error {
var (
zero Step
resultErr error
zero Step
err error
)

iterator := collections.ForwardRunIt[Step, error](sequence, zero)
each := func(step Step) error {
return step.Run(&RunStepInfo{
Item: item,
Source: c.local.destination,
})
return step.Run(&c.private.pi)
}
while := func(_ Step, err error) bool {
if resultErr == nil {
resultErr = err
while := func(_ Step, e error) bool {
if err == nil {
err = e
}

// TODO: this needs to change according to a new, not yet defined
// setting, 'ContinueOnError'
//
return err == nil
return e == nil
}

c.private.pi = pathInfo{
item: item,
origin: item.Parent.Path,
scheme: c.shared.finder.Scheme,
}

// TODO: need to decide a proper policy for cleaning up
Expand All @@ -119,15 +121,15 @@ func (c *controller) Run(item *nav.TraverseItem, sequence Sequence) error {
// Perhaps we have an error policy including one that implements
// a retry.
//
if c.local.destination, resultErr = c.shared.fileManager.Setup(item); resultErr != nil {
return resultErr
if c.private.pi.runStep.Source, err = c.shared.fileManager.Setup(
&c.private.pi,
); err != nil {
return err
}

iterator.RunAll(each, while)

return c.shared.fileManager.Tidy()
}

func (c *controller) Reset() {
c.local.destination = ""
}
func (c *controller) Reset() {}
4 changes: 2 additions & 2 deletions src/app/proxy/enter-shrink.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ func (e *ShrinkEntry) PrincipalOptionsFn(o *nav.TraverseOptions) {

func (e *ShrinkEntry) createFinder() *PathFinder {
finder := &PathFinder{
Scheme: e.Inputs.Root.ProfileFam.Native.Scheme,
Profile: e.Inputs.Root.ProfileFam.Native.Profile,
Scheme: e.Inputs.Root.ProfileFam.Native.Scheme,
ExplicitProfile: e.Inputs.Root.ProfileFam.Native.Profile,
behaviours: strategies{
output: &inlineOutputStrategy{},
deletion: &inlineDeletionStrategy{},
Expand Down
18 changes: 4 additions & 14 deletions src/app/proxy/execution-step.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ import (
"path/filepath"

"github.com/snivilised/cobrass/src/clif"
"github.com/snivilised/extendio/xfs/nav"
)

// Step
type (
RunStepInfo struct {
Item *nav.TraverseItem
Source string
}

Step interface {
Run(rsi *RunStepInfo) error
Run(pi *pathInfo) error
}

// Sequence
Expand All @@ -29,25 +27,17 @@ type (
type magickStep struct {
shared *SharedControllerInfo
thirdPartyCL clif.ThirdPartyCommandLine
scheme string
profile string
sourcePath string
outputPath string
journalPath string
}

// Run
func (s *magickStep) Run(rsi *RunStepInfo) error {
folder, file := s.shared.finder.Result(&resultInfo{
pathInfo: pathInfo{
item: rsi.Item,
origin: rsi.Item.Extension.Parent,
},
scheme: s.scheme,
profile: s.profile,
})
func (s *magickStep) Run(pi *pathInfo) error {
folder, file := s.shared.finder.Result(pi)
result := filepath.Join(folder, file)
input := []string{rsi.Source}
input := []string{pi.runStep.Source}

// if transparent, then we need to ask the fm to move the
// existing file out of the way. But shouldn't that already have happened
Expand Down
Loading

0 comments on commit 71b28fd

Please sign in to comment.