Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 3B836200BCC for ; Tue, 15 Nov 2016 03:40:17 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 39F0F160B0D; Tue, 15 Nov 2016 02:40:17 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 5C6C9160B06 for ; Tue, 15 Nov 2016 03:40:16 +0100 (CET) Received: (qmail 17056 invoked by uid 500); 15 Nov 2016 02:40:15 -0000 Mailing-List: contact commits-help@mynewt.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@mynewt.incubator.apache.org Delivered-To: mailing list commits@mynewt.incubator.apache.org Received: (qmail 17047 invoked by uid 99); 15 Nov 2016 02:40:15 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Nov 2016 02:40:15 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 22177180617 for ; Tue, 15 Nov 2016 02:40:15 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -6.218 X-Spam-Level: X-Spam-Status: No, score=-6.218 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id 0QyqEJLWm7RA for ; Tue, 15 Nov 2016 02:40:12 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 951175F472 for ; Tue, 15 Nov 2016 02:40:11 +0000 (UTC) Received: (qmail 17017 invoked by uid 99); 15 Nov 2016 02:40:10 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Nov 2016 02:40:10 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9DB72DFFAB; Tue, 15 Nov 2016 02:40:10 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ccollins@apache.org To: commits@mynewt.incubator.apache.org Message-Id: <7ccc93cd2e5e498e950777a2739427fc@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: incubator-mynewt-newt git commit: newt - Allow "install" from local machine Date: Tue, 15 Nov 2016 02:40:10 +0000 (UTC) archived-at: Tue, 15 Nov 2016 02:40:17 -0000 Repository: incubator-mynewt-newt Updated Branches: refs/heads/develop 00ec2a349 -> 496fc3327 newt - Allow "install" from local machine This commit is to aid in testing of unreleased version of Mynewt. Prior to his change, newt needed to clone a repo in order to determine which branch or tag it should check out. Now, a project.yml file can specify a repo type of "local". When installing from a local repo, newt assumes an up-to-date clone exists at the specified path, so it just copies the directory rather than cloning with git. Example local repo (project.yml): repository.apache-mynewt-core: type: local vers: 0-latest path: "/Users/ccollins/repos/tmp/core" Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/496fc332 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/496fc332 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/496fc332 Branch: refs/heads/develop Commit: 496fc3327f8e5a8d028c356c769164d5fe30ff53 Parents: 00ec2a3 Author: Christopher Collins Authored: Mon Nov 14 18:35:24 2016 -0800 Committer: Christopher Collins Committed: Mon Nov 14 18:35:24 2016 -0800 ---------------------------------------------------------------------- newt/downloader/downloader.go | 85 ++++++++++++++++++++++++++++++++++++++ newt/project/project.go | 33 ++------------- newt/repo/repo.go | 15 +++---- 3 files changed, 95 insertions(+), 38 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/496fc332/newt/downloader/downloader.go ---------------------------------------------------------------------- diff --git a/newt/downloader/downloader.go b/newt/downloader/downloader.go index 7cf1892..29c0677 100644 --- a/newt/downloader/downloader.go +++ b/newt/downloader/downloader.go @@ -30,6 +30,7 @@ import ( log "github.com/Sirupsen/logrus" + "mynewt.apache.org/newt/newt/newtutil" "mynewt.apache.org/newt/util" ) @@ -57,6 +58,13 @@ type GithubDownloader struct { Password string } +type LocalDownloader struct { + GenericDownloader + + // Path to parent directory of repository.yml file. + Path string +} + func (gd *GenericDownloader) Branch() string { return gd.branch } @@ -194,3 +202,80 @@ func (gd *GithubDownloader) DownloadRepo(commit string) (string, error) { func NewGithubDownloader() *GithubDownloader { return &GithubDownloader{} } + +func (ld *LocalDownloader) FetchFile(name string, dest string) error { + srcPath := ld.Path + "/" + name + + log.Debugf("Fetching file %s to %s", srcPath, dest) + if err := util.CopyFile(srcPath, dest); err != nil { + 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 + } + + return tmpdir, nil +} + +func NewLocalDownloader() *LocalDownloader { + return &LocalDownloader{} +} + +func LoadDownloader(repoName string, repoVars map[string]string) ( + Downloader, error) { + + switch repoVars["type"] { + case "github": + gd := NewGithubDownloader() + + gd.User = repoVars["user"] + gd.Repo = repoVars["repo"] + + // The project.yml file can contain github access tokens and + // authentication credentials, but this file is probably world-readable + // and therefore not a great place for this. + gd.Token = repoVars["token"] + gd.Login = repoVars["login"] + gd.Password = repoVars["password"] + + // Alternatively, the user can put security material in + // $HOME/.newt/repos.yml. + newtrc := newtutil.Newtrc() + privRepo := newtrc.GetStringMapString("repository." + repoName) + if privRepo != nil { + if gd.Token == "" { + gd.Token = privRepo["token"] + } + if gd.Login == "" { + gd.Login = privRepo["login"] + } + if gd.Password == "" { + gd.Password = privRepo["password"] + } + } + return gd, nil + + case "local": + ld := NewLocalDownloader() + ld.Path = repoVars["path"] + return ld, nil + + default: + return nil, util.FmtNewtError("Invalid repository type: %s", + repoVars["type"]) + } +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/496fc332/newt/project/project.go ---------------------------------------------------------------------- diff --git a/newt/project/project.go b/newt/project/project.go index e9c38ad..e7fe60d 100644 --- a/newt/project/project.go +++ b/newt/project/project.go @@ -383,38 +383,13 @@ func (proj *Project) loadRepo(rname string, v *viper.Viper) error { return util.NewNewtError(fmt.Sprintf("Missing type for repository " + rname)) } - if repoVars["type"] != "github" { - return util.NewNewtError("Only github repositories are currently supported.") - } - rversreq := repoVars["vers"] - dl := downloader.NewGithubDownloader() - dl.User = repoVars["user"] - dl.Repo = repoVars["repo"] - - // The project.yml file can contain github access tokens and authentication - // credentials, but this file is probably world-readable and therefore not - // a great place for this. - dl.Token = repoVars["token"] - dl.Login = repoVars["login"] - dl.Password = repoVars["password"] - - // Alternatively, the user can put security material in - // $HOME/.newt/repos.yml. - newtrc := newtutil.Newtrc() - privRepo := newtrc.GetStringMapString("repository." + rname) - if privRepo != nil { - if dl.Token == "" { - dl.Token = privRepo["token"] - } - if dl.Login == "" { - dl.Login = privRepo["login"] - } - if dl.Password == "" { - dl.Password = privRepo["password"] - } + dl, err := downloader.LoadDownloader(rname, repoVars) + if err != nil { + return err } + rversreq := repoVars["vers"] r, err := repo.NewRepo(rname, rversreq, dl) if err != nil { return err http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/496fc332/newt/repo/repo.go ---------------------------------------------------------------------- diff --git a/newt/repo/repo.go b/newt/repo/repo.go index 369e4ba..159c66d 100644 --- a/newt/repo/repo.go +++ b/newt/repo/repo.go @@ -27,6 +27,7 @@ import ( "strings" log "github.com/Sirupsen/logrus" + "github.com/spf13/cast" "mynewt.apache.org/newt/newt/downloader" "mynewt.apache.org/newt/newt/interfaces" @@ -469,17 +470,14 @@ func (r *Repo) readDepRepos(v *viper.Viper) ([]*Repo, error) { repoList := v.GetStringMap(repoTag) for repoName, repoItf := range repoList { - repoVars := repoItf.(map[interface{}]interface{}) + repoVars := cast.ToStringMapString(repoItf) - if repoVars["type"] != "github" { - return nil, util.NewNewtError("Only github repositories are currently supported.") + dl, err := downloader.LoadDownloader(repoName, repoVars) + if err != nil { + return nil, err } - rversreq := repoVars["vers"].(string) - dl := downloader.NewGithubDownloader() - dl.User = repoVars["user"].(string) - dl.Repo = repoVars["repo"].(string) - + rversreq := repoVars["vers"] newRepo, err := NewRepo(repoName, rversreq, dl) if err != nil { return nil, err @@ -495,7 +493,6 @@ func (r *Repo) readDepRepos(v *viper.Viper) ([]*Repo, error) { repos = append(repos, newRepo) } - return repos, nil }