installer

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const KeilDefaultPackRoot = "https://www.keil.com/pack/"

Variables

This section is empty.

Functions

func AddPack

func AddPack(packPath string, checkEula, extractEula, forceReinstall, noRequirements bool, timeout int) error

AddPack adds a pack to the pack installation directory structure

func AddPdsc

func AddPdsc(pdscPath string) error

AddPdsc adds a pack via PDSC file

func CheckConcurrency added in v1.0.1

func CheckConcurrency(concurrency int) int

func DownloadPDSCFiles added in v1.0.0

func DownloadPDSCFiles(skipInstalledPdscFiles bool, concurrency int, timeout int) error

func FindPackURL added in v0.3.0

func FindPackURL(pack *PackType) (string, error)

FindPackURL uses pack.path as packID and try to find the pack URL Finding step are as follows: 1. Find pack.Vendor, pack.Name, pack.Version in Installation.PublicIndex 1.1. if pack.IsPublic == true 1.1.1. read .Web/PDSC file into pdscXML 1.1.2. releastTag = pdscXML.FindReleaseTagByVersion(pack.Version) 1.1.3. if releaseTag.URL != "", return releaseTag.URL 1.1.4. return pdscTag.URL + pack.Vendor + "." + pack.Name + "." + pack.Version + ".pack" 1.2. if pack.IsPublic == false 1.2.1. if pack's pdsc file not found in Installation.LocalDir then raise errs.ErrPackURLCannotBeFound 1.2.2. read .Local/PDSC file into pdscXML 1.2.3. releastTag = pdscXML.FindReleaseTagByVersion(pack.Version) 1.2.3. if releaseTag == nil then raise ErrPackVersionNotFoundInPdsc 1.2.4. if releaseTag.URL != "", return releaseTag.URL 1.2.5. return pdscTag.URL + pack.Vendor + "." + pack.Name + "." + pack.Version + ".pack"

func GetDefaultCmsisPackRoot added in v0.8.3

func GetDefaultCmsisPackRoot() string

GetDefaultCmsisPackRoot provides a default location for the pack root if not provided. This is to enable a "default mode", where the public index will be automatically initiated if not ready yet.

func GetIndexPath added in v1.1.0

func GetIndexPath(indexPath string) (string, error)

func ListInstalledPacks added in v0.3.0

func ListInstalledPacks(listCached, listPublic, listRequirements bool, listFilter string) error

ListInstalledPacks generates a list of all packs present in the pack root folder

Example

Listing on empty

localTestingDir := "test-list-empty-pack-root"
_ = installer.SetPackRoot(localTestingDir, CreatePackRoot)
defer removePackRoot(localTestingDir)

log.SetOutput(os.Stdout)
defer log.SetOutput(io.Discard)

_ = installer.ListInstalledPacks(!ListCached, !ListPublic, !ListRequirements, ListFilter)
Output:

I: Listing installed packs
I: (no packs installed)
Example (EmptyCache)
localTestingDir := "test-list-empty-cache"
_ = installer.SetPackRoot(localTestingDir, CreatePackRoot)
defer removePackRoot(localTestingDir)

log.SetOutput(os.Stdout)
defer log.SetOutput(io.Discard)

_ = installer.ListInstalledPacks(ListCached, !ListPublic, !ListRequirements, ListFilter)
Output:

I: Listing cached packs
I: (no packs cached)
Example (EmptyPublicIndex)
localTestingDir := "test-list-empty-index"
_ = installer.SetPackRoot(localTestingDir, CreatePackRoot)
defer removePackRoot(localTestingDir)

log.SetOutput(os.Stdout)
defer log.SetOutput(io.Discard)

_ = installer.ListInstalledPacks(ListCached, ListPublic, !ListRequirements, ListFilter)
Output:

I: Listing packs from the public index
I: (no packs in public index)
Example (Filter)
localTestingDir := "test-list-packs-filter"
_ = installer.SetPackRoot(localTestingDir, CreatePackRoot)
installer.UnlockPackRoot()
defer removePackRoot(localTestingDir)

pdscFilePath := strings.Replace(publicLocalPack123, ".1.2.3.pack", ".pdsc", -1)
_ = utils.CopyFile(pdscFilePath, filepath.Join(installer.Installation.WebDir, "TheVendor.PublicLocalPack.pdsc"))
_ = installer.Installation.PublicIndexXML.AddPdsc(xml.PdscTag{
	Vendor:  "TheVendor",
	Name:    "PublicLocalPack",
	Version: "1.2.3",
})
_ = installer.Installation.PublicIndexXML.AddPdsc(xml.PdscTag{
	Vendor:  "TheVendor",
	Name:    "PublicLocalPack",
	Version: "1.2.4",
})
_ = installer.Installation.PublicIndexXML.AddPdsc(xml.PdscTag{
	Vendor:  "TheVendor",
	Name:    "PublicLocalPack",
	Version: "1.2.5",
})
_ = installer.AddPack(publicLocalPack123, !CheckEula, !ExtractEula, !ForceReinstall, !NoRequirements, Timeout)
_ = installer.AddPack(publicLocalPack124, !CheckEula, !ExtractEula, !ForceReinstall, !NoRequirements, Timeout)
_ = installer.RemovePack("TheVendor.PublicLocalPack.1.2.3", false /*no purge*/, Timeout)

log.SetOutput(os.Stdout)
defer log.SetOutput(io.Discard)
_ = installer.ListInstalledPacks(ListCached, ListPublic, !ListRequirements, "1.2.4")
Output:

I: Listing packs from the public index, filtering by "1.2.4"
I: TheVendor::PublicLocalPack@1.2.4 (installed)
Example (FilterErrorPackages)
localTestingDir := "test-list-filter-error-message"
_ = installer.SetPackRoot(localTestingDir, CreatePackRoot)
installer.UnlockPackRoot()
defer removePackRoot(localTestingDir)

pdscFilePath := strings.Replace(publicLocalPack123, ".1.2.3.pack", ".pdsc", -1)
_ = utils.CopyFile(pdscFilePath, filepath.Join(installer.Installation.WebDir, "TheVendor.PublicLocalPack.pdsc"))
_ = installer.Installation.PublicIndexXML.AddPdsc(xml.PdscTag{
	Vendor:  "TheVendor",
	Name:    "PublicLocalPack",
	Version: "1.2.3",
})
_ = installer.AddPack(publicLocalPack123, !CheckEula, !ExtractEula, !ForceReinstall, !NoRequirements, Timeout)

// Temper with the installation folder
currVendorFolder := filepath.Join(localTestingDir, "TheVendor")
currPackNameFolder := filepath.Join(localTestingDir, "TheVendor", "PublicLocalPack")
currVersionFolder := filepath.Join(localTestingDir, "TheVendor", "PublicLocalPack", "1.2.3")

temperedVendorFolder := filepath.Join(localTestingDir, "_TheVendor")
temperedPackNameFolder := filepath.Join(localTestingDir, "TheVendor", "_PublicLocalPack")
temperedVersionFolder := filepath.Join(localTestingDir, "TheVendor", "PublicLocalPack", "1.2.3.4")

// Order matters
_ = utils.MoveFile(currVersionFolder, temperedVersionFolder)
_ = utils.MoveFile(currPackNameFolder, temperedPackNameFolder)
_ = utils.MoveFile(currVendorFolder, temperedVendorFolder)

log.SetOutput(os.Stdout)
defer log.SetOutput(io.Discard)
_ = installer.ListInstalledPacks(!ListCached, !ListPublic, !ListRequirements, "TheVendor")
Output:

I: Listing installed packs, filtering by "TheVendor"
E: _TheVendor::_PublicLocalPack@1.2.3.4 - error: pack version incorrect format
Example (FilterInvalidChars)
localTestingDir := "test-list-filter-invalid-chars"
_ = installer.SetPackRoot(localTestingDir, CreatePackRoot)
installer.UnlockPackRoot()
defer removePackRoot(localTestingDir)

pdscFilePath := strings.Replace(publicLocalPack123, ".1.2.3.pack", ".pdsc", -1)
_ = utils.CopyFile(pdscFilePath, filepath.Join(installer.Installation.WebDir, "TheVendor.PublicLocalPack.pdsc"))
_ = installer.Installation.PublicIndexXML.AddPdsc(xml.PdscTag{
	Vendor:  "TheVendor",
	Name:    "PublicLocalPack",
	Version: "1.2.3",
})
_ = installer.Installation.PublicIndexXML.AddPdsc(xml.PdscTag{
	Vendor:  "TheVendor",
	Name:    "PublicLocalPack",
	Version: "1.2.4",
})
_ = installer.Installation.PublicIndexXML.AddPdsc(xml.PdscTag{
	Vendor:  "TheVendor",
	Name:    "PublicLocalPack",
	Version: "1.2.5",
})
_ = installer.AddPack(publicLocalPack123, !CheckEula, !ExtractEula, !ForceReinstall, !NoRequirements, Timeout)
_ = installer.AddPack(publicLocalPack124, !CheckEula, !ExtractEula, !ForceReinstall, !NoRequirements, Timeout)
_ = installer.RemovePack("TheVendor.PublicLocalPack.1.2.3", false /*no purge*/, Timeout)

log.SetOutput(os.Stdout)
defer log.SetOutput(io.Discard)
_ = installer.ListInstalledPacks(ListCached, ListPublic, !ListRequirements, "@ :")
Output:

I: Listing packs from the public index, filtering by "@ :"
Example (FilteradditionalMessages)
localTestingDir := "test-list-filter-additional-messages"
_ = installer.SetPackRoot(localTestingDir, CreatePackRoot)
installer.UnlockPackRoot()
defer removePackRoot(localTestingDir)

pdscFilePath := strings.Replace(publicLocalPack123, ".1.2.3.pack", ".pdsc", -1)
_ = utils.CopyFile(pdscFilePath, filepath.Join(installer.Installation.WebDir, "TheVendor.PublicLocalPack.pdsc"))
_ = installer.Installation.PublicIndexXML.AddPdsc(xml.PdscTag{
	Vendor:  "TheVendor",
	Name:    "PublicLocalPack",
	Version: "1.2.3",
})
_ = installer.Installation.PublicIndexXML.AddPdsc(xml.PdscTag{
	Vendor:  "TheVendor",
	Name:    "PublicLocalPack",
	Version: "1.2.4",
})
_ = installer.Installation.PublicIndexXML.AddPdsc(xml.PdscTag{
	Vendor:  "TheVendor",
	Name:    "PublicLocalPack",
	Version: "1.2.5",
})
_ = installer.AddPack(publicLocalPack123, !CheckEula, !ExtractEula, !ForceReinstall, !NoRequirements, Timeout)
_ = installer.AddPack(publicLocalPack124, !CheckEula, !ExtractEula, !ForceReinstall, !NoRequirements, Timeout)
_ = installer.RemovePack("TheVendor.PublicLocalPack.1.2.3", false /*no purge*/, Timeout)

log.SetOutput(os.Stdout)
defer log.SetOutput(io.Discard)
_ = installer.ListInstalledPacks(ListCached, !ListPublic, !ListRequirements, "(installed)")
Output:

I: Listing cached packs, filtering by "(installed)"
Example (List)

Now list 3 packs from the public index, where * 1 is cached only * 1 is installed * 1 is neither installer or cached, it's just available in the public index

localTestingDir := "test-list-packs"
_ = installer.SetPackRoot(localTestingDir, CreatePackRoot)
installer.UnlockPackRoot()
defer removePackRoot(localTestingDir)

pdscFilePath := strings.Replace(publicLocalPack123, ".1.2.3.pack", ".pdsc", -1)
_ = utils.CopyFile(pdscFilePath, filepath.Join(installer.Installation.WebDir, "TheVendor.PublicLocalPack.pdsc"))
_ = installer.Installation.PublicIndexXML.AddPdsc(xml.PdscTag{
	Vendor:  "TheVendor",
	Name:    "PublicLocalPack",
	Version: "1.2.3",
})
_ = installer.Installation.PublicIndexXML.AddPdsc(xml.PdscTag{
	Vendor:  "TheVendor",
	Name:    "PublicLocalPack",
	Version: "1.2.4",
})
_ = installer.Installation.PublicIndexXML.AddPdsc(xml.PdscTag{
	Vendor:  "TheVendor",
	Name:    "PublicLocalPack",
	Version: "1.2.5",
})
_ = installer.AddPack(publicLocalPack123, !CheckEula, !ExtractEula, !ForceReinstall, !NoRequirements, Timeout)
_ = installer.AddPack(publicLocalPack124, !CheckEula, !ExtractEula, !ForceReinstall, !NoRequirements, Timeout)
_ = installer.RemovePack("TheVendor.PublicLocalPack.1.2.3", false /*no purge*/, Timeout)

log.SetOutput(os.Stdout)
defer log.SetOutput(io.Discard)
_ = installer.ListInstalledPacks(ListCached, ListPublic, !ListRequirements, ListFilter)
Output:

I: Listing packs from the public index
I: TheVendor::PublicLocalPack@1.2.3 (cached)
I: TheVendor::PublicLocalPack@1.2.4 (installed)
I: TheVendor::PublicLocalPack@1.2.5
Example (ListCached)
localTestingDir := "test-list-cached-packs"
_ = installer.SetPackRoot(localTestingDir, CreatePackRoot)
installer.UnlockPackRoot()
defer removePackRoot(localTestingDir)

pdscFilePath := strings.Replace(publicLocalPack123, ".1.2.3.pack", ".pdsc", -1)
_ = utils.CopyFile(pdscFilePath, filepath.Join(installer.Installation.WebDir, "TheVendor.PublicLocalPack.pdsc"))
_ = installer.Installation.PublicIndexXML.AddPdsc(xml.PdscTag{
	Vendor:  "TheVendor",
	Name:    "PublicLocalPack",
	Version: "1.2.3",
})
_ = installer.Installation.PublicIndexXML.AddPdsc(xml.PdscTag{
	Vendor:  "TheVendor",
	Name:    "PublicLocalPack",
	Version: "1.2.4",
})
_ = installer.Installation.PublicIndexXML.AddPdsc(xml.PdscTag{
	Vendor:  "TheVendor",
	Name:    "PublicLocalPack",
	Version: "1.2.5",
})
_ = installer.AddPack(publicLocalPack123, !CheckEula, !ExtractEula, !ForceReinstall, !NoRequirements, Timeout)
_ = installer.AddPack(publicLocalPack124, !CheckEula, !ExtractEula, !ForceReinstall, !NoRequirements, Timeout)
_ = installer.RemovePack("TheVendor.PublicLocalPack.1.2.3", false /*no purge*/, Timeout)

log.SetOutput(os.Stdout)
defer log.SetOutput(io.Discard)
_ = installer.ListInstalledPacks(ListCached, !ListPublic, !ListRequirements, ListFilter)
Output:

I: Listing cached packs
I: TheVendor::PublicLocalPack@1.2.3
I: TheVendor::PublicLocalPack@1.2.4 (installed)
Example (ListMalformedInstalledPacks)
localTestingDir := "test-list-malformed-installed-packs"
_ = installer.SetPackRoot(localTestingDir, CreatePackRoot)
installer.UnlockPackRoot()
defer removePackRoot(localTestingDir)

pdscFilePath := strings.Replace(publicLocalPack123, ".1.2.3.pack", ".pdsc", -1)
_ = utils.CopyFile(pdscFilePath, filepath.Join(installer.Installation.WebDir, "TheVendor.PublicLocalPack.pdsc"))
_ = installer.Installation.PublicIndexXML.AddPdsc(xml.PdscTag{
	Vendor:  "TheVendor",
	Name:    "PublicLocalPack",
	Version: "1.2.3",
})
_ = installer.AddPack(publicLocalPack123, !CheckEula, !ExtractEula, !ForceReinstall, !NoRequirements, Timeout)

// Temper with the installation folder
currVendorFolder := filepath.Join(localTestingDir, "TheVendor")
currPackNameFolder := filepath.Join(localTestingDir, "TheVendor", "PublicLocalPack")
currVersionFolder := filepath.Join(localTestingDir, "TheVendor", "PublicLocalPack", "1.2.3")

temperedVendorFolder := filepath.Join(localTestingDir, "_TheVendor")
temperedPackNameFolder := filepath.Join(localTestingDir, "TheVendor", "_PublicLocalPack")
temperedVersionFolder := filepath.Join(localTestingDir, "TheVendor", "PublicLocalPack", "1.2.3.4")

// Order matters
_ = utils.MoveFile(currVersionFolder, temperedVersionFolder)
_ = utils.MoveFile(currPackNameFolder, temperedPackNameFolder)
_ = utils.MoveFile(currVendorFolder, temperedVendorFolder)

log.SetOutput(os.Stdout)
defer log.SetOutput(io.Discard)
_ = installer.ListInstalledPacks(!ListCached, !ListPublic, !ListRequirements, ListFilter)
Output:

I: Listing installed packs
E: _TheVendor::_PublicLocalPack@1.2.3.4 - error: pack version incorrect format
W: 1 error(s) detected

func LockPackRoot added in v0.7.0

func LockPackRoot()

LockPackRoot enable the read-only flag for the pack-root directory

func RemovePack

func RemovePack(packPath string, purge bool, timeout int) error

RemovePack removes a pack given a pack path

func RemovePdsc

func RemovePdsc(pdscPath string) error

RemovePdsc removes a pack given a pdsc path

func SetPackRoot

func SetPackRoot(packRoot string, create bool) error

SetPackRoot sets the working directory of the packs installation if create == true, cpackget will try to create needed resources

func UnlockPackRoot added in v0.7.0

func UnlockPackRoot()

UnlockPackRoot disable the read-only flag for the pack-root directory

func UpdateInstalledPDSCFiles added in v1.0.0

func UpdateInstalledPDSCFiles(pidxXML *xml.PidxXML, concurrency int, timeout int) error

func UpdatePublicIndex added in v0.2.0

func UpdatePublicIndex(indexPath string, overwrite bool, sparse bool, downloadPdsc bool, downloadRemainingPdscFiles bool, concurrency int, timeout int) error

UpdatePublicIndex receives a index path and place it under .Web/index.pidx.

Types

type PackType

type PackType struct {
	xml.PdscTag

	//IsLocallySourced tells whether the pack's source is local or an HTTP URL
	IsLocallySourced bool

	// IsPublic tells whether the pack exists in the public index or not
	IsPublic bool

	// Subfolder stores the subfolder this pack is in the compressed file.
	Subfolder string

	// Pdsc holds a pointer to the PDSC file already parsed as XML
	Pdsc *xml.PdscXML

	// Requirements represents a packs' dependencies
	Requirements struct {
		// contains filtered or unexported fields
	}
	// contains filtered or unexported fields
}

PackType is the struct that represents the installation of a single pack

func (*PackType) GetVersion added in v0.4.0

func (p *PackType) GetVersion() string

GetVersion makes sure to get the latest version for the pack after parsing possible version modifiers (@~, >=)

func (*PackType) Lock added in v0.7.0

func (p *PackType) Lock()

Lock sets all files and directories for this pack to Read-Only

func (*PackType) PackFileName added in v0.3.0

func (p *PackType) PackFileName() string

PackFileName returns a string with how the pack file name would be: Vendor.PackName.x.y.z.pack

func (*PackType) PackID added in v0.3.0

func (p *PackType) PackID() string

PackID returns the most generic name of a pack: Vendor.PackName

func (*PackType) PackIDWithVersion added in v0.3.0

func (p *PackType) PackIDWithVersion() string

PackIDWithVersion returns the packID with version: Vendor.PackName.x.y.z

func (*PackType) PdscFileName added in v0.3.0

func (p *PackType) PdscFileName() string

PdscFileName returns a string with how the pack's pdsc file name would be: Vendor.PackName.pdsc

func (*PackType) PdscFileNameWithVersion added in v0.3.0

func (p *PackType) PdscFileNameWithVersion() string

PdscFileNameWithVersion returns a string with how the pack's pdsc file name would be: Vendor.PackName.x.y.z.pdsc

func (*PackType) RequirementsSatisfied added in v0.9.1

func (p *PackType) RequirementsSatisfied() bool

func (*PackType) Unlock added in v0.7.0

func (p *PackType) Unlock()

Unlock sets all files and directories for this pack to Read/Write mode

type PacksInstallationType

type PacksInstallationType struct {
	// PackRoot is the working directory if the packs installation
	PackRoot string

	// DownloadDir stores copies of all packs that were installed via pack files
	// from external servers.
	DownloadDir string

	// LocalDir stores "local_repository.pidx" containing a list of all packs
	// installed via PDSC files.
	LocalDir string

	// WebDir stores "index.pidx" containing a list of PDSC tags with all
	// publicly available packs.
	WebDir string

	// PublicIndex stores the path PackRoot/WebDir/index.pidx
	PublicIndex string

	// PublicIndexXML stores a xml.PidxXML reference for PackRoot/WebDir/index.pidx
	PublicIndexXML *xml.PidxXML

	// LocalPidx is a reference to "local_repository.pidx" that contains a flat
	// list of PDSC tags representing all packs installed via PDSC files.
	LocalPidx *xml.PidxXML

	// PackIdx is the "pack.idx" file used by other tools to be notified that
	// the pack installation had changed.
	PackIdx string
	// contains filtered or unexported fields
}

PacksInstallationType is the scruct tha manages Open-CMSIS-Pack installation/deletion.

var Installation *PacksInstallationType

Installation is a singleton variable that keeps the only reference to PacksInstallationType

func (*PacksInstallationType) PackIsInstalled

func (p *PacksInstallationType) PackIsInstalled(pack *PackType) bool

PackIsInstalled checks whether a given pack is already installed or not

type PdscType

type PdscType struct {
	xml.PdscTag
	// contains filtered or unexported fields
}

PdscType is the struct that represents the installation of a pack via PDSC file

Jump to

Keyboard shortcuts

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