diff --git a/src/app/proxy/controller-full.go b/src/app/proxy/controller-full.go index c4b5793..152ad23 100644 --- a/src/app/proxy/controller-full.go +++ b/src/app/proxy/controller-full.go @@ -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 diff --git a/src/app/proxy/controller-sampler.go b/src/app/proxy/controller-sampler.go index 3aed905..17c919c 100644 --- a/src/app/proxy/controller-sampler.go +++ b/src/app/proxy/controller-sampler.go @@ -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 // diff --git a/src/app/proxy/controller-sampler_test.go b/src/app/proxy/controller-sampler_test.go index 349eaf2..318cb91 100644 --- a/src/app/proxy/controller-sampler_test.go +++ b/src/app/proxy/controller-sampler_test.go @@ -39,6 +39,8 @@ var ( backyardWorldsPlanet9Scan01First4 []string backyardWorldsPlanet9Scan01First6 []string + backyardWorldsPlanet9Scan01Last4 []string + profilesConfigData proxy.ProfilesConfigMap samplerConfigData *proxy.MsSamplerConfig ) @@ -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", @@ -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", }, @@ -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", @@ -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", @@ -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", @@ -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", }, @@ -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", @@ -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", @@ -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, }, }), ) diff --git a/src/app/proxy/controller.go b/src/app/proxy/controller.go index c5dfdcb..3ba1abf 100644 --- a/src/app/proxy/controller.go +++ b/src/app/proxy/controller.go @@ -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() {} diff --git a/src/app/proxy/enter-shrink.go b/src/app/proxy/enter-shrink.go index 13b713c..04cd89f 100644 --- a/src/app/proxy/enter-shrink.go +++ b/src/app/proxy/enter-shrink.go @@ -3,7 +3,6 @@ package proxy import ( "fmt" "path" - "path/filepath" "strings" "github.com/pkg/errors" @@ -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 }, } @@ -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) }, } } @@ -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 != "" { @@ -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 @@ -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, }) } @@ -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 { diff --git a/src/app/proxy/entry-base.go b/src/app/proxy/entry-base.go index 802f15f..dfdbaa3 100644 --- a/src/app/proxy/entry-base.go +++ b/src/app/proxy/entry-base.go @@ -25,7 +25,7 @@ func summariseAfter(result *nav.TraverseResult, err error) { summary := fmt.Sprintf("files: %v, folders: %v", files, folders) message := lo.Ternary(err == nil, fmt.Sprintf("navigation completed ok (%v) 💝 [%v]", summary, measure), - fmt.Sprintf("error occurred during navigation (%v)❤️💔 [%v]", err, measure), + fmt.Sprintf("error occurred during navigation (%v)💔 [%v]", err, measure), ) fmt.Println(message) } @@ -44,6 +44,7 @@ type EntryBase struct { ProfilesCFG ProfilesConfig SamplerCFG SamplerConfig Vfs storage.VirtualFS + FileManager *FileManager } func (e *EntryBase) ConfigureOptions(o *nav.TraverseOptions) { diff --git a/src/app/proxy/file-manager.go b/src/app/proxy/file-manager.go index 8c78e22..09f06dc 100644 --- a/src/app/proxy/file-manager.go +++ b/src/app/proxy/file-manager.go @@ -18,13 +18,29 @@ const ( // system and nothing else. type FileManager struct { vfs storage.VirtualFS - finder *PathFinder + Finder *PathFinder +} + +func (fm *FileManager) Create(path string) error { + if fm.vfs.FileExists(path) { + return nil + } + + file, err := fm.vfs.Create(path) + + if err != nil { + return err + } + + defer file.Close() + + return nil } // Setup prepares for operation by moving existing file out of the way, // if applicable. Return the path denoting where the input will be moved to. func (fm *FileManager) Setup(pi *pathInfo) (destination string, err error) { - if !fm.finder.transparentInput { + if !fm.Finder.transparentInput { // Any result file must not clash with the input file, so the input // file must stay in place return pi.item.Path, nil @@ -36,7 +52,7 @@ func (fm *FileManager) Setup(pi *pathInfo) (destination string, err error) { // original alone and create other outputs; in this scenario // we don't want to rename/move the source... // - if folder, file := fm.finder.Destination(pi); folder != "" { + if folder, file := fm.Finder.Destination(pi); folder != "" { if err = fm.vfs.MkdirAll(folder, beezledub); err != nil { return errorDestination, errors.Wrapf( err, "could not create parent setup for '%v'", pi.item.Path, @@ -69,21 +85,12 @@ func (fm *FileManager) Setup(pi *pathInfo) (destination string, err error) { return destination, nil } -func (fm *FileManager) move(from, to string) error { - _, _ = from, to +func (fm *FileManager) Tidy(pi *pathInfo) error { + journalFile := fm.Finder.JournalFile(pi.item) - return nil -} - -func (fm *FileManager) delete(target string) error { - _ = target - - return nil -} + if !fm.vfs.FileExists(journalFile) { + return fmt.Errorf("journal file '%v' not found", journalFile) + } -func (fm *FileManager) Tidy() error { - // invoke deletions - // delete journal file - // - return nil + return fm.vfs.Remove(journalFile) } diff --git a/src/app/proxy/general-params.go b/src/app/proxy/general-params.go deleted file mode 100644 index 8f61335..0000000 --- a/src/app/proxy/general-params.go +++ /dev/null @@ -1,8 +0,0 @@ -package proxy - -type FilterParameters struct { - FolderRexEx string - FolderGlob string - FilesRexEx string - FilesGlob string -} diff --git a/src/app/proxy/path-finder.go b/src/app/proxy/path-finder.go index ae73d52..a97593a 100644 --- a/src/app/proxy/path-finder.go +++ b/src/app/proxy/path-finder.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/samber/lo" + "github.com/snivilised/extendio/xfs/nav" ) type pfPath uint @@ -190,11 +191,6 @@ so we have 3 parameters: // PathFinder provides the common paths required, but its the controller that know // the specific paths based around this common framework -type strategies struct { - output outputStrategy - deletion deletionStrategy -} - type PathFinder struct { Scheme string ExplicitProfile string @@ -223,8 +219,6 @@ type PathFinder struct { arity int transparentInput bool - - behaviours strategies } type staticInfo struct { @@ -232,6 +226,12 @@ type staticInfo struct { legacyLabel string } +func (f *PathFinder) JournalFile(item *nav.TraverseItem) string { + path := FilenameWithoutExtension(item.Extension.Name) + ".journal.txt" + + return filepath.Join(item.Extension.Parent, path) +} + // Destination returns the location of what should be used // for the specified source path; ie when the program runs, it uses // a source file and requires the destination location. The source @@ -240,7 +240,7 @@ type staticInfo struct { // folder. // // Destination creates a path for the input; should return empty -// string for the folder, if no move is required (ie transparent) +// string for the folder, if no move is required (ie non transparent) // The PathFinder will only call this function when the input // is not transparent. When the --Trash option is present, it will // determine the destination path for the input. diff --git a/src/app/proxy/proxy-defs.go b/src/app/proxy/proxy-defs.go index 0b86653..d645c7e 100644 --- a/src/app/proxy/proxy-defs.go +++ b/src/app/proxy/proxy-defs.go @@ -30,9 +30,7 @@ type privateControllerInfo struct { // ItemController type ItemController interface { - OnNewShrinkItem(item *nav.TraverseItem, - positional []string, - ) error + OnNewShrinkItem(item *nav.TraverseItem) error Reset() } diff --git a/src/app/proxy/strategy-deletion.go b/src/app/proxy/strategy-deletion.go deleted file mode 100644 index 16454c7..0000000 --- a/src/app/proxy/strategy-deletion.go +++ /dev/null @@ -1,10 +0,0 @@ -package proxy - -type deletionStrategy interface { -} - -type inlineDeletionStrategy struct { -} - -type ejectDeletionStrategy struct { -} diff --git a/src/app/proxy/strategy-output.go b/src/app/proxy/strategy-output.go deleted file mode 100644 index 3bf6374..0000000 --- a/src/app/proxy/strategy-output.go +++ /dev/null @@ -1,32 +0,0 @@ -package proxy - -// the strategies look like they don't do much, so all this -// abstraction feels like overkill. instead the path finder -// could make a one calculation of destination path depending -// on strategy, using s simple func closure, eg we could -// funcs such as inlineDestination and ejectDestination() of -// the form func(source string) string. (rename this file -// strategy-funcs) - -type outputStrategy interface { - // Destination fills in the gap between the root and the destination - Destination(source string) string -} - -type inlineOutputStrategy struct { -} - -func (s *inlineOutputStrategy) Destination(source string) string { - _ = source - // .//TRASH///destination/<.item.Name>..ext - return "" -} - -type ejectOutputStrategy struct { -} - -func (s *ejectOutputStrategy) Destination(source string) string { - _ = source - // .//TRASH///destination - return "" -} diff --git a/test/data/research/nasa-scientist-index.xml b/test/data/research/nasa-scientist-index.xml index ba9d0a4..7b7ab4f 100644 --- a/test/data/research/nasa-scientist-index.xml +++ b/test/data/research/nasa-scientist-index.xml @@ -25,46 +25,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -