Skip to content

Commit 3bd691a

Browse files
committed
Move terminal notifier to it's own file
1 parent 72beee7 commit 3bd691a

File tree

4 files changed

+91
-74
lines changed

4 files changed

+91
-74
lines changed

tools/make.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
from tools.options import get_default_options_parser
4646
from tools.options import extract_profile
4747
from tools.options import extract_mcus
48-
from tools.notifier import TerminalNotifier
48+
from tools.notifier.term import TerminalNotifier
4949
from tools.build_api import build_project
5050
from tools.build_api import mcu_toolchain_matrix
5151
from tools.build_api import mcu_toolchain_list

tools/notifier/__init__.py

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
from __future__ import print_function, division, absolute_import
1717

1818
from abc import ABCMeta, abstractmethod
19-
from os.path import basename
20-
21-
from ..settings import PRINT_COMPILER_OUTPUT_AS_LINK
2219

2320

2421
class Notifier(object):
@@ -103,72 +100,3 @@ def var(self, key, value):
103100
Update a UI with a key, value pair
104101
"""
105102
self.notify({'type': 'var', 'key': key, 'val': value})
106-
107-
108-
class TerminalNotifier(Notifier):
109-
"""
110-
Writes notifications to a terminal based on a silent and verbose flag.
111-
"""
112-
113-
def __init__(self, verbose=False, silent=False):
114-
self.verbose = verbose
115-
self.silent = silent
116-
self.output = ""
117-
118-
def get_output(self):
119-
return self.output
120-
121-
def notify(self, event):
122-
if self.verbose:
123-
msg = self.print_notify_verbose(event)
124-
else:
125-
msg = self.print_notify(event)
126-
if msg:
127-
if not self.silent:
128-
print(msg)
129-
self.output += msg + "\n"
130-
131-
def print_notify(self, event):
132-
""" Default command line notification
133-
"""
134-
if not self.verbose and event['type'] == 'tool_error':
135-
return event['message']
136-
137-
elif event['type'] in ['info']:
138-
return event['message']
139-
140-
elif event['type'] == 'cc':
141-
event['severity'] = event['severity'].title()
142-
143-
if PRINT_COMPILER_OUTPUT_AS_LINK:
144-
event['file'] = getcwd() + event['file'].strip('.')
145-
return '[%(severity)s] %(file)s:%(line)s:%(col)s: %(message)s' % event
146-
else:
147-
event['file'] = basename(event['file'])
148-
return '[%(severity)s] %(file)s@%(line)s,%(col)s: %(message)s' % event
149-
150-
elif event['type'] == 'progress':
151-
if 'percent' in event:
152-
return '{} [{:>5.1f}%]: {}'.format(event['action'].title(),
153-
event['percent'],
154-
basename(event['file']))
155-
else:
156-
return '{}: {}'.format(event['action'].title(),
157-
basename(event['file']))
158-
159-
def print_notify_verbose(self, event):
160-
""" Default command line notification with more verbose mode
161-
"""
162-
if event['type'] in ['info', 'debug']:
163-
return event['message']
164-
165-
elif event['type'] == 'cc':
166-
event['severity'] = event['severity'].title()
167-
event['file'] = basename(event['file'])
168-
event['mcu_name'] = "None"
169-
event['target_name'] = event['target_name'].upper() if event['target_name'] else "Unknown"
170-
event['toolchain_name'] = event['toolchain_name'].upper() if event['toolchain_name'] else "Unknown"
171-
return '[%(severity)s] %(target_name)s::%(toolchain_name)s::%(file)s@%(line)s: %(message)s' % event
172-
173-
elif event['type'] == 'progress':
174-
return self.print_notify(event) # standard handle

tools/notifier/term.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# mbed SDK
2+
# Copyright (c) 2011-2013 ARM Limited
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
from __future__ import print_function, division, absolute_import
17+
18+
from os.path import basename
19+
20+
from . import Notifier
21+
from ..settings import PRINT_COMPILER_OUTPUT_AS_LINK
22+
23+
class TerminalNotifier(Notifier):
24+
"""
25+
Writes notifications to a terminal based on a silent and verbose flag.
26+
"""
27+
28+
def __init__(self, verbose=False, silent=False):
29+
self.verbose = verbose
30+
self.silent = silent
31+
self.output = ""
32+
33+
def get_output(self):
34+
return self.output
35+
36+
def notify(self, event):
37+
if self.verbose:
38+
msg = self.print_notify_verbose(event)
39+
else:
40+
msg = self.print_notify(event)
41+
if msg:
42+
if not self.silent:
43+
print(msg)
44+
self.output += msg + "\n"
45+
46+
def print_notify(self, event):
47+
""" Default command line notification
48+
"""
49+
if not self.verbose and event['type'] == 'tool_error':
50+
return event['message']
51+
52+
elif event['type'] in ['info']:
53+
return event['message']
54+
55+
elif event['type'] == 'cc':
56+
event['severity'] = event['severity'].title()
57+
58+
if PRINT_COMPILER_OUTPUT_AS_LINK:
59+
event['file'] = getcwd() + event['file'].strip('.')
60+
return '[%(severity)s] %(file)s:%(line)s:%(col)s: %(message)s' % event
61+
else:
62+
event['file'] = basename(event['file'])
63+
return '[%(severity)s] %(file)s@%(line)s,%(col)s: %(message)s' % event
64+
65+
elif event['type'] == 'progress':
66+
if 'percent' in event:
67+
return '{} [{:>5.1f}%]: {}'.format(event['action'].title(),
68+
event['percent'],
69+
basename(event['file']))
70+
else:
71+
return '{}: {}'.format(event['action'].title(),
72+
basename(event['file']))
73+
74+
def print_notify_verbose(self, event):
75+
""" Default command line notification with more verbose mode
76+
"""
77+
if event['type'] in ['info', 'debug']:
78+
return event['message']
79+
80+
elif event['type'] == 'cc':
81+
event['severity'] = event['severity'].title()
82+
event['file'] = basename(event['file'])
83+
event['mcu_name'] = "None"
84+
event['target_name'] = event['target_name'].upper() if event['target_name'] else "Unknown"
85+
event['toolchain_name'] = event['toolchain_name'].upper() if event['toolchain_name'] else "Unknown"
86+
return '[%(severity)s] %(target_name)s::%(toolchain_name)s::%(file)s@%(line)s: %(message)s' % event
87+
88+
elif event['type'] == 'progress':
89+
return self.print_notify(event) # standard handle

tools/toolchains/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
NotSupportedException, split_path, compile_worker)
3838
from ..settings import MBED_ORG_USER, PRINT_COMPILER_OUTPUT_AS_LINK
3939
from .. import hooks
40-
from ..notifier import TerminalNotifier
40+
from ..notifier.term import TerminalNotifier
4141
from ..memap import MemapParser
4242

4343

0 commit comments

Comments
 (0)