metabase

package module
v0.0.0-...-3e0d747 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2018 License: LGPL-2.1 Imports: 36 Imported by: 6

Documentation

Index

Constants

View Source
const FileFingerprintSize = 16777216

Variables

View Source
var ChecksumPolicy = SyncPolicy{
	Fields: []string{`checksum`},
}
View Source
var CleanupIterations = 256
View Source
var DefaultBaseDirectory = `~/.config/metabase`
View Source
var DefaultGlobalExclusions = []string{
	`._.DS_Store`,
	`._.Trashes`,
	`.DS_Store`,
	`.Spotlight-V100`,
	`.Trashes`,
	`desktop.ini`,
	`lost+found`,
	`Thumbs.db`,
}
View Source
var DefaultManifestFields = []string{`id`, `relative_path`, `type`}
View Source
var MaxChildEntries = 10000
View Source
var MaxTimeBetweenDeepScans = time.Duration(0)
View Source
var Metadata mapper.Mapper
View Source
var MetadataEncoding = base32.NewEncoding(`abcdefghijklmnopqrstuvwxyz234567`)
View Source
var MetadataSchema = &dal.Collection{
	Name:              `metadata`,
	IdentityFieldType: dal.StringType,
	Fields: []dal.Field{
		{
			Name:     `name`,
			Type:     dal.StringType,
			Required: true,
		}, {
			Name:     `parent`,
			Type:     dal.StringType,
			Required: true,
		}, {
			Name: `type`,
			Type: dal.StringType,
		}, {
			Name:      `size`,
			Type:      dal.IntType,
			Validator: dal.ValidatePositiveOrZeroInteger,
		}, {
			Name: `checksum`,
			Type: dal.StringType,
		}, {
			Name:     `root_group`,
			Type:     dal.StringType,
			Required: true,
		}, {
			Name:     `group`,
			Type:     dal.BooleanType,
			Required: true,
		}, {
			Name:      `children`,
			Type:      dal.IntType,
			Validator: dal.ValidatePositiveOrZeroInteger,
		}, {
			Name: `descendants`,
			Type: dal.IntType,
		}, {
			Name:     `last_modified_at`,
			Type:     dal.IntType,
			Required: true,
		}, {
			Name: `last_deep_scanned_at`,
			Type: dal.IntType,
		}, {
			Name:         `created_at`,
			Type:         dal.IntType,
			Required:     true,
			DefaultValue: time.Now,
		}, {
			Name: `metadata`,
			Type: dal.ObjectType,
		},
	},
}
View Source
var PopulateGroup = func(group *Group) error {
	if group.ID == `` && group.Path != `` {
		group.ID = path.Base(group.Path)
	}

	if group.RootPath == `` {
		group.RootPath = group.Path
	}

	group.RootPath = strings.TrimSuffix(group.RootPath, `/`)

	if group.Parent == `` {
		group.Parent = RootGroupName
	}

	return nil
}
View Source
var RootGroupName = `root`
View Source
var SearchIndexFlushEveryNRecords = 1000
View Source
var SkipEntry = errors.New("skip entry")

Functions

func CalculateAncestorsFromName

func CalculateAncestorsFromName(root string, name string) []string

func FileIdFromName

func FileIdFromName(rootGroup string, name string) string

func NormalizeFileName

func NormalizeFileName(root string, name string) string

func ParseFilter

func ParseFilter(spec interface{}, fmtvalues ...interface{}) (*filter.Filter, error)

Types

type DB

type DB struct {
	BaseDirectory      string                 `json:"base_dir"`
	AutomigrateModels  bool                   `json:"automigrate"`
	URI                string                 `json:"uri,omitempty"`
	Indexer            string                 `json:"indexer,omitempty"`
	MetadataURI        string                 `json:"metadata_uri,omitempty"`
	MetadataIndexer    string                 `json:"metadata_indexer,omitempty"`
	AdditionalIndexers []string               `json:"additional_indexers,omitempty"`
	GlobalExclusions   []string               `json:"global_exclusions,omitempty"`
	ScanInProgress     bool                   `json:"scan_in_progress"`
	ExtractFields      []string               `json:"extract_fields,omitempty"`
	SkipMigrate        bool                   `json:"skip_migrate"`
	SkipChecksum       bool                   `json:"skip_checksum"`
	StatsDatabase      string                 `json:"stats_database"`
	StatsTags          map[string]interface{} `json:"stats_tags"`
	GroupLister        GroupListFunc          `json:"-"`
	ScanInterval       string                 `json:"scan_interval"`
	PreInitialize      PreInitializeFunc      `json:"-"`
	PostInitialize     PostInitializeFunc     `json:"-"`
	// contains filtered or unexported fields
}
var Instance *DB

func NewDB

func NewDB() *DB

func (*DB) AddGlobalExclusions

func (self *DB) AddGlobalExclusions(patterns ...string)

func (*DB) Cleanup

func (self *DB) Cleanup(skipFileStats bool, skipRootGroupPrune bool) error

func (*DB) GetDirectoriesByFile

func (self *DB) GetDirectoriesByFile(filename string) []Group

func (*DB) GetPivotDatabase

func (self *DB) GetPivotDatabase() backends.Backend

func (*DB) GetPivotMetadataDatabase

func (self *DB) GetPivotMetadataDatabase() backends.Backend

func (*DB) Initialize

func (self *DB) Initialize() error

Initialize the DB by opening the underlying database

func (*DB) Model

func (self *DB) Model(name string) (mapper.Mapper, bool)

func (*DB) PollDirectories

func (self *DB) PollDirectories()

func (*DB) RegisterModel

func (self *DB) RegisterModel(schema *dal.Collection, _db ...backends.Backend) error

func (*DB) RegisterPostScanEvent

func (self *DB) RegisterPostScanEvent(fn PostScanFunc)

func (*DB) Scan

func (self *DB) Scan(deep bool, labels ...string) error

func (*DB) UnregisterModel

func (self *DB) UnregisterModel(name string)

type Entry

type Entry struct {
	ID                string                 `json:"id"`
	RelativePath      string                 `json:"name"`
	Type              string                 `json:"type"`
	Parent            string                 `json:"parent,omitempty"`
	Checksum          string                 `json:"checksum,omitempty"`
	Size              int64                  `json:"size,omitempty"`
	RootGroup         string                 `json:"root_group"`
	IsGroup           bool                   `json:"group"`
	ChildCount        int                    `json:"children"`
	DescendantCount   int                    `json:"descendants"`
	LastModifiedAt    int64                  `json:"last_modified_at,omitempty"`
	LastDeepScannedAt int64                  `json:"last_deep_scanned_at,omitempty"`
	CreatedAt         int64                  `json:"created_at,omitempty"`
	Metadata          map[string]interface{} `json:"metadata"`
	InitialPath       string                 `json:"-"`
	// contains filtered or unexported fields
}

func NewEntry

func NewEntry(rootGroup string, root string, name string) *Entry

func (*Entry) Children

func (self *Entry) Children(filterString ...string) ([]*Entry, error)

func (*Entry) GenerateChecksum

func (self *Entry) GenerateChecksum(forceRecalculate bool) (string, error)

func (*Entry) Get

func (self *Entry) Get(key string, fallback ...interface{}) interface{}

func (*Entry) GetAbsolutePath

func (self *Entry) GetAbsolutePath() (string, error)

func (*Entry) GetHumanSize

func (self *Entry) GetHumanSize(format string) string

func (*Entry) GetManifest

func (self *Entry) GetManifest(fields []string, filterString string) (*Manifest, error)

func (*Entry) Info

func (self *Entry) Info() os.FileInfo

func (*Entry) LastModifiedTime

func (self *Entry) LastModifiedTime() time.Time

func (*Entry) LoadAllMetadata

func (self *Entry) LoadAllMetadata() error

func (*Entry) LoadMetadata

func (self *Entry) LoadMetadata(pass int) error

func (*Entry) String

func (self *Entry) String() string

func (*Entry) Walk

func (self *Entry) Walk(walkFn WalkFunc, filterStrings ...string) error

type Group

type Group struct {
	ID                   string                 `json:"id"`
	Path                 string                 `json:"path"`
	Parent               string                 `json:"parent"`
	RootPath             string                 `json:"-"`
	FilePattern          string                 `json:"file_pattern,omitempty"`
	NoRecurseDirectories bool                   `json:"no_recurse"`
	FollowSymlinks       bool                   `json:"follow_symlinks"`
	FileMinimumSize      int                    `json:"min_file_size,omitempty"`
	DeepScan             bool                   `json:"deep_scan"`
	SkipChecksum         bool                   `json:"skip_checksum"`
	CurrentPass          int                    `json:"-"`
	PassesDone           int                    `json:"-"`
	TargetSubgroups      []string               `json:"-"`
	FileCount            int                    `json:"file_count"`
	ModifiedFileCount    int                    `json:"modified_file_count"`
	Properties           map[string]interface{} `json:"properties,omitempty"`
	// contains filtered or unexported fields
}

func (*Group) ContainsPath

func (self *Group) ContainsPath(absPath string) bool

func (*Group) GetAncestors

func (self *Group) GetAncestors() []string

func (*Group) GetLatestModifyTime

func (self *Group) GetLatestModifyTime() (time.Time, error)

func (*Group) GetParentFromPath

func (self *Group) GetParentFromPath(relPath string) (string, error)

func (*Group) Initialize

func (self *Group) Initialize() error

func (*Group) RefreshStats

func (self *Group) RefreshStats() error

func (*Group) Scan

func (self *Group) Scan(subgroups []string) error

func (*Group) ScanPath

func (self *Group) ScanPath(absPath string) error

func (*Group) WalkModifiedSince

func (self *Group) WalkModifiedSince(lastModifiedAt time.Time, entryFn WalkEntryFunc) error

type GroupListFunc

type GroupListFunc func() (GroupSet, error)

type GroupSet

type GroupSet []Group

func (GroupSet) Len

func (self GroupSet) Len() int

func (GroupSet) Less

func (self GroupSet) Less(i, j int) bool

func (GroupSet) Swap

func (self GroupSet) Swap(i, j int)

type Manifest

type Manifest struct {
	BaseDirectory string
	Items         []ManifestItem
	Fields        []string
}

func NewManifest

func NewManifest(baseDirectory string, fields ...string) *Manifest

func (*Manifest) Add

func (self *Manifest) Add(items ...ManifestItem)

func (*Manifest) GetUpdateManifest

func (self *Manifest) GetUpdateManifest(policy SyncPolicy) (*Manifest, error)

func (*Manifest) LoadTSV

func (self *Manifest) LoadTSV(r io.Reader) error

type ManifestItem

type ManifestItem struct {
	ID           string
	Type         ManifestItemType
	Label        string
	RelativePath string
	Values       []ManifestValue
}

func (*ManifestItem) NeedsUpdate

func (self *ManifestItem) NeedsUpdate(manifest *Manifest, policy *SyncPolicy) (bool, error)

type ManifestItemType

type ManifestItemType string
const (
	FileItem      ManifestItemType = `file`
	DirectoryItem                  = `directory`
)

type ManifestValue

type ManifestValue interface{}

type PopulateGroupFunc

type PopulateGroupFunc func(group *Group) error // {}

type PostInitializeFunc

type PostInitializeFunc func(db *DB, backend backends.Backend) error

type PostScanFunc

type PostScanFunc func()

type PreInitializeFunc

type PreInitializeFunc func(db *DB) error

type SyncPolicy

type SyncPolicy struct {
	ID     string   `json:"id"`
	Fields []string `json:"fields"`
}

func (*SyncPolicy) Compare

func (self *SyncPolicy) Compare(field string, value interface{}, other interface{}) bool

type WalkEntryFunc

type WalkEntryFunc func(entry *Entry, isNew bool) error // {}

type WalkFunc

type WalkFunc func(path string, file *Entry, err error) error // {}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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