示例#1
0
func fwk_run_cmd_build(cmd *commander.Command, args []string) error {
	var err error
	n := "fwk-app-" + cmd.Name()

	fnames := make([]string, 0, len(args))
	for _, arg := range args {
		if arg == "" {
			continue
		}
		if arg[0] == '-' {
			continue
		}
		fnames = append(fnames, arg)
	}

	if len(fnames) <= 0 {
		return fmt.Errorf("%s: you need to give a list of files or a directory", n)
	}

	bldr, err := builder.NewBuilder(fnames...)
	if err != nil {
		return err
	}

	if o := cmd.Flag.Lookup("o").Value.Get().(string); o != "" {
		bldr.Name = o
	}

	err = bldr.Build()
	if err != nil {
		return err
	}

	return err
}
示例#2
0
func hwaf_run_cmd_pmgr_get(cmd *commander.Command, args []string) {
	var err error
	n := "hwaf-pmgr-" + cmd.Name()
	verbose := cmd.Flag.Lookup("v").Value.Get().(bool)

	pkguri := ""
	switch len(args) {
	case 1:
		pkguri = args[0]
	default:
		err = fmt.Errorf("%s: you need to give a package URI to install", n)
		handle_err(err)
	}

	pkguri = strings.Replace(pkguri, "http://", "", 1)
	pkguri = strings.Replace(pkguri, "https://", "", 1)

	if verbose {
		fmt.Printf("%s: get [%s]...\n", n, pkguri)
	}

	//manifest_url := path.Join(pkguri, "MANIFEST")

	if verbose {
		fmt.Printf("%s: get [%s]... [ok]\n", n, pkguri)
	}
}
示例#3
0
文件: cmd_vm_add.go 项目: sbinet/alto
func alto_run_cmd_vm_add(cmd *commander.Command, args []string) {
	var err error
	n := "alto-" + cmd.Name()

	vm_name := ""
	vm_id := ""
	switch len(args) {
	case 2:
		vm_name = args[0]
		vm_id = args[1]
	default:
		err = fmt.Errorf("%s: needs 2 arguments (vm-name, vm-id)\n", n)
		handle_err(err)
	}

	quiet := cmd.Flag.Lookup("q").Value.Get().(bool)
	if !quiet {
		fmt.Printf("%s: adding VM [%s] to repository...\n", n, vm_name)
	}

	err = g_ctx.AddVm(altolib.Vm{Id: vm_id, Tag: vm_name})
	handle_err(err)

	if !quiet {
		fmt.Printf("%s: adding VM [%s] to repository... [done]\n", n, vm_name)
	}
	return
}
示例#4
0
文件: cmd_box_ls.go 项目: sbinet/alto
func alto_run_cmd_box_ls(cmd *commander.Command, args []string) {
	var err error
	n := "alto-" + cmd.Name()

	switch len(args) {
	case 0:
		// ok
	default:
		err = fmt.Errorf("%s: does not take any argument\n", n)
		handle_err(err)
	}

	quiet := cmd.Flag.Lookup("q").Value.Get().(bool)

	if !quiet {
		fmt.Printf("%s: listing boxes...\n", n)
	}

	boxes := g_ctx.Boxes()
	for _, box := range boxes {
		const indent = "    "
		fmt.Printf(
			"::: box [%s] (cpus=%d ram=%dMb)\n%s%v\n%s%v\n",
			box.Id, box.Cpus, box.Ram,
			indent, box.Vm,
			indent, box.Disk,
		)
	}

	if !quiet {
		fmt.Printf("%s: listing boxes... [done]\n", n)
	}

	return
}
示例#5
0
func hwaf_run_cmd_self_init(cmd *commander.Command, args []string) error {
	var err error
	n := "hwaf-self-" + cmd.Name()

	switch len(args) {
	case 0:
		// ok
	default:
		return fmt.Errorf("%s: does NOT take any argument", n)
	}

	verbose := cmd.Flag.Lookup("v").Value.Get().(bool)

	if verbose {
		fmt.Printf("%s...\n", n)
	}

	hwaf_root := os.Getenv("HWAF_ROOT")
	for _, dir := range []string{g_ctx.Root, hwaf_root} {
		if dir != "" {
			g_ctx.Warnf("you are trying to 'hwaf self init' while running a HWAF_ROOT-based installation\n")
			g_ctx.Warnf("this is like crossing the streams in Ghostbusters (ie: it's bad.)\n")
			g_ctx.Warnf("if you think you know what you are doing, unset HWAF_ROOT and re-run 'hwaf self init'\n")
			return fmt.Errorf("${HWAF_ROOT} was set (%s)", dir)
		}
	}

	// 'hwaf self init' is now dummied out...

	if verbose {
		fmt.Printf("%s... [ok]\n", n)
	}

	return err
}
示例#6
0
文件: cmd_vm_ls.go 项目: sbinet/alto
func alto_run_cmd_vm_ls(cmd *commander.Command, args []string) {
	var err error
	n := "alto-" + cmd.Name()

	switch len(args) {
	case 0:
		// ok
	default:
		err = fmt.Errorf("%s: does not take any argument\n", n)
		handle_err(err)
	}

	quiet := cmd.Flag.Lookup("q").Value.Get().(bool)

	if !quiet {
		fmt.Printf("%s: listing VMs...\n", n)
	}

	vms := g_ctx.Vms()
	for _, vm := range vms {
		fmt.Printf("%v\n", vm)
	}

	if !quiet {
		fmt.Printf("%s: listing VMs... [done]\n", n)
	}

	return
}
示例#7
0
func crossReleaseChanges(cmd *c.Command, args []string) {
	dev.MustFindCrowbar()
	if len(args) != 2 {
		log.Fatalf("%s takes exactly 2 release names!")
	}
	releases := new([2]dev.Release)
	// Translate command line parameters.
	// releases[0] will be the release with changes, and
	// releases[1] will be the base release.
	for i, name := range args {
		switch name {
		case "current":
			releases[i] = dev.CurrentRelease()
		case "parent":
			if i == 0 {
				log.Fatalf("parent can only be the second arg to %s\n", cmd.Name())
			}
			releases[1] = releases[0].Parent()
			if releases[1] == nil {
				log.Fatalf("%s does not have a parent release.\n", releases[0].Name())
			}
		default:
			releases[i] = dev.GetRelease(name)
		}
	}
	dev.CrossReleaseChanges(releases[0], releases[1])
}
示例#8
0
func git_run_cmd_dl_rm(cmd *commander.Command, args []string) {
	n := "github-" + cmd.Name()
	if len(args) != 1 {
		err := fmt.Errorf("%s: needs a file-id to delete", n)
		handle_err(err)
	}
	file_id := args[0]

	repo_name := cmd.Flag.Lookup("repo").Value.Get().(string)
	if repo_name == "" {
		err := fmt.Errorf("%s: needs a github repository name to delete from", n)
		handle_err(err)
	}

	user := cmd.Flag.Lookup("u").Value.Get().(string)
	org := cmd.Flag.Lookup("org").Value.Get().(string)

	if user == "" {
		v, err := Cfg.String("go-octogit", "username")
		handle_err(err)
		user = v
	}

	password, err := Cfg.String("go-octogit", "password")
	handle_err(err)

	ghc, err := client.NewGithubClient(user, password, client.AUTH_USER_PASSWORD)
	handle_err(err)

	account := user
	// DELETE /repos/:owner/:repo/downloads/:id
	if org != "" {
		account = org
	}
	url := path.Join("repos", account, repo_name, "downloads", file_id)

	fmt.Printf("%s: deleting download id=%s from [%s/%s]...\n",
		n, file_id, account, repo_name)

	req, err := ghc.NewAPIRequest("DELETE", url, nil)
	handle_err(err)

	resp, err := ghc.RunRequest(req, new(http.Client))
	handle_err(err)

	sc := resp.RawHttpResponse.StatusCode
	switch sc {
	case 204:
		// all good
	case 404:
		err = fmt.Errorf("%s: no such file-id\n", n)
	default:
		err = fmt.Errorf("%s: request did not succeed. got (status=%d) %v\n", n, resp.RawHttpResponse.StatusCode, resp.RawHttpResponse)
	}
	handle_err(err)

	fmt.Printf("%s: deleting download id=%s from [%s/%s]... [done]\n",
		n, file_id, account, repo_name)
}
示例#9
0
文件: cmd_down.go 项目: sbinet/alto
func alto_run_cmd_down(cmd *commander.Command, args []string) {
	var err error
	n := "alto-" + cmd.Name()

	switch len(args) {
	case 0:
		// ok
	default:
		err = fmt.Errorf("%s: does not take any argument\n", n)
		handle_err(err)
	}

	quiet := cmd.Flag.Lookup("q").Value.Get().(bool)
	do_kill := cmd.Flag.Lookup("kill").Value.Get().(bool)

	if !quiet {
		fmt.Printf("%s: shutting down...\n", n)
	}

	const cfg_fname = "AltoFile"
	if !path_exists(cfg_fname) {
		err = fmt.Errorf("%s: no such file [%s]. did you run 'alto init some-box-name' ?", n, cfg_fname)
		handle_err(err)
	}

	const id_fname = ".alto.id"
	if !path_exists(id_fname) {
		err = fmt.Errorf("%s: no such file [%s]. did you run 'alto up' ?", n, id_fname)
		handle_err(err)
	}

	data, err := ioutil.ReadFile(id_fname)
	handle_err(err)

	id := bytes.Trim(data, " \r\n")

	cmd_name := "stratus-shutdown-instance"
	if do_kill {
		cmd_name = "stratus-kill-instance"
	}

	ssh := exec.Command(cmd_name, string(id))
	ssh.Stdin = os.Stdin
	ssh.Stdout = os.Stdout
	ssh.Stderr = os.Stderr
	err = ssh.Run()
	handle_err(err)

	err = os.Remove(id_fname)
	handle_err(err)

	if !quiet {
		fmt.Printf("%s: shutting down... [done]\n", n)
	}
	return
}
示例#10
0
func remoteChanges(cmd *c.Command, args []string) {
	dev.MustFindCrowbar()
	switch len(args) {
	case 0:
		dev.RemoteChanges(dev.CurrentRelease())
	case 1:
		dev.RemoteChanges(dev.GetRelease(args[0]))
	default:
		log.Fatalf("%s takes 0 or 1 release name!\n", cmd.Name())
	}
}
func hwaf_run_cmd_git_rm_submodule(cmd *commander.Command, args []string) {
	var err error
	n := "hwaf-" + cmd.Name()

	pkgdir := ""
	pkgname := ""
	switch len(args) {
	case 1:
		pkgdir = args[0]
		pkgname = args[0]
	default:
		err = fmt.Errorf("%s: needs a submodule name to remove", n)
		handle_err(err)
	}

	nocommit := cmd.Flag.Lookup("no-commit").Value.Get().(bool)

	cmtpkgdir := "src"

	if !path_exists(pkgdir) {
		cfg, err := g_ctx.LocalCfg()
		handle_err(err)
		if cfg.HasOption("hwaf-cfg", "cmtpkgs") {
			cmtpkgdir, err = cfg.String("hwaf-cfg", "cmtpkgs")
			handle_err(err)
		}
		if path_exists(filepath.Join(cmtpkgdir, pkgdir)) {
			pkgdir = filepath.Join(cmtpkgdir, pkgdir)
		}
	}

	pkgdir = os.ExpandEnv(pkgdir)
	pkgdir = filepath.Clean(pkgdir)

	if !path_exists(pkgdir) {
		err = fmt.Errorf("no such directory [%s]", pkgdir)
		handle_err(err)
	}

	if !nocommit {
		git := exec.Command("git", "add", ".gitmodules")
		err = git.Run()
		handle_err(err)

		git = exec.Command(
			"git", "commit", "-m",
			fmt.Sprintf("removed submodule [%s]", pkgname),
		)
		err = git.Run()
		handle_err(err)
	}

	handle_err(err)
}
示例#12
0
func runPostHandleNameCmd(cmd *commander.Command, args []string) error {
	if err := validateCmdArgs(cmd, args); err != nil {
		return err
	}
	req, err := client.NewRequest("POST", "vm/"+cmd.Name()+"/"+args[0], nil)
	if err != nil {
		return err
	}
	if _, err := pp(client.Do(req)); err != nil {
		return err
	}
	return nil
}
示例#13
0
文件: cmd_status.go 项目: sbinet/alto
func alto_run_cmd_status(cmd *commander.Command, args []string) {
	var err error
	n := "alto-" + cmd.Name()

	switch len(args) {
	case 0:
		// ok
	default:
		err = fmt.Errorf("%s: does not take any argument\n", n)
		handle_err(err)
	}

	quiet := cmd.Flag.Lookup("q").Value.Get().(bool)
	all_boxes := cmd.Flag.Lookup("all").Value.Get().(bool)

	if !quiet {
		fmt.Printf("%s...\n", n)
	}

	cmd_name := "stratus-describe-instance"
	id := ""
	if !all_boxes {
		const id_fname = ".alto.id"
		if !path_exists(id_fname) {
			err = fmt.Errorf("%s: no such file [%s]. did you run 'alto up' ?", n, id_fname)
			handle_err(err)
		}

		data, err := ioutil.ReadFile(id_fname)
		handle_err(err)

		id = string(bytes.Trim(data, " \r\n"))
	}

	ssh_args := []string{}
	if id != "" {
		ssh_args = append(ssh_args, id)
	}
	ssh := exec.Command(cmd_name, ssh_args...)
	ssh.Stdin = os.Stdin
	ssh.Stdout = os.Stdout
	ssh.Stderr = os.Stderr
	err = ssh.Run()
	handle_err(err)

	if !quiet {
		fmt.Printf("%s:... [done]\n", n)
	}
	return
}
示例#14
0
func runGetListHandlesubidCmd(cmd *commander.Command, args []string) error {
	if err := validateCmdArgs(cmd, args); err != nil {
		return err
	}

	req, err := client.NewRequest("GET", "v1/"+cmd.Name()+"/list", nil)
	if err != nil {
		return err
	}
	if _, err := pp(client.Do(req)); err != nil {
		return err
	}
	return nil
}
示例#15
0
func run_setup_auth(cmd *commander.Command, args []string) error {
	n := cmd.Name()
	// fmt.Printf("%s:  args: %v\n", n, args)
	// fmt.Printf("%s: flags: %v\n", n, cmd.Flag.NArg())

	dirname := os.ExpandEnv(ami.ConfigDir)
	if !path_exists(dirname) {
		err := os.MkdirAll(dirname, 0700)
		if err != nil {
			return err
		}
	}
	dirname = os.ExpandEnv(ami.CertDir)
	if !path_exists(dirname) {
		err := os.MkdirAll(dirname, 0700)
		if err != nil {
			return err
		}
	}

	cert_fname := cmd.Flag.Lookup("usercert").Value.Get().(string)
	if !path_exists(cert_fname) {
		fmt.Printf("%s: no such user certificate file [%s]\n", n, cert_fname)
	}
	key_fname := cmd.Flag.Lookup("userkey").Value.Get().(string)
	if !path_exists(key_fname) {
		fmt.Printf("%s: no such user key file [%s]\n", n, key_fname)
	}

	user_cert, user_key, err := ami.LoadCert(cert_fname, key_fname)
	if err != nil {
		return err
	}

	cert_fname = filepath.Join(dirname, "usercert.pem")
	err = ioutil.WriteFile(cert_fname, user_cert, 0600)
	if err != nil {
		return err
	}

	key_fname = filepath.Join(dirname, "userkey.pem")
	err = ioutil.WriteFile(key_fname, user_key, 0600)
	if err != nil {
		return err
	}

	return nil
}
示例#16
0
func alto_run_cmd_disk_add(cmd *commander.Command, args []string) {
	var err error
	n := "alto-" + cmd.Name()

	switch len(args) {
	case 0:
		// ok
	default:
		err = fmt.Errorf("%s: does not take any argument\n", n)
		handle_err(err)
	}

	//quiet := cmd.Flag.Lookup("q").Value.Get().(bool)

	return
}
示例#17
0
func git_run_cmd_login(cmd *commander.Command, args []string) {
	n := "github-" + cmd.Name()

	user := cmd.Flag.Lookup("u").Value.Get().(string)
	fmt.Printf("github username: "******"" {
		_, err := fmt.Scanln(&user)
		handle_err(err)
	} else {
		fmt.Printf("%s\n", user)
	}

	password, err := getpasswd("github password: "******"go-octogit"
	for k, v := range map[string]string{
		"username": user,
		"password": password,
	} {
		if Cfg.HasOption(section, k) {
			Cfg.RemoveOption(section, k)
		}
		if !Cfg.AddOption(section, k, v) {
			err := fmt.Errorf("%s: could not add option [%s] to section [%s]", n, k, section)
			panic(err.Error())
		}
	}

	// check credentials
	ghc, err := client.NewGithubClient(user, password, client.AUTH_USER_PASSWORD)
	handle_err(err)

	req, err := ghc.NewAPIRequest("GET", "authorizations", nil)
	handle_err(err)

	resp, err := ghc.RunRequest(req, new(http.Client))
	handle_err(err)

	if !resp.IsSuccess() {
		err = fmt.Errorf("%s: authentication failed\n%v\n", n, resp.RawHttpResponse)
		handle_err(err)
	}

	err = Cfg.WriteFile(CfgFname, 0600, "")
	handle_err(err)
}
func hwaf_run_cmd_self_bdist_upload(cmd *commander.Command, args []string) {
	var err error
	n := "hwaf-self-" + cmd.Name()

	fname := ""
	switch len(args) {
	case 0:
		vers := time.Now().Format("20060102")
		arch := fmt.Sprintf("%s-%s", runtime.GOOS, runtime.GOARCH)
		fname = fmt.Sprintf("hwaf-%s-%s.tar.gz", vers, arch)
	case 1:
		fname = args[0]
	default:
		err = fmt.Errorf("%s: takes a path to a file to upload", n)
		handle_err(err)
	}

	verbose := cmd.Flag.Lookup("v").Value.Get().(bool)

	if verbose {
		fmt.Printf("%s [%s]...\n", n, fname)
	}

	if !path_exists(fname) {
		fname = os.ExpandEnv(fname)
		if !path_exists(fname) {
			err = fmt.Errorf("no such file [%s]", fname)
			handle_err(err)
		}
	}

	dst_dir := "[email protected]:/afs/cern.ch/atlas/project/hwaf/www/downloads/tar"
	dst := fmt.Sprintf("%s/%s", dst_dir, fname)
	scp := exec.Command("scp", fname, dst)
	scp.Stdin = os.Stdin
	scp.Stdout = os.Stdout
	scp.Stderr = os.Stderr
	err = scp.Run()
	handle_err(err)

	if verbose {
		fmt.Printf("%s [%s]... [ok]\n", n, fname)
	}
}
示例#19
0
文件: cmd_vm_rm.go 项目: sbinet/alto
func alto_run_cmd_vm_rm(cmd *commander.Command, args []string) {
	var err error
	n := "alto-" + cmd.Name()

	vm_id := ""
	switch len(args) {
	case 1:
		vm_id = args[0]
	default:
		err = fmt.Errorf("%s: takes one argument (vm-name or vm-id)\n", n)
		handle_err(err)
	}

	quiet := cmd.Flag.Lookup("q").Value.Get().(bool)
	if !quiet {
		fmt.Printf("%s: remove VM [%s] from repository...\n", n, vm_id)
	}

	found := false
	vms := g_ctx.Vms()
	for _, vm := range vms {
		switch vm_id {
		case vm.Tag:
			found = true
			err = g_ctx.RemoveVm(vm.Id)
			handle_err(err)
			break
		case vm.Id:
			found = true
			err = g_ctx.RemoveVm(vm.Id)
			handle_err(err)
			break
		}
	}
	if !found {
		err = fmt.Errorf("%s: could not find the VM [%s] in repository", n, vm_id)
		handle_err(err)
	}

	if !quiet {
		fmt.Printf("%s: remove VM [%s] from repository... [done]\n", n, vm_id)
	}
	return
}
示例#20
0
func runPostHandlesubidCmd(cmd *commander.Command, args []string) error {
	if err := validateCmdArgs(cmd, args); err != nil {
		return err
	}

	subid := args[0]
	form := url.Values{}
	form.Set("SUBID", subid)
	r := strings.NewReader(form.Encode())
	req, err := client.NewRequest("POST", "v1/server/"+cmd.Name(), r)
	if err != nil {
		return err
	}

	if _, err := pp(client.Do(req)); err != nil {
		return err
	}
	return nil
}
示例#21
0
func hwaf_run_cmd_waf_sdist(cmd *commander.Command, args []string) {
	var err error
	n := "hwaf-" + cmd.Name()

	fname := ""
	switch len(args) {
	case 0:
		fname = ""
	case 1:
		fname = args[0]
	default:
		err = fmt.Errorf("%s: too many arguments (%d)", n, len(args))
		handle_err(err)
	}

	if fname == "" {
	}

}
示例#22
0
文件: cmd_pkg_ls.go 项目: hwaf/hwaf
func hwaf_run_cmd_pkg_ls(cmd *commander.Command, args []string) error {
	var err error
	n := "hwaf-pkg-" + cmd.Name()
	pat := ".*?"
	switch len(args) {
	case 0:
		pat = ".*?"
	case 1:
		pat = args[0]
	default:
		return fmt.Errorf("%s: you need to give a package pattern to list", n)
	}

	verbose := cmd.Flag.Lookup("v").Value.Get().(bool)

	if verbose {
		fmt.Printf("%s: listing packages [%s]...\n", n, pat)
	}

	re_pkg, err := regexp.Compile(pat)
	if err != nil {
		return err
	}

	pkgs := g_ctx.PkgDb.Pkgs()
	for _, v := range pkgs {
		if re_pkg.MatchString(v) {
			pkg, err := g_ctx.PkgDb.GetPkg(v)
			if err != nil {
				return err
			}
			fmt.Printf("%s (%s)\n", pkg.Path, pkg.Type)
		}
	}

	if verbose {
		fmt.Printf("%s: listing packages [%s]... [ok]\n", n, pat)
	}

	return err
}
示例#23
0
func alto_run_cmd_market_ls(cmd *commander.Command, args []string) {
	var err error
	n := "alto-" + cmd.Name()

	switch len(args) {
	case 0:
		// ok
	default:
		err = fmt.Errorf("%s: does not take any argument\n", n)
		handle_err(err)
	}

	quiet := cmd.Flag.Lookup("q").Value.Get().(bool)

	if !quiet {
		fmt.Printf("%s: listing...\n", n)
	}

	resp, err := http.Get("https://marketplace.stratuslab.eu:443/metadata")
	handle_err(err)
	defer resp.Body.Close()

	type md_descr_t struct {
		Identifier string `xml:"dcterms:identifier"`
	}
	type MarketMetadata struct {
		XMLName xml.Name      `xml:"metadata"`
		Descr   []*md_descr_t `xml:"rdf:Description"`
	}

	md := MarketMetadata{}
	err = xml.NewDecoder(resp.Body).Decode(&md)
	handle_err(err)
	fmt.Printf(">>> %v\n", md)

	if !quiet {
		fmt.Printf("%s: listing... [done]\n", n)
	}

	return
}
示例#24
0
文件: cmd_init.go 项目: sbinet/alto
func alto_run_cmd_init(cmd *commander.Command, args []string) {
	var err error
	n := "alto-" + cmd.Name()

	box_id := ""
	switch len(args) {
	case 1:
		box_id = args[0]
	default:
		err = fmt.Errorf("%s: need a box id\n", n)
		handle_err(err)
	}

	quiet := cmd.Flag.Lookup("q").Value.Get().(bool)
	if !quiet {
		fmt.Printf("%s with box=%s...\n", n, box_id)
	}

	box, err := g_ctx.GetBox(box_id)
	handle_err(err)

	const fname = "AltoFile"
	if path_exists(fname) {
		err = fmt.Errorf("%s: a file [%s] already exists", n, fname)
		handle_err(err)
	}

	f, err := os.Create(fname)
	handle_err(err)
	defer f.Close()

	err = json.NewEncoder(f).Encode(&box)
	handle_err(err)
	handle_err(f.Sync())
	handle_err(f.Close())

	if !quiet {
		fmt.Printf("%s with box=%s... [done]\n", n, box_id)
	}
	return
}
示例#25
0
文件: cmd_box_rm.go 项目: sbinet/alto
func alto_run_cmd_box_rm(cmd *commander.Command, args []string) {
	var err error
	n := "alto-" + cmd.Name()

	box_id := ""
	switch len(args) {
	case 1:
		box_id = args[0]
	default:
		err = fmt.Errorf("%s: need the name of the box to remove\n", n)
		handle_err(err)
	}

	quiet := cmd.Flag.Lookup("q").Value.Get().(bool)
	if !quiet {
		fmt.Printf("%s: remove box [%s] from repository...\n", n, box_id)
	}

	found := false
	boxes := g_ctx.Boxes()
	for _, box := range boxes {
		switch box_id {
		case box.Id:
			found = true
			err = g_ctx.RemoveBox(box.Id)
			handle_err(err)
			break
		}
	}
	if !found {
		err = fmt.Errorf("%s: could not find the box [%s] in repository", n, box_id)
		handle_err(err)
	}

	if !quiet {
		fmt.Printf("%s: remove VM [%s] from repository... [done]\n", n, box_id)
	}
	return
}
示例#26
0
func runPostFileHandleNameCmd(cmd *commander.Command, args []string) error {
	if err := validateCmdArgs(cmd, args); err != nil {
		return err
	}
	cmdName := cmd.Name()
	pathStr := cmdName + "/" + args[0]
	switch len(args) {
	case 1:
		req, err := client.NewRequest("GET", pathStr, nil)
		if err != nil {
			return err
		}
		if _, err := pp(client.Do(req)); err != nil {
			return err
		}
	case 2:
		var b bytes.Buffer
		w := multipart.NewWriter(&b)
		if err := writeFileField(w, cmdName, args[1]); err != nil {
			return err
		}
		if err := w.Close(); err != nil {
			return err
		}

		req, err := client.NewRequest("POST", pathStr, &b)
		if err != nil {
			return err
		}
		req.Header.Set("Content-Type", w.FormDataContentType())

		if _, err := pp(client.Do(req)); err != nil {
			return err
		}
	default:
		return errors.New("invalid arguments")
	}
	return nil
}
示例#27
0
func runPostPortMapCmd(cmd *commander.Command, args []string) error {
	if err := validateCmdArgs(cmd, args); err != nil {
		return err
	}
	cmdName := cmd.Name()
	pathStr := cmdName + "/" + args[0]
	var b bytes.Buffer
	w := multipart.NewWriter(&b)
	if err := w.WriteField("port", args[1]); err != nil {
		return err
	}
	if err := w.Close(); err != nil {
		return err
	}
	req, err := client.NewRequest("POST", pathStr, &b)
	if err != nil {
		return err
	}
	req.Header.Set("Content-Type", w.FormDataContentType())
	if _, err := pp(client.Do(req)); err != nil {
		return err
	}
	return nil
}
示例#28
0
func hwaf_run_cmd_pkg_rm(cmd *commander.Command, args []string) {
	var err error
	n := "hwaf-pkg-" + cmd.Name()
	switch len(args) {
	case 0:
		err = fmt.Errorf("%s: you need to give (at least) one package name to remove", n)
		handle_err(err)
	}

	verbose := cmd.Flag.Lookup("v").Value.Get().(bool)
	force := cmd.Flag.Lookup("f").Value.Get().(bool)

	cfg, err := g_ctx.LocalCfg()
	handle_err(err)

	srcdir := "src"
	if cfg.HasOption("hwaf-cfg", "cmtpkgs") {
		srcdir, err = cfg.String("hwaf-cfg", "cmtpkgs")
		handle_err(err)
	}

	do_rm := func(pkgname string) error {
		var err error

		pkgname = os.ExpandEnv(pkgname)
		pkgname = filepath.Clean(pkgname)
		if verbose {
			fmt.Printf("%s: remove package [%s]...\n", n, pkgname)
		}

		pkg := pkgname
		if !g_ctx.PkgDb.HasPkg(pkg) {
			pkg = filepath.Join(srcdir, pkgname)
		}
		if !g_ctx.PkgDb.HasPkg(pkg) {
			return fmt.Errorf("%s: no such package [%s] in db", n, pkg)
		}

		// people may have already removed it via a simple 'rm -rf foo'...
		if !path_exists(pkg) && !force {
			err = fmt.Errorf(
				`%s: no such package [%s]
%s: did you remove it by hand ? (re-try with 'hwaf pkg rm -f %s')`,
				n, pkgname,
				n, pkgname,
			)
			return err
		}

		vcspkg, err := g_ctx.PkgDb.GetPkg(pkg)
		if err != nil {
			return err
		}

		switch vcspkg.Type {

		case "svn", "git":
			if path_exists(vcspkg.Path) {
				err = os.RemoveAll(vcspkg.Path)
				if err != nil {
					return err
				}
				path := vcspkg.Path
				// clean-up dir if empty...
				for {
					path = filepath.Dir(path)
					if path == srcdir {
						break
					}
					content, err := filepath.Glob(filepath.Join(path, "*"))
					if err != nil {
						return err
					}
					if len(content) > 0 {
						break
					}
					err = os.RemoveAll(path)
					if err != nil {
						return err
					}
				}
			}

		case "local":
			if path_exists(vcspkg.Path) {
				err = os.RemoveAll(vcspkg.Path)
				if err != nil {
					return err
				}
				path := vcspkg.Path
				// clean-up dir if empty...
				for {
					path = filepath.Dir(path)
					if path == srcdir {
						break
					}
					content, err := filepath.Glob(filepath.Join(path, "*"))
					if err != nil {
						return err
					}
					if len(content) > 0 {
						break
					}
					err = os.RemoveAll(path)
					if err != nil {
						return err
					}
				}
			}

		default:
			return fmt.Errorf("%s: VCS of type [%s] is not handled", n, vcspkg.Type)
		}

		err = g_ctx.PkgDb.Remove(pkg)
		if err != nil {
			if !force {
				return err
			}
		}

		if verbose {
			fmt.Printf("%s: remove package [%s]... [ok]\n", n, pkgname)
		}
		return nil
	}

	errs := []error{}
	for _, pkgname := range args {
		err := do_rm(pkgname)
		if err != nil {
			errs = append(errs, err)
		}
	}

	if len(errs) > 0 {
		for _, err := range errs {
			fmt.Printf("%s\n", err.Error())
		}
		npkgs := ""
		if len(args) > 1 {
			npkgs = "s"
		}
		sargs := make([]string, len(args))
		for i, s := range args {
			sargs[i] = fmt.Sprintf("%q", s)
		}
		handle_err(
			fmt.Errorf(
				"removing package%s %s failed.",
				npkgs, strings.Join(sargs, ", "),
			),
		)
	}
}
示例#29
0
func hwaf_run_cmd_pkg_create(cmd *commander.Command, args []string) {
	var err error
	n := "hwaf-pkg-" + cmd.Name()
	pkgpath := ""
	switch len(args) {
	case 1:
		pkgpath = args[0]
	default:
		err = fmt.Errorf("%s: you need to give a package (full) path", n)
		handle_err(err)
	}

	script := cmd.Flag.Lookup("script").Value.Get().(string)
	switch script {
	case "hscript", "wscript":
		// ok
	default:
		err = fmt.Errorf("%s: script type is either 'hscript' or 'wscript' (got: %q)", n, script)
		handle_err(err)
	}

	verbose := cmd.Flag.Lookup("v").Value.Get().(bool)
	authors := func() []string {
		authors := cmd.Flag.Lookup("authors").Value.Get().(string)
		out := make([]string, 0, 1)
		for _, s := range strings.Split(authors, ",") {
			s = strings.Trim(s, " ")
			if s == "" {
				continue
			}
			out = append(out, s)
		}
		return out
	}()

	if len(authors) == 0 {
		usr, err := user.Current()
		handle_err(err)
		//fmt.Printf(">>>>> %v\n", usr)
		usrname := usr.Name
		if usrname == "" {
			usrname = usr.Username
		}
		authors = []string{usrname}
	}

	if verbose {
		fmt.Printf("%s: create package [%s]...\n", n, pkgpath)
	}

	cfg, err := g_ctx.LocalCfg()
	handle_err(err)

	pkgdir := "src"
	if cfg.HasOption("hwaf-cfg", "pkgdir") {
		pkgdir, err = cfg.String("hwaf-cfg", "pkgdir")
		handle_err(err)
	}

	dir := filepath.Join(pkgdir, pkgpath)
	if path_exists(dir) {
		err = fmt.Errorf("%s: directory [%s] already exists on filesystem", n, dir)
		handle_err(err)
	}

	err = os.MkdirAll(dir, 0755)
	handle_err(err)

	if g_ctx.PkgDb.HasPkg(dir) {
		err = fmt.Errorf("%s: a package with name [%s] already exists", n, dir)
		handle_err(err)
	}

	pkgname := filepath.Base(pkgpath)

	const w_txt = `# -*- python -*-
# automatically generated wscript

import waflib.Logs as msg

PACKAGE = {
    'name': '{{.FullName}}',
    'author': [{{.Authors | printlst }}], 
}

def pkg_deps(ctx):
    # put your package dependencies here.
    # e.g.:
    # ctx.use_pkg('AtlasPolicy')
    return

def configure(ctx):
    msg.debug('[configure] package name: '+PACKAGE['name'])
    return

def build(ctx):
    # build artifacts
    # e.g.:
    # ctx.build_complib(
    #    name = '{{.Name}}',
    #    source = 'src/*.cxx src/components/*.cxx',
    #    use = ['lib1', 'lib2', 'ROOT', 'boost', ...],
    # )
    # ctx.install_headers()
    # ctx.build_pymodule(source=['python/*.py'])
    # ctx.install_joboptions(source=['share/*.py'])
    return
`

	const h_txt = `# -*- yaml -*-
# automatically generated hscript

package: {
  name: "{{.FullName}}",
  authors: [{{.Authors | printlst}}],

  ## dependencies of this package
  deps: {
    public: [
    ],

    private: [
    ],

    # specify runtime dependencies
    # e.g: python modules for scripts installed by this package
    #      binaries used by scripts installed by this package
    runtime: [
    ],
  },
}

options: {}
configure: {}

build: {
  # build artifacts
  # e.g.:
  # {{.Name}}: {
  #    source: "src/*.cxx src/components/*.cxx",
  #    use: ["lib1", "lib2", "ROOT", "boost", ...],
  # }
}

## EOF ##
`
	txt := h_txt
	fname := "hscript.yml"

	switch script {
	case "hscript":
		txt = h_txt
		fname = "hscript.yml"
	case "wscript":
		txt = w_txt
		fname = "wscript"
	}

	// create generic structure...
	for _, d := range []string{
		//"cmt",
		pkgname,
		"src",
	} {
		err = os.MkdirAll(filepath.Join(dir, d), 0755)
		handle_err(err)
	}

	wscript, err := os.Create(filepath.Join(dir, fname))
	handle_err(err)
	defer func() {
		err = wscript.Sync()
		handle_err(err)
		err = wscript.Close()
		handle_err(err)
	}()

	/* fill the template */
	pkg := struct {
		FullName string
		Name     string
		Authors  []string
	}{
		FullName: pkgpath,
		Name:     pkgname,
		Authors:  authors,
	}
	tmpl := template.New(script).Funcs(template.FuncMap{
		"printlst": func(lst []string) string {
			out := []string{}
			for idx, s := range lst {
				s = strings.Trim(s, " ")
				if s == "" {
					continue
				}
				comma := ","
				if idx+1 == len(lst) {
					comma = ""
				}
				out = append(out, fmt.Sprintf("%q%s", s, comma))
			}
			return strings.Join(out, " ")
		},
	})
	tmpl, err = tmpl.Parse(txt)
	handle_err(err)
	err = tmpl.Execute(wscript, &pkg)
	handle_err(err)

	err = g_ctx.PkgDb.Add("local", "", dir)
	handle_err(err)

	if verbose {
		fmt.Printf("%s: create package [%s]... [ok]\n", n, pkgpath)
	}
}
示例#30
0
func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
	var err error
	if len(args) < 3 {
		cmd.Usage()
		return err
	}

	command := cmd.Name()

	localRepoCollection := debian.NewLocalRepoCollection(context.database)

	dstRepo, err := localRepoCollection.ByName(args[1])
	if err != nil {
		return fmt.Errorf("unable to %s: %s", command, err)
	}

	err = localRepoCollection.LoadComplete(dstRepo)
	if err != nil {
		return fmt.Errorf("unable to %s: %s", command, err)
	}

	var (
		srcRefList *debian.PackageRefList
		srcRepo    *debian.LocalRepo
	)

	if command == "copy" || command == "move" {
		srcRepo, err = localRepoCollection.ByName(args[0])
		if err != nil {
			return fmt.Errorf("unable to %s: %s", command, err)
		}

		if srcRepo.UUID == dstRepo.UUID {
			return fmt.Errorf("unable to %s: source and destination are the same", command)
		}

		err = localRepoCollection.LoadComplete(srcRepo)
		if err != nil {
			return fmt.Errorf("unable to %s: %s", command, err)
		}

		srcRefList = srcRepo.RefList()
	} else if command == "import" {
		repoCollection := debian.NewRemoteRepoCollection(context.database)

		srcRepo, err := repoCollection.ByName(args[0])
		if err != nil {
			return fmt.Errorf("unable to %s: %s", command, err)
		}

		err = repoCollection.LoadComplete(srcRepo)
		if err != nil {
			return fmt.Errorf("unable to %s: %s", command, err)
		}

		if srcRepo.RefList() == nil {
			return fmt.Errorf("unable to %s: mirror not updated", command)
		}

		srcRefList = srcRepo.RefList()
	} else {
		panic("unexpected command")
	}

	context.progress.Printf("Loading packages...\n")

	packageCollection := debian.NewPackageCollection(context.database)
	dstList, err := debian.NewPackageListFromRefList(dstRepo.RefList(), packageCollection)
	if err != nil {
		return fmt.Errorf("unable to load packages: %s", err)
	}

	srcList, err := debian.NewPackageListFromRefList(srcRefList, packageCollection)
	if err != nil {
		return fmt.Errorf("unable to load packages: %s", err)
	}

	srcList.PrepareIndex()

	var architecturesList []string

	withDeps := cmd.Flag.Lookup("with-deps").Value.Get().(bool)

	if withDeps {
		dstList.PrepareIndex()

		// Calculate architectures
		if len(context.architecturesList) > 0 {
			architecturesList = context.architecturesList
		} else {
			architecturesList = dstList.Architectures(false)
		}

		sort.Strings(architecturesList)

		if len(architecturesList) == 0 {
			return fmt.Errorf("unable to determine list of architectures, please specify explicitly")
		}
	}

	toProcess, err := srcList.Filter(args[2:], withDeps, dstList, context.dependencyOptions, architecturesList)
	if err != nil {
		return fmt.Errorf("unable to %s: %s", command, err)
	}

	var verb string

	if command == "move" {
		verb = "moved"
	} else if command == "copy" {
		verb = "copied"
	} else if command == "import" {
		verb = "imported"
	}

	err = toProcess.ForEach(func(p *debian.Package) error {
		err = dstList.Add(p)
		if err != nil {
			return err
		}

		if command == "move" {
			srcList.Remove(p)
		}
		context.progress.ColoredPrintf("@g[o]@| %s %s", p, verb)
		return nil
	})
	if err != nil {
		return fmt.Errorf("unable to %s: %s", command, err)
	}

	if cmd.Flag.Lookup("dry-run").Value.Get().(bool) {
		context.progress.Printf("\nChanges not saved, as dry run has been requested.\n")
	} else {
		dstRepo.UpdateRefList(debian.NewPackageRefListFromPackageList(dstList))

		err = localRepoCollection.Update(dstRepo)
		if err != nil {
			return fmt.Errorf("unable to save: %s", err)
		}

		if command == "move" {
			srcRepo.UpdateRefList(debian.NewPackageRefListFromPackageList(srcList))

			err = localRepoCollection.Update(srcRepo)
			if err != nil {
				return fmt.Errorf("unable to save: %s", err)
			}
		}
	}

	return err
}