Sample Code Revit Batch Processor 1.1.11 documentation

Contents:

This Page

duHast.Utilities.Objects package

Submodules

duHast.Utilities.Objects.base module

Base class for objects.

This class provides some utility functions to all child classes:

  • __repr__() a way of providing detailed debug output through print

  • to_json() A json formatted dump of the class

class duHast.Utilities.Objects.base.Base(**kwargs)

Bases: object

Class constructor

default_format()

Provides a formatted output of all class properties and their values without indentation.

Returns:

A string representing all class properties and their values

Return type:

str

formatted_indented_str(indent=0, indent_character=' ')

formatted output including indentation

Parameters:
  • indent (int, optional) – The level of indentation, defaults to 0

  • indent_character (str) – the indentation character used, defaults to “ “

Returns:

A string representing all class properties and their values

Return type:

str

to_json()

Convert the instance of this class to JSON, including public attributes and properties.

Returns:

A JSON object.

Return type:

str

string_to_utf(o)

Used to convert any properties stored as string to utf-8 in to json conversion of all class properties…

Parameters:

o (_type_) – _description_

Returns:

_description_

Return type:

_type_

to_json_utf()

Convert the instance of this class to json, any string properties are converted to utf-8

Returns:

A Json object.

Return type:

json

class_to_dict()

Returns all class properties and their values as a dictionary

Returns:

A dictionary of all class properties names and their values

Return type:

{str:var,}

duHast.Utilities.Objects.file_encoding_bom module

Helper functions relating to comma separated text files.

class duHast.Utilities.Objects.file_encoding_bom.BOMValue

Bases: object

Contains BOM values for different encodings.

UTF_8 = b'\xef\xbb\xbf'
UTF_16 = b'\xfe\xff'
UTF_16_LITTLE_ENDIAN = b'\xff\xfe'
UTF_16_BIG_ENDIAN = b'\xfe\xff'
UTF_32 = b'\x00\x00\xfe\xff'
UTF_32_LITTLE_ENDIAN = b'\xff\xfe\x00\x00'
UTF_32_BIG_ENDIAN = b'\x00\x00\xfe\xff'

duHast.Utilities.Objects.logger_object module

A logger class

The LoggerObject class is a custom logger class that extends both logging.Logger and Base. It is designed to handle logging with both file and console handlers, providing a structured and formatted logging mechanism.

Key Features: 1. Initialization:

  • The constructor initializes the logger with a specified name, output path, log levels, file format, and handlers for both file and console logging.

  • It creates the necessary directories and sets up the log file path.

  • Handlers are set up with specified formatters and added to the logger.

  1. Methods: - clear_handlers(): Clears all existing handlers from the logger. - init_handlers(): Initializes and adds the file and console handlers to the logger. - get_logger_obj(): Returns the logger object. - update_log_level(log_level): Updates the log levels for both file and console handlers.

Usage: - The class can be used to create a logger that writes logs to a file and outputs them to the console

with specified formats.

  • It allows dynamic updating of log levels and ensures that handlers are properly managed.

Example Usage:

# Create a logger object logger = LoggerObject(log_name=”myLogger”, output_path=”/path/to/logs”)

# Get the logger object logger_obj = logger.get_logger_obj()

# Update log levels logger.update_log_level((logging.INFO, logging.ERROR))

# Log messages logger_obj.info(“This is an info message”) logger_obj.error(“This is an error message”)

class duHast.Utilities.Objects.logger_object.LoggerObject(log_name='duHast', output_path='C:\\Users\\runneradmin\\AppData\\Roaming', log_level=(10, 30), file_format='.txt', fil_stream_hndlr=<class 'logging.handlers.RotatingFileHandler'>, fil_stream_frmt=<function level_time_local_msg_formatter>, cons_stream_hndlr=<class 'logging.StreamHandler'>, cons_stream_frmt=<function msg_only>, **kwargs)

Bases: Logger, Base

Constructor for the LoggerObject class.

Parameters:
  • log_name (str) – The name of the log.

  • output_path (str) – The path to the output directory.

  • log_level (tuple) – The log levels for the file and console handlers.

  • file_format (str) – The file format for the log file.

  • fil_stream_hndlr (class) – The file stream handler class.

  • fil_stream_frmt (logging.Formatter) – The file stream formatter.

  • cons_stream_hndlr (class) – The console stream handler class.

  • cons_stream_frmt (logging.Formatter) – The console stream formatter.

clear_handlers()

Clears all handlers from the logger.

init_handlers()

Initializes the file and console handlers for the logger.

get_logger_obj()

Returns the logger object.

Returns:

The logger object.

Return type:

logging.Logger

update_log_level(log_level)

Set the log levels for the file and console handlers.

Parameters:

log_level (tuple) – A tuple containing the log levels for the file and console handlers.

Returns:

The updated logger object.

Return type:

logging.Logger

duHast.Utilities.Objects.result module

A class used to return status, messages and objects back to a caller.

The Result class is a subclass of the base.Base class and is used to store and manipulate the results of a process. It has fields for message, status, and result, and provides methods to update these fields.

Example Usage:

result = Result() # Create a new instance of the Result class result.append_message(“An error occurred”) # Append a new message to the existing message result.update_status(False) # Update the status to False result.update_sep(True, “Process completed successfully”) # Update the status and append a new message print(result) # Print the result object

Methods:
__init__(self):

Initializes the Result object with default values for message, status, and result

__repr__(self):

Returns a string representation of the Result object, including the formatted message, status, and result

append_message(self, message):

Appends a new line and new message string to the existing message

update(self, otherResult):

Updates the Result object using another Result object, updating the message, status, and result

update_sep(self, status, message):

Updates the status and message properties of the Result object

update_status(self, status):

Updates the status property of the Result object

Fields:

message: A string representing the message of the result status: A boolean representing the status of the result result: A list to store the result items

class duHast.Utilities.Objects.result.Result

Bases: Base

Class constructor.

  • message default value is -

  • status default value is True

  • result default value is []

append_message(message)

Appends a new line and new message string to the existing message.

First message appended will replace the default value of -

Parameters:

message (str) – The new message to be appended.

update(otherResult)

Will use the past in result instance to update the instance.

  • .status is using a logical AND

  • .message is using append (unless other message is default ‘-‘)

  • .result is looping over past in result and adding it one by one to this .result list (ignores None)

Parameters:

otherResult (SampleBatchProcessorCode.Result) – Another result class instance.

update_sep(status, message)

Updates the .status and .message property only.

  • .status is using a logical AND

  • .message is using append (unless other message is default ‘-‘)

Parameters:
  • status (bool) – The status to be added.

  • message (str) – The message to be appended.

update_status(status)

Update .status only.

  • .status is using a logical AND

Parameters:

status (bool) – The status to be added.

duHast.Utilities.Objects.timer module

A timer class to measure code performance.

duHast.Utilities.Objects.timer.PAD_SINGLE_DIGIT_TO_TWO = '%02d'

time output formatting 2 digit padding

duHast.Utilities.Objects.timer.PAD_SINGLE_DIGIT_TO_THREE = '%03d'

time output formatting default 3 digit padding

exception duHast.Utilities.Objects.timer.TimerError

Bases: Exception

A custom exception used to report errors in use of Timer class

class duHast.Utilities.Objects.timer.Timer

Bases: Base

A class that provides functionality to measure the elapsed time between starting and stopping the timer.

Example Usage: `python timer = Timer()  # Create a new instance of the Timer class timer.start()  # Start the timer # Perform some operations timer.stop()  # Stop the timer and get the elapsed time `

Methods: - __init__(): Initializes a new instance of the Timer class. - start(): Starts a new timer. - stop(): Stops the timer and returns the elapsed time. - is_running(): Checks whether the timer is running.

Initializes a new instance of the Timer class.

start()

Starts a new timer.

Raises:

TimerError – When the timer is already running.

stop()

Stops the timer and returns the elapsed time.

Raises:

TimerError – When the timer is not running yet.

Returns:

The elapsed time since the timer has started.

Return type:

str

is_running()

Checks whether the timer is running.

Returns:

True if the timer is running, False otherwise.

Return type:

bool

Module contents