You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by st...@apache.org on 2016/03/09 17:55:30 UTC

incubator-mynewt-newt git commit: flush status messages to console, ensuring they get displayed quickly. cleanup install & upgrade state logic, this was a beast.

Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/rename_project_app 1affb86f0 -> 0442a0df7


flush status messages to console, ensuring they get displayed quickly.  cleanup install & upgrade state logic, this was a beast.


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/0442a0df
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/0442a0df
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/0442a0df

Branch: refs/heads/rename_project_app
Commit: 0442a0df7c8c79691e7afac1991938fed534670d
Parents: 1affb86
Author: Sterling Hughes <st...@apache.org>
Authored: Wed Mar 9 08:54:55 2016 -0800
Committer: Sterling Hughes <st...@apache.org>
Committed: Wed Mar 9 08:55:15 2016 -0800

----------------------------------------------------------------------
 newt/project/project.go | 119 +++++++++++++++++++------------------------
 util/util.go            |   6 ++-
 2 files changed, 56 insertions(+), 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/0442a0df/newt/project/project.go
----------------------------------------------------------------------
diff --git a/newt/project/project.go b/newt/project/project.go
index e5f21e6..7292c7b 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -139,79 +139,56 @@ func (proj *Project) PackageSearchDirs() []string {
 }
 
 func (proj *Project) upgradeCheck(r *repo.Repo, vers *repo.Version,
-	upgrade bool, force bool) (bool, error) {
+	force bool) (bool, error) {
 	rdesc, err := r.GetRepoDesc()
 	if err != nil {
 		return false, err
 	}
 
-	if !upgrade {
+	branch, newVers, _ := rdesc.Match(r)
+	if newVers == nil {
 		util.StatusMessage(util.VERBOSITY_DEFAULT,
-			fmt.Sprintf("Installed repository %s has version %s, "+
-				"which meets project requirements. Moving on to next repository.\n",
-				r.Name(), vers))
-		return true, nil
-	} else {
-		_, newVers, _ := rdesc.Match(r)
-		if newVers == nil {
-			util.StatusMessage(util.VERBOSITY_DEFAULT,
-				"No matching version to upgrade to "+
-					"found for %s.  Please check your project requirements, and use the "+
-					"project show-repo command to see available repository versions.",
-				r.Name())
-			return false, util.NewNewtError(fmt.Sprintf("Cannot find a "+
-				"version of repository %s that matches project requirements.",
-				r.Name()))
-		}
+			"No matching version to upgrade to "+
+				"found for %s.  Please check your project requirements, and use the "+
+				"project show-repo command to see available repository versions.",
+			r.Name())
+		return false, util.NewNewtError(fmt.Sprintf("Cannot find a "+
+			"version of repository %s that matches project requirements.",
+			r.Name()))
+	}
 
-		// If the change between the old repository and the new repository would cause
-		// and upgrade.  Then prompt for an upgrade response, unless the force option
-		// is present.
-		if vers.CompareVersions(newVers, vers) != 0 ||
-			vers.Stability() != newVers.Stability() {
-			if !force {
-				branch, newVers, _ := rdesc.Match(r)
-
-				str := ""
-				if newVers.Stability() != repo.VERSION_STABILITY_NONE {
-					str += "(" + branch + ")"
-				}
-
-				fmt.Printf("Would you like to upgrade repository %s from %s to %s %s? [Yn] ",
-					r.Name(), vers.String(), newVers.String(), str)
-
-				if !upgrade {
-					util.StatusMessage(util.VERBOSITY_DEFAULT,
-						fmt.Sprintf("Installed repository %s matches project requirements, "+
-							"moving on to next repository.\n", r.Name()))
-					return true, nil
-				} else {
-					_, newVers, _ := rdesc.Match(r)
-					if newVers == nil {
-						return true, util.NewNewtError(fmt.Sprintf(
-							"No matching version for repository %s\n", r.Name()))
-					}
-					line, more, err := bufio.NewReader(os.Stdin).ReadLine()
-					if more || err != nil {
-						return false, util.NewNewtError(fmt.Sprintf(
-							"Couldn't read upgrade response: %s\n", err.Error()))
-					}
-
-					// Anything but no means yes.
-					answer := strings.ToUpper(strings.Trim(string(line), " "))
-					if answer == "N" || answer == "NO" {
-						fmt.Printf("Users says don't upgrade, skipping upgrade of %s\n",
-							r.Name())
-						return true, nil
-					}
-				}
+	// If the change between the old repository and the new repository would cause
+	// and upgrade.  Then prompt for an upgrade response, unless the force option
+	// is present.
+	if vers.CompareVersions(newVers, vers) != 0 ||
+		vers.Stability() != newVers.Stability() {
+		if !force {
+			str := ""
+			if newVers.Stability() != repo.VERSION_STABILITY_NONE {
+				str += "(" + branch + ")"
+			}
+
+			fmt.Printf("Would you like to upgrade repository %s from %s to %s %s? [Yn] ",
+				r.Name(), vers.String(), newVers.String(), str)
+			line, more, err := bufio.NewReader(os.Stdin).ReadLine()
+			if more || err != nil {
+				return false, util.NewNewtError(fmt.Sprintf(
+					"Couldn't read upgrade response: %s\n", err.Error()))
+			}
+
+			// Anything but no means yes.
+			answer := strings.ToUpper(strings.Trim(string(line), " "))
+			if answer == "N" || answer == "NO" {
+				fmt.Printf("Users says don't upgrade, skipping upgrade of %s\n",
+					r.Name())
+				return true, nil
 			}
-		} else {
-			util.StatusMessage(util.VERBOSITY_DEFAULT,
-				"Repository %s doesn't need to be upgraded, latest "+
-					"version installed.\n", r.Name())
-			return true, nil
 		}
+	} else {
+		util.StatusMessage(util.VERBOSITY_DEFAULT,
+			"Repository %s doesn't need to be upgraded, latest "+
+				"version installed.\n", r.Name())
+		return true, nil
 	}
 
 	return false, nil
@@ -229,15 +206,23 @@ func (proj *Project) checkVersionRequirements(r *repo.Repo, upgrade bool, force
 	if vers != nil {
 		ok := rdesc.SatisfiesVersion(vers, r.VersionRequirements())
 		if !ok && !upgrade {
-			util.StatusMessage(util.VERBOSITY_DEFAULT, "WARNING: Installed"+
+			util.StatusMessage(util.VERBOSITY_DEFAULT, "WARNING: Installed "+
 				"version %s of repository %s does not match desired "+
 				"version %s in project file.  You can fix this by either upgrading"+
 				" your repository, or modifying the project.yml file.\n",
 				vers, rname, r.VersionRequirementsString())
 			return true, err
 		} else {
-			skip, err := proj.upgradeCheck(r, vers, upgrade, force)
-			return skip, err
+			if !upgrade {
+				util.StatusMessage(util.VERBOSITY_DEFAULT,
+					fmt.Sprintf("Installed repository %s has version %s, "+
+						"which meets project requirements. Moving on to next repository.\n",
+						r.Name(), vers))
+				return true, nil
+			} else {
+				skip, err := proj.upgradeCheck(r, vers, force)
+				return skip, err
+			}
 		}
 	} else {
 		// Fallthrough and perform the installation.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/0442a0df/util/util.go
----------------------------------------------------------------------
diff --git a/util/util.go b/util/util.go
index dc439ac..cd37c44 100644
--- a/util/util.go
+++ b/util/util.go
@@ -22,10 +22,8 @@ package util
 import (
 	"bufio"
 	"fmt"
-	"github.com/hashicorp/logutils"
 	"io/ioutil"
 	"log"
-	"mynewt.apache.org/newt/viper"
 	"os"
 	"os/exec"
 	"os/signal"
@@ -36,6 +34,9 @@ import (
 	"strings"
 	"syscall"
 	"time"
+
+	"github.com/hashicorp/logutils"
+	"mynewt.apache.org/newt/viper"
 )
 
 var Logger *log.Logger
@@ -79,6 +80,7 @@ func StatusMessage(level int, message string, args ...interface{}) {
 	if Verbosity >= level {
 		fmt.Printf(message, args...)
 	}
+	os.Stdout.Sync()
 }
 
 // Print Silent, Quiet and Verbose aware status messages to stderr.