Пример #1
0
func NewContextFrom(workarea string) (*Context, error) {
	var err error
	var ctx *Context

	if !path_exists(workarea) {
		err = fmt.Errorf("hwaf: no such directory [%s]", workarea)
		return nil, err
	}

	wdir := string(workarea)
	ctx = &Context{
		Root:     "",
		sitedir:  "",
		variant:  "",
		workarea: &wdir,
		gcfg:     nil,
		lcfg:     nil,
		PkgDb:    nil,
		msg:      logger.New("hwaf"),
		subcmds:  make([]*exec.Cmd, 0),
		atexit:   make([]func(), 0),
	}

	err = ctx.init()
	return ctx, err
}
Пример #2
0
func NewContext() (*Context, error) {
	var err error
	var ctx *Context

	ctx = &Context{
		Root:     "",
		sitedir:  "",
		variant:  "",
		workarea: nil,
		gcfg:     nil,
		lcfg:     nil,
		PkgDb:    nil,
		msg:      logger.New("hwaf"),
		subcmds:  make([]*exec.Cmd, 0),
		atexit:   make([]func(), 0),
	}

	err = ctx.init()
	return ctx, err
}
Пример #3
0
func NewBase(name string) *Base {
	return &Base{
		Logger: logger.New(name),
		ticker: time.NewTicker(1 * time.Second),
	}
}
Пример #4
0
func lbpkr_run_cmd_self_bdist(cmd *commander.Command, args []string) error {
	var err error

	debug := cmd.Flag.Lookup("v").Value.Get().(bool)
	name := cmd.Flag.Lookup("name").Value.Get().(string)
	vers := cmd.Flag.Lookup("version").Value.Get().(string)

	switch len(args) {
	case 0:
	default:
		cmd.Usage()
		return fmt.Errorf("lbpkr: invalid number of arguments. expected n=0. got=%d (%v)",
			len(args),
			args,
		)
	}

	tmpdir, err := ioutil.TempDir("", "lbpkr-self-bdist-")
	if err != nil {
		return err
	}
	defer os.RemoveAll(tmpdir)
	//fmt.Printf(">>> [%s]\n", tmpdir)

	msg := logger.New("lbpkr")
	if debug {
		msg.SetLevel(logger.DEBUG)
	}

	lbpkr, err := exec.LookPath(os.Args[0])
	if err != nil {
		msg.Errorf("could not locate '%s': %v\n", err, os.Args[0])
		return err
	}

	lbpkr, err = filepath.EvalSymlinks(lbpkr)
	if err != nil {
		msg.Errorf("could not find '%s' executable: %v\n", lbpkr, err)
		return err
	}

	data := struct {
		Name    string
		Version string
		Arch    string
	}{
		Name:    name,
		Version: vers,
		Arch:    "x86_64",
	}

	switch runtime.GOARCH {
	case "amd64":
		data.Arch = "x86_64"
	case "386":
		data.Arch = "i686"
	}

	bdist_fname := fmt.Sprintf("%s-%s.%s.tar.gz", data.Name, data.Version, data.Arch)
	bdist_fname, err = filepath.Abs(bdist_fname)
	if err != nil {
		return err
	}
	msg.Infof("creating [%s]...\n", bdist_fname)

	// prepare a tarball with the lbpkr binary.
	dirname := fmt.Sprintf("%s-%s", data.Name, data.Version)

	//
	top := filepath.Join(tmpdir, dirname)

	// create hierarchy of dirs for bdist
	for _, dir := range []string{
		filepath.Join("usr", "bin"),
	} {
		err = os.MkdirAll(filepath.Join(top, dirname, dir), 0755)
		if err != nil {
			return err
		}
	}

	// install under /bin
	dst_lbpkr := filepath.Join(top, dirname, "usr", "bin", "lbpkr")
	dst, err := os.OpenFile(dst_lbpkr, os.O_WRONLY|os.O_CREATE, 0755)
	if err != nil {
		return err
	}
	defer func(dst *os.File) error {
		err := dst.Sync()
		if err != nil {
			return err
		}
		err = dst.Close()
		return err
	}(dst)

	src, err := os.Open(lbpkr)
	if err != nil {
		return err
	}
	defer func(src *os.File) error {
		return src.Close()
	}(src)

	_, err = io.Copy(dst, src)
	if err != nil {
		return err
	}

	// create tarball
	err = _tar_gz(bdist_fname, top)
	if err != nil {
		return err
	}

	msg.Infof("creating [%s]... [ok]\n", bdist_fname)
	return err
}
Пример #5
0
	"os/exec"
	"path/filepath"
	"regexp"
	"sort"
	"strings"

	"github.com/gonuts/logger"
	"gopkg.in/yaml.v2"
)

var (
	cfg = Config{
		njobs:   1,
		disable: make(map[string]struct{}),
	}
	msg = logger.New("aligot")
)

type Config struct {
	action      string
	pkgs        []string
	cfgdir      string
	devel       []string
	docker      string
	wdir        string
	arch        string
	env         []string
	volumes     []string
	njobs       int
	refsrc      string
	remoteStore string
Пример #6
0
func lbpkr_run_cmd_self_upload_rpm(cmd *commander.Command, args []string) error {
	var err error

	cfgtype := cmd.Flag.Lookup("type").Value.Get().(string)
	debug := cmd.Flag.Lookup("v").Value.Get().(bool)

	fname := ""
	switch len(args) {
	case 1:
		fname = args[0]
	default:
		cmd.Usage()
		return fmt.Errorf("lbpkr: invalid number of arguments. expected n=1. got=%d (%v)",
			len(args),
			args,
		)
	}

	//cfg := NewConfig(cfgtype)
	msg := logger.New("lbpkr")
	if debug {
		msg.SetLevel(logger.DEBUG)
	}

	msg.Infof("uploading [%s]...\n", fname)

	switch cfgtype {
	case "lhcb":
		rpmdir := "/afs/cern.ch/lhcb/distribution/rpm"
		dst := filepath.Join(rpmdir, "lhcb", fname)
		err = bincp(dst, fname)
		if err != nil {
			msg.Errorf("could not copy [%s] into [%s] (err=%v)\n", fname, dst, err)
			return err
		}

		msg.Debugf("updating metadata...\n")
		updatecmd := filepath.Join(rpmdir, "update.sh")
		regen := newCommand(updatecmd)
		regen.Dir = rpmdir
		regen.Stdout = os.Stdout
		regen.Stderr = os.Stderr
		regen.Stdin = os.Stdin
		err = regen.Run()
		if err != nil {
			msg.Errorf("could not regenerate metadata: %v\n", err)
			return err
		}
		msg.Debugf("updating metadata... [ok]\n")

		lbpkr, err := exec.LookPath(os.Args[0])
		if err != nil {
			msg.Errorf("could not locate '%s': %v\n", err, os.Args[0])
			return err
		}

		lbpkr, err = filepath.EvalSymlinks(lbpkr)
		if err != nil {
			msg.Errorf("could not find '%s' executable: %v\n", lbpkr, err)
			return err
		}

		err = bincp(filepath.Join(rpmdir, "lbpkr"), lbpkr)
		if err != nil {
			msg.Errorf("could not copy 'lbpkr': %v\n", err)
			return err
		}

	default:
		return fmt.Errorf("lbpkr: config type [%s] not handled", cfgtype)
	}

	msg.Infof("uploading [%s]... [ok]\n", fname)
	return err
}
Пример #7
0
package main

import (
	"flag"
	"fmt"
	"os"
	"path/filepath"

	"github.com/gonuts/logger"
)

var msg = logger.New("gen-lcgcmt")
var g_out = flag.String("o", "hscript.py", "path to hscript.py file to generate")
var g_debug = flag.Bool("v", false, "enable debug output")
var g_verbose = flag.Bool("vv", false, "enable verbose output")

func init() {
	flag.Usage = func() {
		bin := filepath.Base(os.Args[0])
		fmt.Fprintf(os.Stderr, "Usage of %s:\n", bin)
		fmt.Fprintf(
			os.Stderr,
			`$ %s [options] path/to/lcgcmt.txt

ex:
 $ %s /afs/cern.ch/sw/lcg/experimental/LCG-preview/LCG_x86_64-slc6-gcc48-opt.txt

options:
`,
			bin, bin,
		)
Пример #8
0
func lbpkr_run_cmd_self_bdist_rpm(cmd *commander.Command, args []string) error {
	var err error

	debug := cmd.Flag.Lookup("v").Value.Get().(bool)
	name := cmd.Flag.Lookup("name").Value.Get().(string)
	vers := cmd.Flag.Lookup("version").Value.Get().(string)
	release := cmd.Flag.Lookup("release").Value.Get().(int)

	switch len(args) {
	case 0:
	default:
		cmd.Usage()
		return fmt.Errorf("lbpkr: invalid number of arguments. expected n=0. got=%d (%v)",
			len(args),
			args,
		)
	}

	tmpdir, err := ioutil.TempDir("", "lbpkr-self-bdist-rpm-")
	if err != nil {
		return err
	}
	defer os.RemoveAll(tmpdir)
	//fmt.Printf(">>> [%s]\n", tmpdir)

	rpmbuildroot := filepath.Join(tmpdir, "rpmbuild")

	// make sure there is no hysteresis effect from outside
	err = os.Setenv("MYSITEROOT", "")
	if err != nil {
		return fmt.Errorf("error resetting $MYSITEROOT: %v", err)
	}

	siteroot := ""
	cfg := NewConfig(siteroot)
	msg := logger.New("lbpkr")
	if debug {
		msg.SetLevel(logger.DEBUG)
	}

	rpmbuild, err := exec.LookPath("rpmbuild")
	if err != nil {
		msg.Errorf("could not locate 'rpmbuild': %v\n", err)
		return err
	}

	tarcmd := newCommand("lbpkr",
		"self", "bdist",
		"-name="+name,
		"-version="+vers,
		fmt.Sprintf("-v=%v", debug),
	)
	tarcmd.Stdout = os.Stdout
	tarcmd.Stderr = os.Stderr
	tarcmd.Stdin = os.Stdin
	err = tarcmd.Run()
	if err != nil {
		msg.Errorf("could not create tarball: %v\n", err)
		return err
	}

	data := struct {
		Url       string
		Prefix    string
		BuildRoot string
		Name      string
		Version   string
		Release   int
	}{
		Url:       "http://github.com/lhcb-org/lbpkr",
		Prefix:    cfg.Siteroot(),
		BuildRoot: tmpdir,
		Name:      name,
		Version:   vers,
		Release:   release,
	}

	rpm_arch := "x86_64"
	switch runtime.GOARCH {
	case "amd64":
		rpm_arch = "x86_64"
	case "386":
		rpm_arch = "i686"
	}

	rpm_fname := fmt.Sprintf("%s-%s-%d.%s.rpm", data.Name, data.Version, data.Release, rpm_arch)
	msg.Infof("creating [%s]...\n", rpm_fname)

	// prepare a tarball with the lbpkr binary.
	dirname := fmt.Sprintf("%s-%s", data.Name, data.Version)
	fname := dirname + ".tar.gz"
	bdist_fname := dirname + "." + rpm_arch + ".tar.gz"

	// create hierarchy of dirs for rpmbuild
	for _, dir := range []string{"RPMS", "SRPMS", "BUILD", "SOURCES", "SPECS", "tmp"} {
		err = os.MkdirAll(filepath.Join(rpmbuildroot, dir), 0755)
		if err != nil {
			return err
		}
	}

	// copy tarball
	err = bincp(filepath.Join(rpmbuildroot, "SOURCES", fname), bdist_fname)
	if err != nil {
		return err
	}

	// create spec-file
	spec_fname := fmt.Sprintf("%s-%s-%d.spec", data.Name, data.Version, data.Release)
	spec, err := os.Create(filepath.Join(
		rpmbuildroot, "SPECS",
		spec_fname,
	))
	if err != nil {
		return err
	}
	defer spec.Close()
	t := template.Must(template.New("bdist-rpm-spec").Parse(rpm_tmpl))
	err = t.Execute(spec, &data)
	if err != nil {
		return err
	}
	spec.Sync()
	spec.Close()

	rpm := newCommand(rpmbuild, "-ba", filepath.Join("SPECS", spec_fname))
	rpm.Dir = rpmbuildroot
	if debug {
		rpm.Stdout = os.Stdout
		rpm.Stderr = os.Stderr
	}

	err = rpm.Run()
	if err != nil {
		return err
	}

	err = bincp(rpm_fname, filepath.Join(rpmbuildroot, "RPMS", rpm_arch, rpm_fname))
	if err != nil {
		return err
	}

	msg.Infof("creating [%s]... [ok]\n", rpm_fname)

	msg.Infof("content of [%s]:\n", rpm_fname)
	rpm = newCommand("rpm", "-q", "-filesbypkg", "-p", rpm_fname)
	rpm.Stdout = os.Stdout
	rpm.Stderr = os.Stderr
	err = rpm.Run()
	if err != nil {
		return err
	}

	return err
}