示例#1
0
func (pw *PackageWriter) fixupPKG() error {
	pkgBase := path.Base(pw.fullName)

	// Move include file to name after package name
	if err := util.MoveFile(pw.targetPath+"/include/your-path/your-file.h",
		pw.targetPath+"/include/your-path/"+pkgBase+".h"); err != nil {
		return err
	}

	// Move source file
	if err := util.MoveFile(pw.targetPath+"/src/your-source.c",
		pw.targetPath+"/src/"+pkgBase+".c"); err != nil {
		return err
	}

	if err := util.CopyDir(pw.targetPath+"/include/your-path/",
		pw.targetPath+"/include/"+pkgBase+"/"); err != nil {
		return err
	}

	if err := os.RemoveAll(pw.targetPath + "/include/your-path/"); err != nil {
		return util.ChildNewtError(err)
	}

	if err := pw.cleanupPackageFile(pw.targetPath + "/pkg.yml"); err != nil {
		return err
	}

	return nil
}
示例#2
0
func (pw *PackageWriter) WritePackage() error {
	dl := pw.downloader

	dl.User = PACKAGEWRITER_GITHUB_DOWNLOAD_USER
	dl.Repo = pw.repo

	util.StatusMessage(util.VERBOSITY_DEFAULT,
		"Download package template for package type %s.\n",
		strings.ToLower(pw.template))

	tmpdir, err := dl.DownloadRepo(PACKAGEWRITER_GITHUB_DOWNLOAD_BRANCH)
	if err != nil {
		return err
	}

	if err := os.RemoveAll(tmpdir + "/.git/"); err != nil {
		return util.NewNewtError(err.Error())
	}

	if err := util.CopyDir(tmpdir, pw.targetPath); err != nil {
		return err
	}

	switch pw.template {
	case "PKG":
		if err := pw.fixupPKG(); err != nil {
			return err
		}
	}

	util.StatusMessage(util.VERBOSITY_DEFAULT,
		"Package successfuly installed into %s.\n", pw.targetPath)

	return nil
}
示例#3
0
func (r *Repo) downloadRepo(branchName string) error {
	dl := r.downloader

	// Download the git repo, returns the git repo, checked out to that branch
	tmpdir, err := dl.DownloadRepo(branchName)
	if err != nil {
		return util.NewNewtError(fmt.Sprintf("Error download repository %s, : %s",
			r.Name(), err.Error()))
	}

	// Copy the Git repo into the the desired local path of the repo
	if err := util.CopyDir(tmpdir, r.Path()); err != nil {
		// Cleanup any directory that might have been created if we error out
		// here.
		os.RemoveAll(r.Path())
		return err
	}

	return nil
}
func (ld *LocalDownloader) DownloadRepo(commit string) (string, error) {
	// Get a temporary directory, and copy the repository into that directory.
	tmpdir, err := ioutil.TempDir("", "newt-repo")
	if err != nil {
		return "", err
	}

	util.StatusMessage(util.VERBOSITY_VERBOSE,
		"Downloading local repository %s\n", ld.Path)

	if err := util.CopyDir(ld.Path, tmpdir); err != nil {
		return "", err
	}

	// Checkout the specified commit.
	if err := checkout(tmpdir, commit); err != nil {
		return "", err
	}

	return tmpdir, nil
}
func newRunCmd(cmd *cobra.Command, args []string) {
	if len(args) < 1 {
		NewtUsage(cmd, util.NewNewtError("Must specify "+
			"a project directory to newt new"))
	}

	newDir := args[0]

	if util.NodeExist(newDir) {
		NewtUsage(cmd, util.NewNewtError("Cannot create new project, "+
			"directory already exists"))
	}

	util.StatusMessage(util.VERBOSITY_DEFAULT, "Downloading "+
		"project skeleton from apache/incubator-mynewt-blinky...\n")
	dl := downloader.NewGithubDownloader()
	dl.User = "******"
	dl.Repo = "incubator-mynewt-blinky"

	dir, err := dl.DownloadRepo(newtutil.NewtBlinkyTag)
	if err != nil {
		NewtUsage(cmd, err)
	}

	util.StatusMessage(util.VERBOSITY_DEFAULT, "Installing "+
		"skeleton in %s...\n", newDir)

	if err := util.CopyDir(dir, newDir); err != nil {
		NewtUsage(cmd, err)
	}

	if err := os.RemoveAll(newDir + "/" + "/.git/"); err != nil {
		NewtUsage(cmd, err)
	}

	util.StatusMessage(util.VERBOSITY_DEFAULT,
		"Project %s successfully created.\n", newDir)
}