Ejemplo n.º 1
0
func TestListFromDir(t *testing.T) {
	packs, e := packages.ListFromDir(logger, appDir, packages.TypeGoInternal, packages.SourceApplet)
	if !assert.NoError(t, e, "ListFromDir") || !assert.NotEmpty(t, packs, "ListFromDir") {
		return
	}
	assert.NotEmpty(t, packs[0].DisplayedName, "DisplayedName")
}
Ejemplo n.º 2
0
func listPackages() (list packages.AppletPackages, e error) {

	// List server only.
	if *listServer {
		return packages.ListDistant(logger, cdglobal.AppletsDirName+"/"+cdglobal.AppletsServerTag)
	}

	// Get applets dir.
	externalUserDir, e := packages.DirAppletsExternal(*listUserDir)
	if e != nil {
		return nil, e
	}

	// List local only.
	if *listLocal {
		return packages.ListFromDir(logger, externalUserDir, packages.TypeUser, packages.SourceApplet)
	}

	// List default (merged both).
	packs, e := packages.ListDownloadApplets(logger, externalUserDir)
	if e != nil {
		return nil, e
	}
	return packages.ListDownloadSort(packs), nil
}
Ejemplo n.º 3
0
// ListThemeINI builds a list of icon theme in system and user dir.
//
func (sc SourceCommon) ListThemeINI(localSystem, localUser, distant string) map[string]Handbooker {
	// Themes installed in system dir.
	list, _ := packages.ListFromDir(sc.Log, localSystem, packages.TypeLocal, packages.SourceTheme)

	// Themes installed in user dir.
	userDir, e := packages.DirThemeExtra(sc.ConfDir, localUser)
	if e == nil {
		dist, _ := packages.ListFromDir(sc.Log, userDir, packages.TypeUser, packages.SourceTheme)
		list = append(list, dist...)
	}
	sc.Log.Debug("ListThemeINI found total ", len(list), userDir)

	out := make(map[string]Handbooker)
	for _, v := range list {
		out[v.GetName()] = v
	}

	return out
}
Ejemplo n.º 4
0
// PacksExternal lists applets packages in the given dir.
//
func PacksExternal(log cdtype.Logger, dir string) (packages.AppletPackages, error) {
	packs, e := packages.ListFromDir(log, dir, packages.TypeUser, packages.SourceApplet)
	if e != nil {
		return nil, e
	}
	if len(packs) == 0 {
		return nil, errors.New("no packages found in " + dir)
	}
	return packs, nil
}
Ejemplo n.º 5
0
func (o *AppManager) registerApplets() {
	dir := globals.DirShareData(cdglobal.ConfigDirAppletsGo)
	packs, e := packages.ListFromDir(o.log, dir, packages.TypeGoInternal, packages.SourceApplet)
	if o.log.Err(e, "registerapplets") {
		return
	}
	for _, pack := range packs {
		if cdtype.Applets.GetNewFunc(pack.DisplayedName) != nil {
			o.registerOneApplet(pack)
		}
	}
}
Ejemplo n.º 6
0
// ListDockThemeSave builds the list of dock themes for save widget (local).
//
func (d Data) ListDockThemeSave() []datatype.Field {
	dir := globals.DirDockData(cdglobal.ConfigDirDockThemes)
	packs, e := packages.ListFromDir(d.Log, dir, packages.TypeUser, packages.SourceDockTheme)
	if e != nil {
		println("ListDockThemeSave wrong dir:", dir) // TODO: use a logger.
		return nil
	}

	var list []datatype.Field
	for _, pack := range packs {
		list = append(list, datatype.Field{
			Key:  pack.DisplayedName,
			Name: pack.GetName(),
		})
	}
	return list
}
Ejemplo n.º 7
0
func installOrRemoveApplets(list []string, remove bool) {

	// TODO: use active dock if available.

	externalUserDir, e := packages.DirAppletsExternal(*listUserDir)
	exitIfFail(e, "get config dir") // Ensure we have the config dir.

	var packs packages.AppletPackages
	var action func(appname string, pack *packages.AppletPackage) bool

	if remove {
		action = func(appname string, pack *packages.AppletPackage) bool {
			e := pack.Uninstall(externalUserDir)
			return testErr(e, "uninstall", "Applet removed", appname)
		}
		packs, e = packages.ListFromDir(logger, externalUserDir, packages.TypeUser, packages.SourceApplet)

	} else { // install.
		options := ""
		if *listVerbose {
			options = "v" // Tar command verbose option.
		}
		action = func(appname string, pack *packages.AppletPackage) bool {
			pack.SrvTag = cdglobal.AppletsDirName + "/" + cdglobal.AppletsServerTag
			e := pack.Install(externalUserDir, options)
			return testErr(e, "install", "Applet installed", appname)
		}
		packs, e = packages.ListDistant(logger, cdglobal.AppletsDirName+"/"+cdglobal.AppletsServerTag)
	}
	exitIfFail(e, "get applets list") // Ensure we have the server list.

	failed := false
	for _, appname := range list {
		pack := packs.Get(strings.Title(appname)) // Applets are using a CamelCase format. This will help lazy users
		if pack != nil {
			failed = failed || !action(appname, pack)
		}
	}
	if failed || len(list) == 0 {
		println("use list command to get the list of valid applets names")
	}
}