Merge ~brad-figg/+git/kteam-tools:cranky-checkout-no-color into ~canonical-kernel/+git/kteam-tools:master

Proposed by Brad Figg
Status: Needs review
Proposed branch: ~brad-figg/+git/kteam-tools:cranky-checkout-no-color
Merge into: ~canonical-kernel/+git/kteam-tools:master
Diff against target: 75 lines (+23/-5)
2 files modified
cranky/cmds.d/checkout (+11/-2)
ktl/log.py (+12/-3)
Reviewer Review Type Date Requested Status
Cory Todd (community) Approve
Francis Ginther (community) Approve
Brad Figg Pending
Review via email: mp+433809@code.launchpad.net

This proposal supersedes a proposal from 2022-11-24.

Description of the change

While working on some tools for cranking kernels, one of which is post-processing the output from cranky checkout I found that it would be nice to disable the colorization.

To post a comment you must log in.
Revision history for this message
Francis Ginther (fginther) wrote :

This is consistent with how ckct disables colorized logging and it works in that project.

review: Approve
Revision history for this message
Cory Todd (corytodd) wrote :

+1 Approve

I'll apply and push this today.

review: Approve
Revision history for this message
Jose Ogando Justo (joseogando) wrote :

Hello Brad,

This MP code has already been merged. The commit ID is 886892afeac3403511360a68a7a006ecde983ee3.

The status at the top of the page will show Needs Review until you either approve it or delete the MP.

Thanks!

Unmerged commits

4281efb... by Brad Figg

cranky/cmds.d/checkout: Add a command line option which allows the output colorization to be disabled. This is useful (disabling colorization) when the output is being post processed by another tool.

Signed-off-by: Brad Figg <email address hidden>

b6eda67... by Brad Figg

ktl/log.py: If Clog.color is set to False, none of the log output should be colored.

Signed-off-by: Brad Figg <email address hidden>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cranky/cmds.d/checkout b/cranky/cmds.d/checkout
2index 042daa1..716f746 100755
3--- a/cranky/cmds.d/checkout
4+++ b/cranky/cmds.d/checkout
5@@ -12,13 +12,15 @@ import datetime
6 from crl.git import GitHandleSet, GitError
7 from crl.config import Config
8 from crl.handle import HandleError
9-from ktl.log import cerror, cnotice
10+from ktl.log import cerror, cnotice, Clog
11
12
13-def checkout_repos(handle, reference=None, dissociate=False, depth=None, crd=None):
14+def checkout_repos(handle, reference=None, dissociate=False, depth=None, crd=None, nc=False):
15 """
16 Clone the repos that make up the set of kernel packages
17 """
18+ Clog.color = not nc
19+
20 # Cycle through the trees and clone/update the package specific
21 # repositories.
22 ghs = GitHandleSet(handle)
23@@ -162,6 +164,9 @@ otherwise the cranky checkout'd repo will get corrupted.
24 Borrow the objects from the referenced local repository only to reduce network
25 traffic. This is a git clone option, check 'git help clone' for more details.
26 """
27+ help_nc = '''No Colour. By default the debug output that is printed comes out in
28+multiple colours to help with the debugging. This option disables that.
29+'''
30
31 help_crd = """
32 Checks out branches as CRD-{DATE}+{BRANCH} and sets upstream to 'security'.
33@@ -186,6 +191,10 @@ Checks out branches as CRD-{DATE}+{BRANCH} and sets upstream to 'security'.
34 default=None,
35 type=datetime.date.fromisoformat,
36 help=help_crd)
37+ parser.add_argument('--nc',
38+ action='store_true',
39+ default=False,
40+ help=help_nc)
41
42 try:
43 checkout_repos(**vars(parser.parse_args()))
44diff --git a/ktl/log.py b/ktl/log.py
45index a3f3074..27c320c 100644
46--- a/ktl/log.py
47+++ b/ktl/log.py
48@@ -45,15 +45,24 @@ class Clog:
49
50 @classmethod
51 def debug(c, msg, color='magenta'):
52- debug(colored(msg, color))
53+ if c.color:
54+ debug(colored(msg, color))
55+ else:
56+ debug(msg)
57
58 @classmethod
59 def warn(c, msg, color='red'):
60- warning(colored(msg, color))
61+ if c.color:
62+ warning(colored(msg, color))
63+ else:
64+ warning(msg)
65
66 @classmethod
67 def notice(c, msg, color='yellow'):
68- c.info(colored(msg, color))
69+ if c.color:
70+ c.info(colored(msg, color))
71+ else:
72+ info(msg)
73
74 @classmethod
75 def enter(c, msg):

Subscribers

People subscribed via source and target branches