Skip to content

parser

Base module ofr parsing extensions.

Attributes

mlogger = get_logger(__name__) module-attribute

Functions

parse_comp_dir(comp_path, comp_class)

Source code in pyrevitlib/pyrevit/extensions/parser.py
def parse_comp_dir(comp_path, comp_class):
    return _create_subcomponents(
        comp_path,
        _get_subcomponents_classes([comp_class]),
        create_from_search_dir=True
        )

get_parsed_extension(extension)

Creates and adds the extensions components to the package.

Each package object is the root to a tree of components that exists under that package. (e.g. tabs, buttons, ...) sub components of package can be accessed by iterating the _get_component. See _basecomponents for types.

Source code in pyrevitlib/pyrevit/extensions/parser.py
def get_parsed_extension(extension):
    """Creates and adds the extensions components to the package.

    Each package object is the root to a tree of components that exists
    under that package. (e.g. tabs, buttons, ...) sub components of package
    can be accessed by iterating the _get_component.
    See _basecomponents for types.
    """
    _parse_for_components(extension)
    return extension

parse_dir_for_ext_type(root_dir, parent_cmp_type)

Return the objects of type parent_cmp_type of the extensions in root_dir.

The package objects won't be parsed at this level. This is useful for collecting basic info on an extension type for cache cheching or updating extensions using their directory paths.

Parameters:

Name Type Description Default
root_dir str

directory to parse

required
parent_cmp_type type

type of objects to return

required
Source code in pyrevitlib/pyrevit/extensions/parser.py
def parse_dir_for_ext_type(root_dir, parent_cmp_type):
    """Return the objects of type parent_cmp_type of the extensions in root_dir.

    The package objects won't be parsed at this level.
    This is useful for collecting basic info on an extension type
    for cache cheching or updating extensions using their directory paths.

    Args:
        root_dir (str): directory to parse
        parent_cmp_type (type): type of objects to return
    """
    # making sure the provided directory exists.
    # This is mainly for the user defined package directories
    if not op.exists(root_dir):
        mlogger.debug('Extension search directory does not exist: %s', root_dir)
        return []

    # try creating extensions in given directory
    ext_data_list = []

    mlogger.debug('Parsing directory for extensions of type: %s',
                  parent_cmp_type)
    for ext_data in _create_subcomponents(root_dir, [parent_cmp_type]):
        mlogger.debug('Extension directory found: %s', ext_data)
        ext_data_list.append(ext_data)

    return ext_data_list