Exemplo n.º 1
0
func TestDir(t *testing.T) {
	home := os.Getenv("HOME")
	for in, out := range map[string]string{
		"":     home + "/.config/cairo-dock/third-party",
		"/tmp": "/tmp/third-party",
	} {
		str, e := packages.DirAppletsExternal(in)
		assert.NoError(t, e, "DirAppletsExternal")
		assert.Equal(t, out, str, "DirAppletsExternal")
	}

	for in, out := range map[string]string{
		"":     home + "/.config/cairo-dock/extras/gauges",
		"/tmp": "/tmp/extras/gauges",
	} {
		str, e := packages.DirThemeExtra(in, "gauges")
		assert.NoError(t, e, "DirTheme")
		assert.Equal(t, out, str, "DirTheme")
	}

	gauges, e := packages.ListThemesDir(logger, "/usr/share/cairo-dock/gauges", packages.TypeLocal)
	assert.NoError(t, e, "ListThemesDir")
	assert.True(t, len(gauges) > 3, "ListThemesDir count")
	gauge := gauges[0]
	assert.Equal(t, "Battery[0]", gauge.GetName(), "gauge.GetName()")
	assert.Equal(t, "Battery", gauge.GetTitle(), "gauge.GetTitle()")
	assert.Equal(t, "Adrien Pilleboue", gauge.GetAuthor(), "gauge.GetAuthor()")
	assert.Equal(t, "2", gauge.GetModuleVersion(), "gauge.GetModuleVersion()")
	assert.Equal(t, packages.TypeLocal, gauge.Type, "gauge.Type")
	// assert.Equal(t, "", gauge.GetGettextDomain(), "gauge.GetGettextDomain()")
	assert.Equal(t, "Made by Necropotame for Cairo-Dock.\n", gauge.GetDescription(), "gauge.GetDescription()")
	assert.Equal(t, "/usr/share/cairo-dock/gauges/Battery/preview", gauge.GetPreviewFilePath(), "gauge.GetPreviewFilePath()")
}
Exemplo 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
}
Exemplo n.º 3
0
func main() {
	logger := log.NewLog(log.Logs)

	externalUserDir, e := packages.DirAppletsExternal("") // option config dir
	log.Fatal(e, "DirAppletsExternal")

	packs, e := editpack.PacksExternal(logger, externalUserDir)
	log.Fatal(e, "get external packages")

	editpack.Start(logger, packs)
}
Exemplo n.º 4
0
func runAppInfo(cmd *Command, args []string) {
	setPathAbsolute(appinfoConfPath) // Ensure we have an absolute path for the config dir.

	externalUserDir, e := packages.DirAppletsExternal("") // option config dir
	exitIfFail(e, "start termui")

	packs, e := editpack.PacksExternal(logger, externalUserDir)
	exitIfFail(e, "get external packages")
	editpack.Start(logger, packs)
	return
}
Exemplo n.º 5
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")
	}
}