Source code for watch_do.banner_builder

"""The :class:`.BannerBuilder` class is responsible for creating the banners
that are displayed when using the command line interface to Watch Do.

Headers and footers are created in a format defined within this class that make
use of the metadata that is passed into the :meth:`build_header` and
:meth:`build_footer` methods.

As an example, the following code would return a header populated with the
required metadata.

>>> BannerBuilder.build_header(
...     {'file1', 'file2'}, ModificationTime)
"""

import time


[docs]class BannerBuilder: """This class creates the headers and footers (banners) containing metrics that are used predominantly by the command line interface. """ @staticmethod
[docs] def build_header(files, watch_method): """Build a header from the provided metadata. This interpolates the metadata provided by the parameters into a predefined string that can be used as information to display **before** a change has occurred. Parameters: files (set): A ``set`` containing the files that are currently being watched. watch_method (:class:`.Watcher`): A reference to the class that is being used to watch the files. Returns: str: A string containing the generated header. """ header = ('Watching {number_of_files} file{plural} for changes using ' 'the {watch_method} method...\n\n') return header.format( number_of_files=len(files), plural='' if len(files) == 1 else 's', watch_method=watch_method.__name__)
@staticmethod