common

package
v0.0.0-...-bbac468 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Definitions = definitions{
	Pixa: pixaDefs{
		AppName:            appName,
		Emoji:              "🧙",
		SourceID:           "github.com/snivilised/pixa",
		ConfigTestFilename: fmt.Sprintf("%v-test", appName),
		ConfigType:         yml,
		SubPath:            filepath.Join(org, appName),
		Org:                org,
	},
	ThirdParty: thirdPartyDefs{
		Magick: "magick",
		Dummy:  "dummy",
		Fake:   "fake",
	},
	Commands: commandDefs{
		Shrink: "shrink",
	},
	Defaults: defaultDefs{
		Config: configDefs{
			ConfigFilename: fmt.Sprintf("%v.%v", appName, yml),
		},
		Logging: loggingDefs{
			LogFilename: fmt.Sprintf("%v.log", appName),
		},
	},
	Environment: environmentDefs{
		Home:   "PIXA_HOME",
		UseXDG: "PIXA_XDG",
	},
	Filing: filingDefs{
		JournalExt:    ".txt",
		Discriminator: ".$",
	},
	Interaction: interactionDefs{
		Names: struct {
			Discovery string
			Primary   string
		}{
			Discovery: "discover",
			Primary:   "primary",
		},
	},
}
View Source
var InterlaceEnumInfo = assistant.NewEnumInfo(assistant.AcceptableEnumValues[InterlaceEnum]{
	InterlaceNoneEn:      []string{"none", "n"},
	InterlaceLineEn:      []string{"line", "l"},
	InterlacePlaneEn:     []string{"plane", "pl"},
	InterlacePartitionEn: []string{"partition", "pa"},
	InterlaceJPEGEn:      []string{"jpeg", "j"},
	InterlaceGIFEn:       []string{"gif", "g"},
	InterlacePNGEn:       []string{"png", "p"},
})
View Source
var Permissions = permissions{
	Write:       write,
	Faydeaudeau: faydeaudeau,
	Beezledub:   beezledub,
}
View Source
var SamplingFactorEnumInfo = assistant.NewEnumInfo(assistant.AcceptableEnumValues[SamplingFactorEnum]{
	SamplingFactor420En: []string{"4:2:0", "420", "4"},
	SamplingFactor2x1En: []string{"2x1", "21", "2"},
})

Functions

func IsUsingXDG

func IsUsingXDG(vc configuration.ViperConfig) bool

Types

type AdvancedConfig

type AdvancedConfig interface {
	AbortOnError() bool
	AdhocLabel() string
	JournalLabel() string
	LegacyLabel() string
	TrashLabel() string
	FakeLabel() string
	SupplementLabel() string
	SampleLabel() string
	Extensions() ExtensionsConfig
	Executable() ExecutableConfig
}

type AfterFunc

type AfterFunc func(*nav.TraverseResult, error)

type CallbackOnBegin

type CallbackOnBegin interface {
	Notify(finder PathFinder, scheme, profile string)
}

type CallbackOnBeginFunc

type CallbackOnBeginFunc func(finder PathFinder, scheme, profile string)

func (CallbackOnBeginFunc) Notify

func (f CallbackOnBeginFunc) Notify(finder PathFinder, scheme, profile string)

type ClientTraverseInfo

type ClientTraverseInfo interface {
	Name() string
	// ActiveOptionsFn allows the client to obtain the options func
	// for the current phase.
	ActiveOptionsFn() nav.TraverseOptionFn

	RunWith() nav.CreateNewRunnerWith
	Resumption() *nav.Resumption
	IsDryRun() bool
}

ClientTraverseInfo represents an entity which needs start a navigation operation.

type ConfigInfo

type ConfigInfo struct {
	Name       string
	ConfigType string
	ConfigPath string
	Viper      configuration.ViperConfig
	Scope      ConfigScope
}

type ConfigRunner

type ConfigRunner interface {
	Run() error
	DefaultPath() string
}

type ConfigScope

type ConfigScope interface {
	ConfigDirs() ([]string, error)
	LogPath(filename string) (string, error)
}

type Configs

type Configs struct {
	Profiles    ProfilesConfig
	Schemes     SchemesConfig
	Sampler     SamplerConfig
	Interaction InteractionConfig
	Advanced    AdvancedConfig
	Logging     LoggingConfig
}

type DiscoveredMsg

type DiscoveredMsg struct {
	Result *nav.TraverseResult
	Err    error
}

DiscoveredMsg indicates that the discovery phase has completed.

type DriverTraverseInfo

type DriverTraverseInfo interface {
	ClientTraverseInfo
	// Next allows the driver to indicate switching over to the next
	// phase of traversal. The underlying info object starts off in
	// discovery state, the driver switches it into the principal
	// phase by calling Next.
	Next()
}

DriverTraverseInfo represents the controller entity that controls the whole traversal consisting of discovery and principal phases.

type ExecutableConfig

type ExecutableConfig interface {
	Symbol() string
	ProgramTimeout() (duration time.Duration, err error)
	NoRetries() uint
}

type ExecutionAgent

type ExecutionAgent interface {
	// IsInstalled determines whether the underlying program is installed
	IsInstalled() bool

	// Invoke returns the command line args required for the executor to
	// run correctly. Only the source and destination are required because
	// they are the dynamic args that change for each invocation. All the
	// other flags that come directly from the command line/config possibly
	// via a profile are static, which means the concrete agent will already
	// have those and merely has to formulate the complete command line in
	// the correct order required by the third party program.
	Invoke(thirdPartyCL clif.ThirdPartyCommandLine, source, destination string) error
}

type Executor

type Executor interface {
	ProgName() string
	Look() (string, error)
	Execute(args ...string) error
}

type ExtensionsConfig

type ExtensionsConfig interface {
	Suffixes() string
	Transforms() string
	Map() map[string]string
}

type FileManager

type FileManager interface {
	Finder() PathFinder
	FileExists(pathAt string) bool
	DirectoryExists(pathAt string) bool
	Create(path string, overwrite bool) error
	Setup(pi *PathInfo) (destination string, err error)
	Tidy(pi *PathInfo) error
}

type FinishedMsg

type FinishedMsg struct {
	Result *nav.TraverseResult
	Err    error
}

FinishedMsg indicates end of traversal

type InteractionConfig

type InteractionConfig interface {
	TuiConfig() TuiConfig
}

type InterlaceEnum

type InterlaceEnum int
const (
	InterlaceNoneEn InterlaceEnum
	InterlaceLineEn
	InterlacePlaneEn
	InterlacePartitionEn
	InterlaceJPEGEn
	InterlaceGIFEn
	InterlacePNGEn
)

type ItemController

type ItemController interface {
	OnNewShrinkItem(item *nav.TraverseItem) error
	Reset()
}

ItemController

type JournalMetaInfo

type JournalMetaInfo struct {
	Core          string // without any decoration
	Actual        string // used as part of the journal file name
	WithoutExt    string
	Extension     string // .txt
	Discriminator string // the journal/sample file discriminator (.$)
}

type LifecycleNotifications

type LifecycleNotifications struct {
	OnBegin CallbackOnBeginFunc
}

type LoggingConfig

type LoggingConfig interface {
	Path() string
	MaxSizeInMb() uint
	MaxNoOfBackups() uint
	MaxAgeInDays() uint
	Level() string
	TimeFormat() string
}

type Observers

type Observers struct {
	PathFinder PathFinder
}

type PathFinder

type PathFinder interface {
	Transfer(info *PathInfo) (folder, file string)
	Result(info *PathInfo) (folder, file string)
	FolderSupplement(profile string) string
	FileSupplement(profile, withSampling string) string
	SampleFileSupplement(withSampling string) string
	TransparentInput() bool
	JournalFullPath(item *nav.TraverseItem) string
	Statics() *StaticInfo
	Scheme() string
	Observe(o PathFinder) PathFinder
}

type PathInfo

type PathInfo struct {
	Item       *nav.TraverseItem
	Origin     string
	Scheme     string
	Profile    string
	RunStep    RunStepInfo
	IsCuddling bool
	IsSampling bool
	Output     string
	Trash      string
}

type PresentationOptions

type PresentationOptions struct {
	WithoutRenderer bool
}

type PrivateControllerInfo

type PrivateControllerInfo struct {
	Destination string
	Pi          PathInfo
}

type ProfilesConfig

type ProfilesConfig interface {
	Profile(name string) (clif.ChangedFlagsMap, bool)
}

type ProfilesConfigMap

type ProfilesConfigMap map[string]clif.ChangedFlagsMap

func (ProfilesConfigMap) Validate

func (pc ProfilesConfigMap) Validate(name string) error

type ProfilesFlagOptionAsAnyPair

type ProfilesFlagOptionAsAnyPair = map[string]any

type ProgressMsg

type ProgressMsg struct {
	Source      string
	Destination string
	Scheme      string
	Profile     string
	Err         error
}

ProgressMsg indicates a job completion

type RootParameterSet

type RootParameterSet struct {
	Directory  string
	IsSampling bool
	NoFiles    uint
	NoFolders  uint
	Last       bool
}

type RunStepInfo

type RunStepInfo struct {
	Source string
}

type SamplerConfig

type SamplerConfig interface {
	NoFiles() uint
	NoFolders() uint
}

type SamplingFactorEnum

type SamplingFactorEnum int
const (
	SamplingFactor420En SamplingFactorEnum
	SamplingFactor2x1En
)

type SchemeConfig

type SchemeConfig interface {
	Profiles() []string
}

type SchemesConfig

type SchemesConfig interface {
	Validate(name string, profiles ProfilesConfig) error
	Scheme(name string) (SchemeConfig, bool)
}

type Sequence

type Sequence []Step

Sequence

type SessionControllerInfo

type SessionControllerInfo struct {
	Agent       ExecutionAgent
	Inputs      *ShrinkCommandInputs
	FileManager FileManager
	Interaction UserInteraction
}

type ShrinkCommandInputs

type ShrinkCommandInputs struct {
	Root     *RootCommandInputs
	ParamSet *assistant.ParamSet[ShrinkParameterSet]
	PolyFam  *assistant.ParamSet[store.PolyFilterParameterSet]
}

type ShrinkParameterSet

type ShrinkParameterSet struct {
	ThirdPartySet
	//
	OutputPath string
	TrashPath  string
	Cuddle     bool
}

type StaticInfo

type StaticInfo struct {
	Adhoc      string
	Journal    JournalMetaInfo
	Legacy     string
	Trash      string
	Fake       string
	Supplement string
	Sample     string
}

func NewStaticInfoFromConfig

func NewStaticInfoFromConfig(advanced AdvancedConfig) *StaticInfo

func (*StaticInfo) FileSupplement

func (i *StaticInfo) FileSupplement(baseFilename, supp string) string

func (*StaticInfo) JournalFilterGlob

func (i *StaticInfo) JournalFilterGlob() string

func (*StaticInfo) JournalFilterRegex

func (i *StaticInfo) JournalFilterRegex(sourcePattern, suffixesCSV string) string

func (*StaticInfo) JournalLocation

func (i *StaticInfo) JournalLocation(name, parent string) string

func (*StaticInfo) TrashTag

func (i *StaticInfo) TrashTag() string

type Step

type Step interface {
	Run(pi *PathInfo) error
}

type ThirdPartySet

type ThirdPartySet struct {
	GaussianBlur     float32
	SamplingFactorEn assistant.EnumValue[SamplingFactorEnum]
	InterlaceEn      assistant.EnumValue[InterlaceEnum]
	Strip            bool
	Quality          int
	// Auxiliary
	//
	LongChangedCL cobrass.ThirdPartyCommandLine
	KnownBy       cobrass.KnownByCollection
}

ThirdPartySet represents flags that are only of use to the third party application being invoked (ie magick). These flags are of no significance to pixa, but we have to define them explicitly, because of a deficiency in cobra in the way it handles third party args. The convention in command line interfaces is that the double dash delineates arguments for third parties, and cobra does support this, but what it does not support is to extract and provide some way to access those args. Pixa needs this functionality so it can pass them onto magick. As it stands, we can't access those args (after the --), so we have to define them explicitly, then pass them on. This is less than desirable, because magick has a vast flag set, which in theory would mean re-implementing them all on pixa. We only define the ones relevant to compressing images.

type TraverseInfoTrash

type TraverseInfoTrash struct {
	DiscoverOptionsFn  nav.TraverseOptionFn
	PrincipalOptionsFn nav.TraverseOptionFn
	With               nav.CreateNewRunnerWith
	Resumption         *nav.Resumption
	IsDryRun           bool
}

type TuiConfig

type TuiConfig interface {
	PerItemDelay() time.Duration
}

type UserInteraction

type UserInteraction interface {
	// Decorate allows the interaction to provide a wrapper around the callback.
	// If the interaction does not need it, then it just returns the target. Only
	// the Principal callback is decorated.
	//
	Decorate(target *nav.LabelledTraverseCallback) *nav.LabelledTraverseCallback

	// Performs the full traversal which consists of a discovery navigation followed
	// by the principal navigation.
	Traverse(di DriverTraverseInfo) (*nav.TraverseResult, error)

	// Tick allows the model to be updated, as activity occurs during
	// the traversal.
	//
	Tick(progress *ProgressMsg)
}

type WalkInfo

type WalkInfo struct {
	DiscoverOptionsFn  nav.TraverseOptionFn
	PrincipalOptionsFn nav.TraverseOptionFn
	With               nav.CreateNewRunnerWith
	Resumption         *nav.Resumption
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL