Package: scottbrian-utils
IntroThis is a collection of generally useful functions for use with any application.The diag_msg function allows you to print a message with the time and caller sequence added for you.The FileCatalog item allows you to map file names to their paths.The @time_box decorator allows you to print start, stop, and execution times.The print_flower_box_msg function allows you to print text in a flower box (i.e., surrounded by asterisks).The log_verifier allows you to verify that expected log messages have been issued.The msgs item is a simple facility you can use to send messages between threads.The stop_watch item is a simple timing function that you can use in test cases.The timer item provides a way to keep track of time to determine when a function has timed out.The Pauser class provides a pause function similar to the python sleep function, but with improved accuracy.The UniqueTS class provides a way to obtain a unique timestamp.The doc_checker module provides an easy way to do doctest.Examples:Withdiag_msgyou can print messages with the time and caller info added automatically.Example:print a diagnostic message (<input> appears as the module name when run from the console)>>> from scottbrian_utils.diag_msg import diag_msg
>>> diag_msg('this is a diagnostic message')
16:20:05.909260 <input>:1 this is a diagnostic messageWithFileCatalog, you can code your application with file names and retrieve their paths at run time
from a catalog. This allows you to use different catalogs for the same set of files, such as one catalog for production
and another for testing. Here’s as example:>>> from scottbrian_utils.file_catalog import FileCatalog
>>> from pathlib import Path
>>> prod_cat = FileCatalog({'file1': Path('/prod_files/file1.csv')})
>>> print(prod_cat.get_path('file1'))
/prod_files/file1.csv>>> test_cat = FileCatalog({'file1': Path('/test_files/test_file1.csv')})
>>> print(test_cat.get_path('file1'))
/test_files/test_file1.csvWith@time_box, you can decorate a function to be sandwiched between start
time and end time messages like this:>>> from scottbrian_utils.time_hdr import time_box>>> @time_box
... def func2() -> None:
...      print('2 * 3 =', 2*3)>>> func2()
<BLANKLINE>
**********************************************
* Starting func2 on Mon Jun 29 2020 18:22:50 *
**********************************************
2 * 3 = 6
<BLANKLINE>
********************************************
* Ending func2 on Mon Jun 29 2020 18:22:51 *
* Elapsed time: 0:00:00.001204             *
********************************************WithPauser, you can pause execution for a specified number of seconds like this:fromscottbrian_utils.pauserimportPauserpauser=Pauser()pauser.pause(1.5)# pause for 1.5 secondsInstallationpip installscottbrian-utilsDevelopment setupSee tox.iniRelease History1.0.0Initial release1.0.1Added doc link to setup.pyAdded version number to __init__.pyAdded code in setup.py to get version number from __init__.pyAdded licence to setup.py classifiers1.1.0Added FileCatalog1.2.0Added diag_msg2.0.0changed get_formatted_call_sequence and diag_msg
(both in diag_msg.py) to get class name in additional
casesdropped support for python 3.6, 3.7, and 3.82.1.0added pausersupport for python 3.102.2.0added repr for LogVer2.3.0added is_specified method in Timeradded timeout_value in Timersupport for python 3.112.4.0added fullmatch parm to add_msg in log_ver.pyadded print_matched parm to print_match_results in log_ver.py3.0.0added unique_tsadded doc_checkersupport python 3.12drop support python < 3.12MetaScott TuttleDistributed under the MIT license. SeeLICENSEfor more information.ContributingFork it (<https://github.com/yourname/yourproject/fork>)Create your feature branch (git checkout -b feature/fooBar)Commit your changes (git commit -am ‘Add some fooBar’)Push to the branch (git push origin feature/fooBar)Create a new Pull Request