func (de *DebExplorer) fetchPackage(pack string) error {
	//make sure that we always end up in curDir
	defer os.Chdir(de.curDir)	
	
	var err error
	var absPath string

	//check if this a local file
	if filepath.Ext(pack) != ".deb" {
		if err = os.Chdir(de.tmpDir); err != nil {
			return err
		}
		
		cmd := exec.Command("apt-get","download","-q",pack)
		out, err := cmd.Output(); 
		if err != nil {
			return err
		}
		
		reg, err := regex.Compile("Get:[0-9]+ " + pack + " ([\S]+)")
		if err != nil {
			return err
		}

		m, err := reg.FindStringSubmatch(out)
		if err != nil {
			return err
		}
		
		name = pack+ "_" + m[1] + "_" + de.architecture + ".deb"

		absPath = filepath.join(de.tmpDir,name)
	} else {
		if absPath, err = filepath.Abs(pack); err != nil {
			return err
		}
	}

	cmd := exec.Command("dpkg","-x",absPath,de.tmpDir)
	if err = cmd.Run(); err != nil {
		return err
	}

	return nil
}
Beispiel #2
0
func T(name string) *template.Template {
	cachedMutex.Lock()
	defer cachedMutex.unlock()

	//this is a two value assignment test for existence of a key
	//this returns a template and true or false, then, if true return t
	//see http://blog.golang.org/go-maps-in-action  - also has a good note on the use of "_"
	if t, ok := cachedTemplates[name]; ok {
		return t
	}

	t := template.New("_base.html").Funcs(funcs)

	t = template.Must(t.ParseFiles(
		"templates/_base.html",
		filepath.join("templates", name),
	))

}