aboutsummaryrefslogtreecommitdiffstats
path: root/autobuild
diff options
context:
space:
mode:
authorScott Murray <scott.murray@konsulko.com>2020-06-25 17:58:53 -0400
committerScott Murray <scott.murray@konsulko.com>2020-06-25 17:59:09 -0400
commitb33bdb202c1e7d2d36611793e8d5a9c7b39f05ed (patch)
treede076776b866242e15735ea27d49bad185acc1ca /autobuild
parent702b701fb181bb965c0ef13063d180e296e3ece3 (diff)
Fix a couple of issues related to running the autobuild script from outside the source tree. Bug-AGL: SPEC-3300 Signed-off-by: Scott Murray <scott.murray@konsulko.com> Change-Id: I32436a3a3b385ab9ca278e1cab67fa43bd9e4eec
Diffstat (limited to 'autobuild')
-rwxr-xr-xautobuild/agl/autobuild2
-rwxr-xr-xautobuild/linux/autobuild2
2 files changed, 4 insertions, 0 deletions
diff --git a/autobuild/agl/autobuild b/autobuild/agl/autobuild
index fa1d1c2..fa27570 100755
--- a/autobuild/agl/autobuild
+++ b/autobuild/agl/autobuild
@@ -73,6 +73,7 @@ clean-all: clean-release
distclean: clean-all
configure-release: clean-release
+ @cd $(ROOT_DIR)
@rm -rf node_modules
@npm install
@@ -90,6 +91,7 @@ build-debug: ;
build-all: build-release
package-release: package-%: build-%
+ @mkdir -p $(OUTPUT_DIR)/
@cp $(ROOT_DIR)/package/*.wgt $(OUTPUT_DIR)/
@if [ "$(abspath $(DEST))" != "$(abspath $(OUTPUT_DIR))" ]; then \
mkdir -p $(DEST) && cp $(OUTPUT_DIR)/*.wgt $(DEST); \
diff --git a/autobuild/linux/autobuild b/autobuild/linux/autobuild
index fa1d1c2..fa27570 100755
--- a/autobuild/linux/autobuild
+++ b/autobuild/linux/autobuild
@@ -73,6 +73,7 @@ clean-all: clean-release
distclean: clean-all
configure-release: clean-release
+ @cd $(ROOT_DIR)
@rm -rf node_modules
@npm install
@@ -90,6 +91,7 @@ build-debug: ;
build-all: build-release
package-release: package-%: build-%
+ @mkdir -p $(OUTPUT_DIR)/
@cp $(ROOT_DIR)/package/*.wgt $(OUTPUT_DIR)/
@if [ "$(abspath $(DEST))" != "$(abspath $(OUTPUT_DIR))" ]; then \
mkdir -p $(DEST) && cp $(OUTPUT_DIR)/*.wgt $(DEST); \
bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
package main

import (
	"fmt"
	"strings"

	"github.com/iotbzh/xds-agent/lib/apiv1"
	"github.com/urfave/cli"
)

func initCmdProjects(cmdDef *[]cli.Command) {
	*cmdDef = append(*cmdDef, cli.Command{
		Name:     "projects",
		Aliases:  []string{"prj"},
		HideHelp: true,
		Usage:    "project commands group",
		Subcommands: []cli.Command{
			{
				Name:    "add",
				Aliases: []string{"a"},
				Usage:   "Add a new project",
				Action:  projectsAdd,
				Flags: []cli.Flag{
					cli.StringFlag{
						Name:  "label, l",
						Usage: "project label (free form string)",
					},
					cli.StringFlag{
						Name:  "path, p",
						Usage: "project local path",
					},
					cli.StringFlag{
						Name:  "server-path, sp",
						Usage: "project server path (only used with pathmap type)",
					},
					cli.StringFlag{
						Name:  "type, t",
						Usage: "project type (pathmap|pm, cloudsync|sc)",
					},
				},
			},
			{
				Name:   "get",
				Usage:  "Get a property of a project",
				Action: projectsGet,
				Flags: []cli.Flag{
					cli.StringFlag{
						Name:  "id",
						Usage: "project id",
					},
				},
			},
			{
				Name:    "list",
				Aliases: []string{"ls"},
				Usage:   "List existing projects",
				Action:  projectsList,
				Flags: []cli.Flag{
					cli.BoolFlag{
						Name:  "verbose, v",
						Usage: "display verbose output",
					},
				},
			},
			{
				Name:    "remove",
				Aliases: []string{"rm"},
				Usage:   "Remove an existing project",
				Action:  projectsRemove,
				Flags: []cli.Flag{
					cli.StringFlag{
						Name:  "id",
						Usage: "project id",
					},
				},
			},
			{
				Name:    "sync",
				Aliases: []string{},
				Usage:   "Force synchronization of project sources",
				Action:  projectsSync,
				Flags: []cli.Flag{
					cli.StringFlag{
						Name:  "id",
						Usage: "project id",
					},
				},
			},
		},
	})
}

func projectsList(ctx *cli.Context) error {
	// Get projects list
	prjs := []apiv1.ProjectConfig{}
	if err := ProjectsListGet(&prjs); err != nil {
		return cli.NewExitError(err.Error(), 1)
	}
	_displayProjects(prjs, ctx.Bool("verbose"))
	return nil
}

func projectsGet(ctx *cli.Context) error {
	id := GetID(ctx)
	if id == "" {
		return cli.NewExitError("id parameter or option must be set", 1)
	}
	prjs := make([]apiv1.ProjectConfig, 1)
	if err := HTTPCli.Get("/projects/"+id, &prjs[0]); err != nil {
		return cli.NewExitError(err, 1)
	}
	_displayProjects(prjs, true)
	return nil
}

func _displayProjects(prjs []apiv1.ProjectConfig, verbose bool) {
	// Display result
	first := true
	writer := NewTableWriter()
	for _, folder := range prjs {
		if verbose {
			if !first {
				fmt.Fprintln(writer)
			}
			fmt.Fprintln(writer, "ID:\t", folder.ID)
			fmt.Fprintln(writer, "Label:\t", folder.Label)
			fmt.Fprintln(writer, "Path type:\t", folder.Type)
			fmt.Fprintln(writer, "Local Path:\t", folder.ClientPath)
			if folder.Type != apiv1.TypeCloudSync {
				fmt.Fprintln(writer, "Server Path:\t", folder.ServerPath)
			}
			fmt.Fprintln(writer, "Status:\t", folder.Status)
			fmt.Fprintln(writer, "Is in Sync:\t", folder.IsInSync)
			ds := folder.DefaultSdk
			if ds == "" {
				ds = "-"
			}
			fmt.Fprintln(writer, "Default Sdk:\t", ds)

		} else {
			if first {
				fmt.Fprintln(writer, "ID\t Label\t LocalPath")
			}
			fmt.Fprintln(writer, folder.ID, "\t", folder.Label, "\t", folder.ClientPath)
		}
		first = false
	}
	writer.Flush()
}

func projectsAdd(ctx *cli.Context) error {

	// Decode project type
	var ptype apiv1.ProjectType
	switch strings.ToLower(ctx.String("type")) {
	case "pathmap", "pm":
		ptype = apiv1.TypePathMap
	case "cloudsync", "cs":
		ptype = apiv1.TypeCloudSync
	default:
		return cli.NewExitError("Unknown project type", 1)
	}

	prj := apiv1.ProjectConfig{
		ServerID:   XdsServerIDGet(),
		Label:      ctx.String("label"),
		Type:       ptype,
		ClientPath: ctx.String("path"),
		ServerPath: ctx.String("server-path"),
	}

	Log.Infof("POST /project %v", prj)
	newPrj := apiv1.ProjectConfig{}
	err := HTTPCli.Post("/projects", prj, &newPrj)
	if err != nil {
		return cli.NewExitError(err, 1)
	}

	fmt.Printf("New project '%s' (id %v) successfully created.\n", newPrj.Label, newPrj.ID)

	return nil
}

func projectsRemove(ctx *cli.Context) error {
	var res apiv1.ProjectConfig
	id := GetID(ctx)
	if id == "" {
		return cli.NewExitError("id parameter or option must be set", 1)
	}

	if err := HTTPCli.Delete("/projects/"+id, &res); err != nil {
		return cli.NewExitError(err, 1)
	}

	fmt.Println("Project ID " + res.ID + " successfully deleted.")
	return nil
}

func projectsSync(ctx *cli.Context) error {
	id := GetID(ctx)
	if id == "" {
		return cli.NewExitError("id parameter or option must be set", 1)
	}
	if err := HTTPCli.Post("/projects/sync/"+id, "", nil); err != nil {
		return cli.NewExitError(err, 1)
	}
	fmt.Println("Sync successfully resquested.")
	return nil
}