Exemple #1
0
func (ag *AptGet) setPackages(args haiconf.CommandArgs) error {
	pl, _ := haiconf.CheckStringList("Packages", args)

	if len(pl) > 0 {
		ag.Packages = stringutils.RemoveDuplicates(pl)
		return nil
	}

	pfs, _ := haiconf.CheckAbsolutePath("PackagesFromSource", args)
	if pfs != "" {
		buff, err := ioutil.ReadFile(pfs)
		if err != nil {
			return err
		}

		nlSplit := func(r rune) bool {
			if r == '\n' {
				return true
			}
			return false
		}

		pkgs := strings.FieldsFunc(string(buff), nlSplit)
		ag.Packages = stringutils.RemoveDuplicates(pkgs)

		return nil
	}

	msg := "You must provide a value for either Packages or PackagesFromSource"
	return haiconf.NewArgError(msg, args)
}
Exemple #2
0
func (ag *AptGet) Run() error {
	// Check if we could use APT's native API instead of calling an external command
	// It seems we can use C++ with CGO by using Swig.
	//
	// Using the API directly would be much more efficient and less risky that
	// calling a system command which is kind of ugly.
	//
	// Interesting links:
	// http://golang.org/doc/faq#Do_Go_programs_link_with_Cpp_programs
	// http://www.swig.org/Doc2.0/Go.html

	// XXX : crap
	args := append(defaultOptions, ag.Method)
	args = stringutils.RemoveDuplicates(append(args, ag.ExtraOptions...))
	args = stringutils.RemoveDuplicates(append(args, ag.Packages...))

	sc := osutils.SystemCommand{
		Path:                 APT_GET,
		Args:                 args,
		EnvVars:              envVariables,
		ExecDir:              os.TempDir(),
		EnableShellExpansion: true,
	}

	output := sc.Run()
	if output.HasError() {
		return output
	}

	return nil
}
Exemple #3
0
func (ag *AptGet) setExtraOptions(args haiconf.CommandArgs) error {
	xtraOpts, _ := haiconf.CheckStringList("ExtraOptions", args)
	l := len(xtraOpts)

	if l > 0 {
		ag.ExtraOptions = stringutils.RemoveDuplicates(xtraOpts)
	}

	return nil
}