takashi kadono
/
Nucleo_446
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/tools/notifier/__init__.py@3:f3764f852aa8, 2018-10-11 (annotated)
- Committer:
- kadonotakashi
- Date:
- Thu Oct 11 02:27:46 2018 +0000
- Revision:
- 3:f3764f852aa8
- Parent:
- 0:8fdf9a60065b
Nucreo 446 + SSD1331 test version;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | # mbed SDK |
kadonotakashi | 0:8fdf9a60065b | 2 | # Copyright (c) 2011-2013 ARM Limited |
kadonotakashi | 0:8fdf9a60065b | 3 | # |
kadonotakashi | 0:8fdf9a60065b | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
kadonotakashi | 0:8fdf9a60065b | 5 | # you may not use this file except in compliance with the License. |
kadonotakashi | 0:8fdf9a60065b | 6 | # You may obtain a copy of the License at |
kadonotakashi | 0:8fdf9a60065b | 7 | # |
kadonotakashi | 0:8fdf9a60065b | 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
kadonotakashi | 0:8fdf9a60065b | 9 | # |
kadonotakashi | 0:8fdf9a60065b | 10 | # Unless required by applicable law or agreed to in writing, software |
kadonotakashi | 0:8fdf9a60065b | 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
kadonotakashi | 0:8fdf9a60065b | 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kadonotakashi | 0:8fdf9a60065b | 13 | # See the License for the specific language governing permissions and |
kadonotakashi | 0:8fdf9a60065b | 14 | # limitations under the License. |
kadonotakashi | 0:8fdf9a60065b | 15 | |
kadonotakashi | 0:8fdf9a60065b | 16 | from __future__ import print_function, division, absolute_import |
kadonotakashi | 0:8fdf9a60065b | 17 | |
kadonotakashi | 0:8fdf9a60065b | 18 | from abc import ABCMeta, abstractmethod |
kadonotakashi | 0:8fdf9a60065b | 19 | |
kadonotakashi | 0:8fdf9a60065b | 20 | |
kadonotakashi | 0:8fdf9a60065b | 21 | class Notifier(object): |
kadonotakashi | 0:8fdf9a60065b | 22 | """ |
kadonotakashi | 0:8fdf9a60065b | 23 | Notifiers send build system events to a front end or may implement a front |
kadonotakashi | 0:8fdf9a60065b | 24 | end themselves, displaying warnings and errors for a user. |
kadonotakashi | 0:8fdf9a60065b | 25 | |
kadonotakashi | 0:8fdf9a60065b | 26 | This is different from a logger in a few ways: |
kadonotakashi | 0:8fdf9a60065b | 27 | * The structure of the events are defined by this interface. |
kadonotakashi | 0:8fdf9a60065b | 28 | * A "progress" level is included allowing signaling completion status to |
kadonotakashi | 0:8fdf9a60065b | 29 | users. |
kadonotakashi | 0:8fdf9a60065b | 30 | * It's tailored to providing events from a build system. |
kadonotakashi | 0:8fdf9a60065b | 31 | |
kadonotakashi | 0:8fdf9a60065b | 32 | The structure of a message is a dict with a 'type' key. The type key |
kadonotakashi | 0:8fdf9a60065b | 33 | determines the remaining keys as follows: |
kadonotakashi | 0:8fdf9a60065b | 34 | type | description and remaining keys |
kadonotakashi | 0:8fdf9a60065b | 35 | ---------- | ------------------------------ |
kadonotakashi | 0:8fdf9a60065b | 36 | info | A simple message. The 'message' key contains the message |
kadonotakashi | 0:8fdf9a60065b | 37 | debug | Another simple message; this one is less useful when compiles |
kadonotakashi | 0:8fdf9a60065b | 38 | | are working. Again, the 'message' key contains the message |
kadonotakashi | 0:8fdf9a60065b | 39 | progress | A progress indicator, which may include progress as a |
kadonotakashi | 0:8fdf9a60065b | 40 | | percentage. The action key includes what action was taken to |
kadonotakashi | 0:8fdf9a60065b | 41 | | make this progress, the file key what file was used to make |
kadonotakashi | 0:8fdf9a60065b | 42 | | this progress, and the percent key, when present, indicates |
kadonotakashi | 0:8fdf9a60065b | 43 | | how far along the build is. |
kadonotakashi | 0:8fdf9a60065b | 44 | tool_error | When a compile fails, this contains the entire output of the |
kadonotakashi | 0:8fdf9a60065b | 45 | | compiler. |
kadonotakashi | 0:8fdf9a60065b | 46 | var | Provides a key, in the 'key' key, and a value, in the 'value' |
kadonotakashi | 0:8fdf9a60065b | 47 | | key, for use in a UI. At the time of writing it's used to |
kadonotakashi | 0:8fdf9a60065b | 48 | | communicate the binary location to the online IDE. |
kadonotakashi | 0:8fdf9a60065b | 49 | """ |
kadonotakashi | 0:8fdf9a60065b | 50 | |
kadonotakashi | 0:8fdf9a60065b | 51 | __metaclass__ = ABCMeta |
kadonotakashi | 0:8fdf9a60065b | 52 | |
kadonotakashi | 0:8fdf9a60065b | 53 | @abstractmethod |
kadonotakashi | 0:8fdf9a60065b | 54 | def notify(self, event): |
kadonotakashi | 0:8fdf9a60065b | 55 | """ |
kadonotakashi | 0:8fdf9a60065b | 56 | Send the user a notification specified in the event. |
kadonotakashi | 0:8fdf9a60065b | 57 | """ |
kadonotakashi | 0:8fdf9a60065b | 58 | raise NotImplemented |
kadonotakashi | 0:8fdf9a60065b | 59 | |
kadonotakashi | 0:8fdf9a60065b | 60 | def info(self, message): |
kadonotakashi | 0:8fdf9a60065b | 61 | """ |
kadonotakashi | 0:8fdf9a60065b | 62 | Send the user a simple message. |
kadonotakashi | 0:8fdf9a60065b | 63 | """ |
kadonotakashi | 0:8fdf9a60065b | 64 | self.notify({'type': 'info', 'message': message}) |
kadonotakashi | 0:8fdf9a60065b | 65 | |
kadonotakashi | 0:8fdf9a60065b | 66 | def debug(self, message): |
kadonotakashi | 0:8fdf9a60065b | 67 | """ |
kadonotakashi | 0:8fdf9a60065b | 68 | Send a debug message to the user. |
kadonotakashi | 0:8fdf9a60065b | 69 | """ |
kadonotakashi | 0:8fdf9a60065b | 70 | if isinstance(message, list): |
kadonotakashi | 0:8fdf9a60065b | 71 | message = ' '.join(message) |
kadonotakashi | 0:8fdf9a60065b | 72 | self.notify({'type': 'debug', 'message': message}) |
kadonotakashi | 0:8fdf9a60065b | 73 | |
kadonotakashi | 0:8fdf9a60065b | 74 | def cc_info(self, info=None): |
kadonotakashi | 0:8fdf9a60065b | 75 | if info is not None: |
kadonotakashi | 0:8fdf9a60065b | 76 | info['type'] = 'cc' |
kadonotakashi | 0:8fdf9a60065b | 77 | self.notify(info) |
kadonotakashi | 0:8fdf9a60065b | 78 | |
kadonotakashi | 0:8fdf9a60065b | 79 | def cc_verbose(self, message, file=""): |
kadonotakashi | 0:8fdf9a60065b | 80 | self.notify({ |
kadonotakashi | 0:8fdf9a60065b | 81 | 'type': 'cc', |
kadonotakashi | 0:8fdf9a60065b | 82 | 'severity': 'verbose', |
kadonotakashi | 0:8fdf9a60065b | 83 | 'file': file, |
kadonotakashi | 0:8fdf9a60065b | 84 | 'message': message |
kadonotakashi | 0:8fdf9a60065b | 85 | }) |
kadonotakashi | 0:8fdf9a60065b | 86 | |
kadonotakashi | 0:8fdf9a60065b | 87 | def progress(self, action, file, percent=None): |
kadonotakashi | 0:8fdf9a60065b | 88 | """ |
kadonotakashi | 0:8fdf9a60065b | 89 | Indicate compilation progress to a user. |
kadonotakashi | 0:8fdf9a60065b | 90 | """ |
kadonotakashi | 0:8fdf9a60065b | 91 | msg = {'type': 'progress', 'action': action, 'file': file} |
kadonotakashi | 0:8fdf9a60065b | 92 | if percent: |
kadonotakashi | 0:8fdf9a60065b | 93 | msg['percent'] = percent |
kadonotakashi | 0:8fdf9a60065b | 94 | self.notify(msg) |
kadonotakashi | 0:8fdf9a60065b | 95 | |
kadonotakashi | 0:8fdf9a60065b | 96 | def tool_error(self, message): |
kadonotakashi | 0:8fdf9a60065b | 97 | """ |
kadonotakashi | 0:8fdf9a60065b | 98 | Communicate a full fatal error to a user. |
kadonotakashi | 0:8fdf9a60065b | 99 | """ |
kadonotakashi | 0:8fdf9a60065b | 100 | self.notify({'type': 'tool_error', 'message': message}) |
kadonotakashi | 0:8fdf9a60065b | 101 | |
kadonotakashi | 0:8fdf9a60065b | 102 | def var(self, key, value): |
kadonotakashi | 0:8fdf9a60065b | 103 | """ |
kadonotakashi | 0:8fdf9a60065b | 104 | Update a UI with a key, value pair |
kadonotakashi | 0:8fdf9a60065b | 105 | """ |
kadonotakashi | 0:8fdf9a60065b | 106 | self.notify({'type': 'var', 'key': key, 'val': value}) |