summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan S. Arnold <ryan.arnold@linaro.org>2016-11-21 16:00:58 -0600
committerRyan Arnold <ryan.arnold@linaro.org>2016-12-13 14:03:50 +0000
commit884672450622abc15eeaf15e9c257a1a0e2a7481 (patch)
tree75a13cfd5f8da1ed829cd57bcd28886bfb9e4655
parent560be160441e40ec3983b090deb31d2ebe439409 (diff)
Add linaropy/colors.py to provided color codes to terminal output.
Provide a print_info() function like what is used in tcwg-release.sh Printed information output now conforms to use print_info(). Change-Id: Idbfde7c0984a58bc7288ce6deb2a8f133167eda6
-rw-r--r--linaropy/colors.py13
-rw-r--r--linaropy/git/workdir.py4
-rw-r--r--linaropy/rn/rnseries.py28
-rw-r--r--linaropy/rninput.py6
-rw-r--r--rn.py44
5 files changed, 59 insertions, 36 deletions
diff --git a/linaropy/colors.py b/linaropy/colors.py
new file mode 100644
index 0000000..33d8d16
--- /dev/null
+++ b/linaropy/colors.py
@@ -0,0 +1,13 @@
+RED = "\033[31m"
+BLUE = "\033[34m"
+NC = "\033[0m"
+GREEN = "\033[32m"
+BOLD = "\033[1m"
+ITALIC = "\033[3m"
+
+def print_info(pstr):
+ """ This precedes pstr with two blue asterisks and a space. The input
+ string parameter, pstr, may also contain color codes from
+ linaropy/colors.py embedded in the string. This function always returns
+ the terminal to no-color text after printing pstr. """
+ print BLUE + "** " + NC + pstr + NC
diff --git a/linaropy/git/workdir.py b/linaropy/git/workdir.py
index f729a5a..8de4a81 100644
--- a/linaropy/git/workdir.py
+++ b/linaropy/git/workdir.py
@@ -60,13 +60,13 @@ class Workdir(GitRepo):
(workdir, track))
# TODO: Do we want to prevalidate that 'track' is a valid branch or tag?
# If we don't this will just throw an exception.
- print git_new_workdir(clone.clonedir(), workdir, track, _err_to_out=True, _out="/dev/null")
+ git_new_workdir(clone.clonedir(), workdir, track, _err_to_out=True, _out="/dev/null")
else:
logging.info(
"Workdir(): Calling git new-workdir for workdir %s, tracking %s" %
(workdir, "origin/HEAD"))
# Always just checkout HEAD if the track is not specified.
- print git_new_workdir(clone.clonedir(), workdir, "origin/HEAD", _err_to_out=True, _out="/dev/null")
+ git_new_workdir(clone.clonedir(), workdir, "origin/HEAD", _err_to_out=True, _out="/dev/null")
except ErrorReturnCode as exc:
# if 'workdir' is None
diff --git a/linaropy/rn/rnseries.py b/linaropy/rn/rnseries.py
index 6b69279..9b3063d 100644
--- a/linaropy/rn/rnseries.py
+++ b/linaropy/rn/rnseries.py
@@ -15,6 +15,7 @@ from linaroseries import linaroSeriesFromBranchname
from template import RNTemplate
from ..rninput import yninput
+from ..colors import *
# Abstract base class for a release-notes series
# Every RNSeries has a templateRN instance and a workdir. The template
@@ -139,13 +140,11 @@ class RNSeries(object):
remote_track = self.rn_clone.remote_branchname(
self.track_series.branchname())
if not self.rn_series:
- print("Looking for branch %s" % self.track_series.branchname())
+ logging.info("Looking for branch %s" % self.track_series.branchname())
# The workdir for the first candidate series will be derived from
# the changes made to the master branch templates. The workdir for
# subsequent candidates and releases will be made based on the
# existing candidate or release branch.
- # if not
- # self.rn_clone.branchexists(self.track_series.branchname()):
if not self.rn_clone.branchexists(remote_track):
logging.info(
"Creating RNSeries based on branch "
@@ -159,9 +158,8 @@ class RNSeries(object):
branchname=self.next_series.branchname())
else:
logging.info(
- "MARK Creating RNSeries based on branch "
+ "Creating RNSeries based on branch "
+ remote_track)
- # + self.track_series.branchname())
self.rn_series = Workdir(
proj=self.proj,
@@ -169,16 +167,16 @@ class RNSeries(object):
workdir=self.next_series.shorttype(),
track=remote_track,
branchname=self.next_series.branchname())
- # track=self.track_series.branchname(),
-
- logging.warning(
- "If you updated the template README.textile.series file"
- " the changes will not be reflected in this series"
- " README.textile.series as this series is derived from %s."
- " Please make the changes to the series"
- " README.textile.series file as well." %
- remote_track)
- # self.track_series.branchname())
+
+ print_info(
+ " If you updated the template README.textile.series file"
+ " the changes will not be reflected in this series")
+ print_info(
+ " README.textile.series as this series is derived from"
+ " the %s%s%s%s" % (BOLD, RED, remote_track, NC))
+ print_info(
+ " series release notes. Please make the changes to the"
+ " series README.textile.series file as well.")
# TODO: Ask if the user would like to merge the changes in
# the template README.textile.series file instead of the
diff --git a/linaropy/rninput.py b/linaropy/rninput.py
index d440a5b..6f4e346 100644
--- a/linaropy/rninput.py
+++ b/linaropy/rninput.py
@@ -1,6 +1,8 @@
# For fileIO
import os.path
+from colors import *
+
# @message - The question to display to the user.
# @default - The default if <enter> is hit.
# @accept - The list of valid responses.
@@ -19,7 +21,7 @@ def yninput(message, default="n", accept=['yes', 'y', 'no', 'n'], retry=True):
default_msg = " [Y/n]: "
while(1):
- answer = raw_input(message + default_msg) or default.lower()
+ answer = raw_input(BLUE + "** " + NC + BOLD + message + default_msg + NC) or default.lower()
if answer.lower() not in accept and retry:
print "'%s' is an invalid response. Please try again." % answer.lower()
continue
@@ -33,7 +35,7 @@ def yninput(message, default="n", accept=['yes', 'y', 'no', 'n'], retry=True):
def finput(message, orval):
while(1):
- answer = raw_input(message) or orval
+ answer = raw_input(BLUE + "** " + NC + BOLD + message + NC) or orval
if os.path.exists(answer) and os.path.isfile(answer):
return answer
diff --git a/rn.py b/rn.py
index 28a1573..6de8ad9 100644
--- a/rn.py
+++ b/rn.py
@@ -25,6 +25,9 @@ from linaropy.rn.rngen import rngen
from linaropy.rninput import yninput
from linaropy.rninput import finput
+# Terminal color codes.
+from linaropy.colors import *
+
from jinja2.exceptions import TemplateSyntaxError
import traceback
@@ -36,38 +39,43 @@ def rncleanup():
# This will be the case if the script is run via the test driver.
print "No cleanup needed"
else:
- print "Cleaning up Proj dir %s if possible." % rnProj[0].projdir
+ print_info("Cleaning up Proj dir %s if possible." % rnProj[0].projdir)
rnProj[0].cleanup()
def generate(track, to_date, to_series, gccsource, persist):
# Delay creating the Proj directory until now so that the parser (and
# parser validation functions) can be tested in the unittests without
# invoking the internals of this driver.
- rnProj.append(Proj(prefix='rn', persist=persist))
- print "proj dir is: %s with persist=%s" % (rnProj[0].projdir, str(persist))
+ rnProj.append(Proj(prefix='rn-', persist=persist))
+ if persist:
+ andpersist="(and persist) "
+
+ print_info(BOLD + "Release notes will be generated %sin:" % andpersist)
+ print_info(" %s" % rnProj[0].projdir)
# This will raise an exception if gccsource is not a git repository.
gccclone = GCCClone(rnProj[0], clonedir=gccsource)
# use gccsource to figure out the GCC Base Version and the FSF Version
# from the git commit history.
- print 'gccbaseversion is ' + gccclone.get_base_version()
- print 'fsf revision is ' + gccclone.get_fsf_revision()
+ logging.info("gccbaseversion is " + gccclone.get_base_version())
+ logging.info("fsf revision is " + gccclone.get_fsf_revision())
if gccclone.tag_exists(track):
logging.info("%s is a tag. Creating Series from tag.")
track_series = linaro_series_from_tag(track)
else:
- logging.info("%s is a branch? Creating Series from branchname.")
+ logging.info("%s is a branch. Creating Series from branchname.")
track_series = linaroSeriesFromBranchname(track)
try:
next_series = track_series.toNext(to_series)
except TypeError:
- print(
- "Next series '%s' from '%s' in an invalid progression"
+ logging.error( "Next series '%s' from '%s' in an invalid progression"
% (LinaroSeries.series[to_series], track_series.shorttype()))
- print("If this is a release series try tracking the release-candidate tag instead of the release branch.")
+ logging.error(
+ "If this is a release series try tracking the release-candidate"
+ " tag instead of the release branch.")
sys.exit(2)
if to_date != next_series.date:
@@ -85,7 +93,9 @@ def generate(track, to_date, to_series, gccsource, persist):
next_series=next_series)
if next_rn.update_templ_readmes():
- print "Please verify that your changes have been committed on the template branch:"
+ print_info(
+ "Please verify that your changes have been committed on the"
+ " template branch:")
next_rn.rn_template.log(1)
ans = True
@@ -101,15 +111,15 @@ def generate(track, to_date, to_series, gccsource, persist):
rngen(next_rn, gccclone, history)
except TemplateSyntaxError:
traceback.print_exc(file=sys.stdout)
- print "Please correct the template and try again."
+ print_info("Please correct the template and try again.")
- print "Please direct your browser to the rendered .html files in"
- print "%s and make sure that they look correct." % rnProj[0].projdir
+ print_info(
+ "Please direct your browser to the rendered .html files in"
+ " %s%s%s%s and make sure that they look correct."
+ % (BOLD, RED, rnProj[0].projdir, NC))
ans = next_rn.update_series_readmes()
# Verify that the GCC Source is located where it says it is.
-
-
class VerifyGCCSourceAction(argparse.Action):
def __init__(self, option_strings, dest, nargs=None, **kwargs):
@@ -119,9 +129,9 @@ class VerifyGCCSourceAction(argparse.Action):
option_strings, dest, **kwargs)
def __call__(self, parser, namespace, values, option_string=None):
- print('%r %r %r' % (namespace, values, option_string))
+ logging.info("%r %r %r" % (namespace, values, option_string))
setattr(namespace, self.dest, values)
- print "gccsource: " + values
+ logging.info("gccsource: " + values)
# We simply want to test that the directory exists. We'll prove that
# it is a git directory in a later step.
if not os.path.isdir(values):