endive

package
v0.0.0-...-725ffc3 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2016 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package endive is the root package of endive.

It defines the main interfaces. It manages the configuration file and also deals with the internal database of already imported files (tracked through their SHA256 hashes). It also contains functions that are used by other endive subpackages.

Index

Constants

View Source
const (
	// Endive is the name of this program.
	Endive = "endive"

	// XdgLogPath is the path for the main log file.
	XdgLogPath = Endive + "/" + Endive + ".log"
	// XdgLockPath is the path for the db lock.
	XdgLockPath = Endive + "/" + Endive + ".lock"
	// XdgArchiveDir is the path where database archives are kept
	XdgArchiveDir = Endive + "/archives/"
)
View Source
const (
	// EpubExtension is the lowercase extension for all epubs.
	EpubExtension = ".epub"
	// True as string
	True = "true"
	// False as string
	False = "false"
	// EmptyIndexError for Indexer
	EmptyIndexError = "Index is empty"
)

Variables

This section is empty.

Functions

func AskForISBN

func AskForISBN(ui i.UserInterface) (string, error)

AskForISBN when not found in epub

func CleanISBN

func CleanISBN(full string) (isbn13 string, err error)

CleanISBN from a string

func GetArchiveUniqueName

func GetArchiveUniqueName(filename string) (archive string, err error)

GetArchiveUniqueName in the endive archive directory.

func GetConfigPath

func GetConfigPath() (configFile string, err error)

GetConfigPath gets the default path for configuration.

func GetIndexPath

func GetIndexPath() (path string)

GetIndexPath gets the default index path

func GetKnownHashesPath

func GetKnownHashesPath() (hashesFile string, err error)

GetKnownHashesPath gets the default path for known hashes.

func RemoveLock

func RemoveLock() (err error)

RemoveLock for current library.

func SetLock

func SetLock() (err error)

SetLock sets the library lock.

func TabulateMap

func TabulateMap(input map[string]int, firstHeader string, secondHeader string) (table string)

TabulateMap of map[string]int.

func TabulateRows

func TabulateRows(rows [][]string, headers ...string) (table string)

TabulateRows of map[string]int.

Types

type Collection

type Collection interface {
	// contents
	Books() []GenericBook
	Add(...GenericBook)
	Propagate(i.UserInterface, Config)
	RemoveByID(int) error
	Diff(Collection, Collection, Collection, Collection)
	// 	Check() error
	// search
	FindByID(int) (GenericBook, error)
	FindByHash(string) (GenericBook, error)
	FindByMetadata(string, string, string) (GenericBook, error)
	FindByFullPath(string) (GenericBook, error)
	// extracting information
	Retail() Collection
	NonRetailOnly() Collection
	Exported() Collection
	Progress(string) Collection
	Incomplete() Collection
	WithID(...int) Collection
	Authors() map[string]int
	Publishers() map[string]int
	Tags() map[string]int
	Series() map[string]int
	// output
	Table() string
	Sort(string)
	First(int) Collection
	Last(int) Collection
}

Collection interface for slices of Books

type Config

type Config struct {
	Filename           string
	DatabaseFile       string
	LibraryRoot        string
	RetailSource       []string
	NonRetailSource    []string
	EpubFilenameFormat string
	AuthorAliases      map[string][]string
	TagAliases         map[string][]string
	PublisherAliases   map[string][]string
	EReaderMountPoint  string
	GoodReadsAPIKey    string
}

Config holds all relevant information

func (*Config) Check

func (c *Config) Check() error

Check if the paths in the configuration file are valid, and if the EpubFilename Format is ok.

func (*Config) ListAuthorAliases

func (c *Config) ListAuthorAliases() (allAliases string)

ListAuthorAliases from the configuration file.

func (*Config) Load

func (c *Config) Load() (err error)

Load configuration file using viper.

func (*Config) String

func (c *Config) String() string

String displays all configuration information.

type Database

type Database interface {
	SetPath(string)
	Path() string
	Equals(Database) bool
	Load(Collection) error
	Save(Collection) (bool, error)
	Backup(string) error
}

Database is the interface for loading/saving Book information

type EpubCandidate

type EpubCandidate struct {
	Filename           string
	Hash               string
	Imported           bool
	ImportedButMissing bool
}

EpubCandidate for import/export/refresh

func NewCandidate

func NewCandidate(filename string, knownHashes KnownHashes, collection Collection) *EpubCandidate

NewCandidate returns a filled epubCandidate struct

func ScanForEpubs

func ScanForEpubs(root string, knownHashes KnownHashes, collection Collection) ([]EpubCandidate, error)

ScanForEpubs recursively in folder.

func (EpubCandidate) String

func (c EpubCandidate) String() string

String representation for EpubCandidate

type EpubCandidates

type EpubCandidates []EpubCandidate

EpubCandidates is a slice of EpubCandidates.

func (EpubCandidates) Importable

func (c EpubCandidates) Importable() EpubCandidates

Importable EpubCandidate-s in EpubCandidates

func (EpubCandidates) Missing

func (c EpubCandidates) Missing() EpubCandidates

Missing EpubCandidate-s in EpubCandidates

func (EpubCandidates) New

New EpubCandidate-s in EpubCandidates

type Error

type Error int

Error handles errors found in configuration

const (
	ErrorConfigFileCreated Error = iota
	ErrorCannotLockDB
	ErrorLibraryRootDoesNotExist
	ErrorLibraryRootUnknown
	ErrorBadFormat
	WarningGoodReadsAPIKeyMissing
	WarningRetailSourceDoesNotExist
	WarningNonRetailSourceDoesNotExist
)

Constant Error values which can be compared to determine the type of error

func (Error) Error

func (e Error) Error() string

Error implements the error interface

type GenericBook

type GenericBook interface {
	ID() int
	HasHash(string) bool
	HasEpub() bool
	FullPath() string
	String() string
	CleanFilename() string
	Refresh() ([]bool, []string, error)
	AddEpub(string, bool, string) (bool, error)
	Check() (bool, bool, error)
	SetExported(bool)
}

GenericBook interface for Books

type Indexer

type Indexer interface {
	SetPath(path string)
	Rebuild(Collection) error
	Update(Collection, Collection, Collection) error
	Check(Collection) error
	Query(query string) ([]string, error)
	Count() uint64
}

Indexer provides an interface for indexing books.

type KnownHashes

type KnownHashes struct {
	Filename string   `json:"-"`
	Hashes   []string `json:"hashes"`
	Count    int      `json:"-"`
}

KnownHashes keeps track of the hashes of already imported epubs.

func (*KnownHashes) Add

func (k *KnownHashes) Add(hash string) (added bool, err error)

Add a hash to the database.

func (*KnownHashes) IsIn

func (k *KnownHashes) IsIn(hash string) (isIn bool)

IsIn checks whether a hash is known.

func (*KnownHashes) Load

func (k *KnownHashes) Load() (err error)

Load the known hashes.

func (*KnownHashes) Save

func (k *KnownHashes) Save() (modified bool, err error)

Save the known hashes database.

Jump to

Keyboard shortcuts

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