Files
lvgl/docs/announce.py
T
Victor Wheeler 69052cd2ea
Arduino Lint / lint (push) Waiting to run
MicroPython CI / Build esp32 port (push) Waiting to run
MicroPython CI / Build rp2 port (push) Waiting to run
MicroPython CI / Build stm32 port (push) Waiting to run
MicroPython CI / Build unix port (push) Waiting to run
C/C++ CI / Build OPTIONS_16BIT - Ubuntu (push) Waiting to run
C/C++ CI / Build OPTIONS_24BIT - Ubuntu (push) Waiting to run
C/C++ CI / Build OPTIONS_FULL_32BIT - Ubuntu (push) Waiting to run
C/C++ CI / Build OPTIONS_NORMAL_8BIT - Ubuntu (push) Waiting to run
C/C++ CI / Build OPTIONS_SDL - Ubuntu (push) Waiting to run
C/C++ CI / Build OPTIONS_VG_LITE - Ubuntu (push) Waiting to run
C/C++ CI / Build OPTIONS_16BIT - cl - Windows (push) Waiting to run
C/C++ CI / Build OPTIONS_16BIT - gcc - Windows (push) Waiting to run
C/C++ CI / Build OPTIONS_24BIT - cl - Windows (push) Waiting to run
C/C++ CI / Build OPTIONS_24BIT - gcc - Windows (push) Waiting to run
C/C++ CI / Build OPTIONS_FULL_32BIT - cl - Windows (push) Waiting to run
C/C++ CI / Build OPTIONS_FULL_32BIT - gcc - Windows (push) Waiting to run
C/C++ CI / Build OPTIONS_VG_LITE - cl - Windows (push) Waiting to run
C/C++ CI / Build OPTIONS_VG_LITE - gcc - Windows (push) Waiting to run
C/C++ CI / Build ESP IDF ESP32S3 (push) Waiting to run
C/C++ CI / Run tests with 32bit build (push) Waiting to run
C/C++ CI / Run tests with 64bit build (push) Waiting to run
BOM Check / bom-check (push) Waiting to run
Verify that lv_conf_internal.h matches repository state / verify-conf-internal (push) Waiting to run
Verify the widget property name / verify-property-name (push) Waiting to run
Verify code formatting / verify-formatting (push) Waiting to run
Build docs / build-and-deploy (push) Waiting to run
Test API JSON generator / Test API JSON (push) Waiting to run
Check Makefile / Build using Makefile (push) Waiting to run
Check Makefile for UEFI / Build using Makefile for UEFI (push) Waiting to run
Port repo release update / run-release-branch-updater (push) Waiting to run
Verify Kconfig / verify-kconfig (push) Waiting to run
docs(doc_builder.py): overhaul, remove bugs, clean up, modularize (#7913)
2025-03-20 13:54:45 +01:00

81 lines
2.3 KiB
Python

"""announce.py
Manage logging announcements to `stdout`
It is the designer's intention that:
1. The variable `__file__` be passed as the first argument in
`announce()` and `announce_start()`.
(Unfortunately, there is no way this author knows of yet to
have this module know what Python module is importing it. So
this is a hold-over requirement until that need is fulfilled.)
2. `announce_start()` and `announce_finish()` should be used
in pairs like this:
announce_start(__file__, 'something is running...')
# do something that takes a while here
announce_finish()
3. If this is used in a module that sometimes has a need to
not have anything output to STDOUT, when that is known,
call `announce_set_silent_mode()`. To turn "silent mode"
off, call `announce_set_silent_mode(False)`.
"""
import os
import datetime
__all__ = ('announce', 'announce_start', 'announce_finish', 'announce_set_silent_mode')
_announce_start_time: datetime.datetime
_announce_silent_mode: bool = False
def _announce(file: str, args: tuple, start=False):
if _announce_silent_mode:
return
_args = []
for arg in args:
# Avoid the single quotes `repr()` puts around strings.
if type(arg) is str:
_args.append(arg)
else:
_args.append(repr(arg))
if start:
_end = ''
else:
_end = '\n'
print(f'{os.path.basename(file)}: ', ' '.join(_args), end=_end, flush=True)
def announce(file: str, *args, start=False, finish=False):
global _announce_start_time
_announce_start_time = None
_announce(file, args)
def announce_start(file: str, *args, start=False, finish=False):
global _announce_start_time
_announce_start_time = datetime.datetime.now()
_announce(file, args, start=True)
def announce_finish():
# Just output line ending to terminate output for `announce_start()`.
global _announce_start_time
if _announce_start_time is not None:
if not _announce_silent_mode:
print(' Elapsed: ', datetime.datetime.now() - _announce_start_time, flush=True)
_announce_start_time = None
else:
if not _announce_silent_mode:
print(flush=True)
def announce_set_silent_mode(mode=True):
global _announce_silent_mode
_announce_silent_mode = mode