smartinspectpython.sifilehelper

@export
class SIFileHelper:

Responsible for the log file rotate management as used by the SIFileProtocol class.

This class implements a flexible log file rotate management system. For a detailed description of how to use this class, please refer to the documentation of the Initialize(DateTime) and Update(DateTime) methods and the Mode property.

Threadsafety:

This class is not guaranteed to be thread-safe.

ALREADY_EXISTS_SUFFIX: str = 'a'
DATETIME_FORMAT: str = 'yyyy-MM-dd-HH-mm-ss'
DATETIME_FORMAT_LEN: int = 19
DATETIME_SEPARATOR: <built-in function chr> = '-'
DATETIME_TOKENS: int = 6
@staticmethod
def DeleteFiles(baseName: str, maxParts: int) -> None:

Deletes existing log files that fall outside the maximum retention range.

Arguments:
  • baseName (str): Base name path of a log file (e.g. "C:\logfile-hourly.txt").
  • maxParts (int): Maximum number of files to keep for the base name path.
@staticmethod
def GetFileDate(baseName: str, path: str) -> datetime.datetime:

Returns a datetime object of the timestamp portion of the filename path argument.

Arguments:
  • baseName (str): Base name path of a log file (e.g. "C:\logfile-hourly.txt").
  • path (str): Full name of a log file, which is comprised of the base name path and a timestamp before the extension (e.g. "C:\logfile-hourly-2023-05-22-00-49-55.txt").
Returns:

A datetime object of the timestamp portion of the path argument filename.

Raises:
  • SmartInspectException: Thrown if the datetime object could not be created from the timestamp portion of the path argument filename.
@staticmethod
def GetFileName(baseName: str, append: bool) -> str:

Returns a log file path.

Arguments:
  • baseName (str): Base name path of a log file (e.g. "C:\logfile-hourly.txt").
  • append (bool): True to append to the existing latest log file; otherwise, False to create a new log file path from the specified base name path.
Returns:

A log file path that includes the base name path along with a timestamp value (e.g. "C:\logfile-hourly-2023-05-22-12-00-00.txt").

If no rotating log file was found, or we are not appending to an existing file, then a new log file will be created.