Skip to content

Commit

Permalink
ref(proxy): add supporting code for strategies and some tidy up (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Dec 16, 2023
1 parent ea3dc52 commit 8cf2b99
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 68 deletions.
20 changes: 0 additions & 20 deletions src/app/command/root-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
xi18n "github.com/snivilised/extendio/i18n"
"github.com/snivilised/pixa/src/app/proxy"
"github.com/snivilised/pixa/src/i18n"
"github.com/spf13/pflag"
"golang.org/x/text/language"
)

const (
Expand All @@ -32,24 +30,6 @@ func (b *Bootstrap) buildRootCommand(container *assistant.CobraContainer) {
rootCommand := container.Root()
paramSet := assistant.NewParamSet[proxy.RootParameterSet](rootCommand)

// --lang (TODO: should really come from the family store,
// as its a generic concept.)
//
paramSet.BindValidatedString(&assistant.FlagInfo{
Name: "lang",
Usage: i18n.LeadsWith(
"lang",
xi18n.Text(i18n.RootCmdLangUsageTemplData{}),
),
Default: xi18n.DefaultLanguage.Get().String(),
AlternativeFlagSet: rootCommand.PersistentFlags(),
},
&paramSet.Native.Language,
func(value string, _ *pflag.Flag) error {
_, err := language.Parse(value)
return err
})

// --sample (pending: sampling-family)
//
paramSet.BindBool(&assistant.FlagInfo{
Expand Down
20 changes: 10 additions & 10 deletions src/app/command/shrink-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
// file and the short forms would be x and g instead of X and G.

var thirdPartyFlags = cobrass.KnownByCollection{
// third-party:
// third-party: (perhaps third party parameters should not have short codes)
//
"gaussian-blur": "b",
"sampling-factor": "f",
Expand All @@ -46,17 +46,17 @@ var shrinkShortFlags = cobrass.KnownByCollection{
//
"mirror-path": "r",
"mode": "m",
// root:
// families:
//
"cpu": "C",
"cpu": "C", // family: worker-pool
"now": "N", // family: worker-pool
"dry-run": "D", // family: preview
"files-gb": "G",
"files-rx": "X",
"folders-gb": "Z",
"folders-rx": "Y",
"now": "N",
"profile": "P",
"scheme": "S",
"files-gb": "G", // family: filter
"files-rx": "X", // family: filter
"folders-gb": "Z", // family: filter
"folders-rx": "Y", // family: filter
"profile": "P", // family: profile
"scheme": "S", // family: profile
}

func init() {
Expand Down
10 changes: 10 additions & 0 deletions src/app/proxy/enter-shrink.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ func (e *ShrinkEntry) PrincipalOptionsFn(o *nav.TraverseOptions) {
}
}

func (e *ShrinkEntry) createFinder() *PathFinder {
return &PathFinder{
Behaviours: strategies{
output: inlineOutputStrategy{}, // mirrorOutputStrategy{}
deletion: inlineDeletionStrategy{}, // mirrorDeletionStrategy{}
},
}
}

func (e *ShrinkEntry) ConfigureOptions(o *nav.TraverseOptions) {
o.Notify.OnBegin = func(_ *nav.NavigationState) {
fmt.Printf("===> 🛡️ beginning traversal ...\n")
Expand All @@ -119,6 +128,7 @@ func (e *ShrinkEntry) ConfigureOptions(o *nav.TraverseOptions) {
profiles: e.ProfilesCFG,
sampler: e.SamplerCFG,
Inputs: e.Inputs,
finder: e.createFinder(),
})
}

Expand Down
9 changes: 8 additions & 1 deletion src/app/proxy/execution-step.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,12 @@ type magickStep struct {
func (s *magickStep) Run() error {
positional := []string{s.sourcePath}

return s.program.Execute(clif.Expand(positional, s.thirdPartyCL)...)
// prepare: move existing file out of the way

err := s.program.Execute(clif.Expand(positional, s.thirdPartyCL)...)

// invoke deletions
// delete journal file

return err
}
2 changes: 0 additions & 2 deletions src/app/proxy/image-defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ type RootParameterSet struct { // should contain RootCommandInputs
NoFiles uint
NoFolders uint
Last bool
Language string // TODO: move this to family store
}

type (
ProfilesFlagOptionAsAnyPair = map[string]any
ProfilesFlagOptionPairL = map[string]string
ProfilesConfigMap map[string]clif.ChangedFlagsMap
)

Expand Down
52 changes: 34 additions & 18 deletions src/app/proxy/path-finder.go
Original file line number Diff line number Diff line change
@@ -1,52 +1,66 @@
package proxy

// INLINE-MODE: MIRROR | INLINE (should we call this a strategy?
// INLINE-MODE: EJECT | INLINE (should we call this a strategy?
// they do the same thing but create a different output structure => OutputStrategy)
//
// MIRROR: replicate the source directory struct but mirror elsewhere
// EJECT: replicate the source directory struct but eject elsewhere
// INLINE: create the file at the same location as the original but rename as required

// The runner is aware of the output strategy moving files accordingly,
// using the path-finder to create the paths and the file-manager to interact
// with the file system, using a vfs.

// Then we can also have a deletion strategy, use a central location or inline
// CENTRAL-LOCATION: is like MIRROR
// CENTRAL-LOCATION: is like EJECT
// INLINE: INLINE

// Can we have 2 different strategies at the same time?, ie:
// OUTPUT-STRATEGY: INLINE
// DELETION-STRATEGY: MIRROR
// DELETION-STRATEGY: EJECT
//
// ... well in this case, the output file would be in the same folder
// as item.Path, but the TRASH folder would be relative to mirror-path (ie in
// as item.Path, but the TRASH folder would be relative to eject-path (ie in
// the same folder as item.Path) and the

/* mirror parameters:
/* eject parameters:
we can't have --mirror, because ambiguous, which strategy does this apply to?
(but what we could say is --mirror if specified applies to output && deletion)
we can't have --eject, because ambiguous, which strategy does this apply to?
(but what we could say is --eject if specified applies to output && deletion)
- the same goes for inline, but --inline would be a switch, not a flag
==> --mirror(path) & --inline [still needs a way to specify how to manage renames]
==> --eject(path) & --inline [still needs a way to specify how to manage renames]
both strategies set to eject or inline(~transparent mode)
if we say this, then --inline could be redundant, ie if --eject is not set,
then we revert to the default which is eject(transparent)
-- then other flags could adjust the transparent mode
if --eject not specified, then ous=inline; des=inline
but if can be adjusted by --output <path>, --trash <path>
-- perhaps we have a transparency mode, ie perform renames such that the new generated
files adopt the existing files, so there is no difference, except for the original
file would be renamed to something else. With transparency enabled, we make all the
decisions woo make this possible, we internally make the choice of which strategies
decisions to make this possible, we internally make the choice of which strategies
are in place, so the user doesn't have to work this out for themselves. But the
deletion strategy is independent of transparency, so it really only applies to output.
Or, perhaps, do we assume transparent by default and the other options adjust this.
and/or
--output-path
--trash-strategy (inline|mirror)
so we have 3 parameters:
* neither --output or --trash specified [ous=eject; des=eject];
* --output <path> [ous=eject; des=inline]
* --trash <path> [ous=inline; des=eject]
* --output <path> --trash <path> [ous=eject; des=eject]
*/

// PathFinder provides the common paths required, but its the runners that know
// the specific paths based around this common framework

type strategies struct {
output outputStrategy
deletion deletionStrategy
}

type PathFinder struct {
// is this item.Path or item.Path's parent folder?
//
Expand All @@ -60,12 +74,14 @@ type PathFinder struct {
// perhaps represented as a slice so it can be joined with filepath.Join
//
// if MirrorPath is set, then use this as the output, but also
// create the intermediate in order to implement mirroring
// create the intermediate paths in order to implement mirroring
//
Output string

// I think this depends on the mode (tidy/preserve)
Trash string

Behaviours strategies
}

/*
Expand All @@ -80,10 +96,10 @@ contains:
- path-manager
*** path-manager needs to provide the following paths
- output directory (inline | mirror)
- output directory (inline | eject)
- trash file location (central or local)
- for sampling scheme, we use profile name as part of the relative output path
- output root (depends on mirror)
- output root (depends on eject)
behaviour of naming output files:
- output filename (same as input file with a suffix | backup input, replace input file)
Expand Down
1 change: 1 addition & 0 deletions src/app/proxy/proxy-defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type SharedRunnerInfo struct {
profiles ProfilesConfig
sampler SamplerConfig
Inputs *ShrinkCommandInputs
finder *PathFinder
}

// ItemController
Expand Down
2 changes: 1 addition & 1 deletion src/app/proxy/runner-base.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// scheme: adhoc and profile from a scheme
//

type baseRunner struct {
type baseRunner struct { // rename to be a controller instead of a runner
shared *SharedRunnerInfo
}

Expand Down
14 changes: 0 additions & 14 deletions src/app/proxy/runner-sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,6 @@ func (r *SamplerRunner) OnNewShrinkItem(item *nav.TraverseItem,
) error {
_ = positional

// foreach profileName inside the scheme:
// start off with (*r.shared.profilesCFG)[blurProfile] => copy into another map: current
// foreach args in secondary
// if secondary arg not present in current, add to current
// if secondary arg not present in current, if not already in current
// ---
// - at end, we end up with a map(current) that contains profileName args combined with present
// - add the current to end of positional to create a clif.ThirdPartyCommandLine: useCL
// to achieve this Overlay needs the KnownBy collection the same way Evaluate does;
// the reason is although we can limit the flags specified inside the config to be
// of their long forms, the arguments present on the command line must be free to be
// either long or short forms, therefore we, need to be able to recognise if a short form
// flag in present is actually in present in the config as its long form.
//
profileName := r.shared.Inputs.Root.ProfileFam.Native.Profile
schemeName := r.shared.Inputs.Root.ProfileFam.Native.Scheme

Expand Down
10 changes: 10 additions & 0 deletions src/app/proxy/strategy-deletion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package proxy

type deletionStrategy interface {
}

type inlineDeletionStrategy struct {
}

type ejectDeletionStrategy struct {
}
10 changes: 10 additions & 0 deletions src/app/proxy/strategy-output.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package proxy

type outputStrategy interface {
}

type inlineOutputStrategy struct {
}

type ejectOutputStrategy struct {
}
7 changes: 5 additions & 2 deletions test/data/configuration/pixa-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ sampler:
profiles: ["adaptive", "blur"]
advanced:
abort-on-error: false
legacy-file-suffix: LEGACY
journal-suffix: JOURNAL
external-program-execution-timeout: "20s"
external-program-execution-retry: 0
legacy-file-dot-suffix: LEGACY
journal-file-dot-suffix: JOURNAL
trash-folder: TRASH

0 comments on commit 8cf2b99

Please sign in to comment.