10.1.3. Module: pptx_builder

Tanium Hygiene Assessment Tool (THAT) Power Point builder module.

10.1.3.1. Class: PptxBuilder

class tanium_hat.pptx_builder.PptxBuilder(pptx_output_path, pptx_input_path, **kwargs)[source]

Bases: object

Power Point builder for THAT.

Parameters:
PPTX_OUTPUT_PATH

str

PPTX_INPUT_PATH

str

  • path to input power point file that contains layout slides, set at init
PRESO

pptx.Presentation

  • Presentation object of loaded pptx_input_path, set at init
SLIDE_MAP

dict

  • dictionary that keeps track of added slides by name
SORTED_LAYOUTS

list

  • list of slides sorted by add_order
LOG

logging.Logger

  • python logger for this instance
ENGINE

tanium_hat.pptx_builder.TemplateEngine

  • Template engine used for templatizing items strings before adding to slides
__init__(pptx_output_path, pptx_input_path, **kwargs)[source]

Constructor.

__str__()[source]

String method for class.

_sep1()[source]

Log a level 1 separation line.

_sep2()[source]

Log a level 2 separation line.

_sep3()[source]

Log a level 3 separation line.

_sep4()[source]

Log a level 4 separation line.

add_slide_from_layouts(layout_idx, layout_def)[source]

Add a layout slide from pptx_input_path as a master slide to pptx_output_path.

Parameters:
  • layout_idx (int) –
    • The index of the layout slide to get from pptx_input_path
  • layout_def (dict) –
    • The layout definition for this slide
Returns:

ret

  • The master slide added to the presentation object

Return type:

pptx.slide.Slide

add_slides(layouts, results, check_unset=True)[source]

Add layout slides as master slides based on layout definitions.

Parameters:
  • layouts (dict) –
    • layout definitions dictionary
  • results (dict) –
    • results dictionary
  • check_unset (bool, optional) –
    • default : True
    • True : After adding slides and updating items, log all items we did not update
    • False : do not log unset items
check_unset_slide_items(layout_idx, layout_def)[source]

Check a master slide for unset items.

  • Gets slide map for layout_def[name] from tanium_hat.pptx_builder.PptxBuilder.SLIDE_MAP
  • Gets master slide from slide_map[slide]
  • Gets placeholder tracker from slide_map[ph_tracker]
  • Logs warning message for each placeholder index not found in placeholder tracker
Parameters:
  • layout_idx (int) –
    • The index of the layout slide to get from pptx_input_path
  • layout_def (dict) –
    • The layout definition for this slide
get_layout_slide(idx, name)[source]

Get a layout slide from pptx_input_path by index idx.

Parameters:
  • idx (int) –
    • The index of the layout slide to get from pptx_input_path
  • name (str) –
    • The name given to this slide from the layout definition
Returns:

ret

  • The layout slide from the pptx_input_path

Return type:

pptx.slide.SlideLayout

layouts_sorted(layouts, results)[source]

Sort layout definitions based on add_order.

  • If a layout definition has an add_dependency that does not exist as a key name in results, that means the plugin was not enabled, so we will not add that layout definition
  • If a layout definition does not define add_order, determine add_order by:
    • Get the “priority” key from results[layout_def[“add_dependency”]]
    • Default to 5000 if not defined
    • Add 100 to whatever was resolved
Parameters:
  • layouts (dict) –
    • layout definitions dictionary
  • results (dict) –
    • results dictionary
Returns:

ret

  • add_order sorted list of layout definition items

Return type:

list

load_input_file(pptx_input_path)[source]

Load pptx_input_file as a Presentation object.

Parameters:pptx_input_path (str) –
  • path to input power point file that contains layout slides
Returns:ret
  • Presentation object loaded from pptx_input_path
Return type:pptx.Presentation
log_slides(layouts=False, debug=False)[source]

Log all slides found in tanium_hat.pptx_builder.PptxBuilder.PRESO.

Parameters:
  • layouts (bool, optional) –
    • default : False
    • True : log the layout slides
    • False : log the master slides
  • debug (bool, optional) –
    • default : False
    • True : log at info level
    • False : log at debug level
save(**kwargs)[source]

Save tanium_hat.pptx_builder.PptxBuilder.PRESO to pptx_output_path as a powerpoint file.

Parameters:pptx_output_path (str, optional) –
slide_map_by_name(name)[source]

Get a slide map from tanium_hat.pptx_builder.PptxBuilder.SLIDE_MAP by name.

Parameters:name (str) –
  • name of slide to fetch from slide map
Returns:ret
  • The slide map for name
Return type:dict
update_slide_item(idx, tmpl, name)[source]

Update an item by idx on a master slide.

Parameters:
  • idx (int) –
    • The index of the item on the master slide to update
  • tmpl (str) –
    • The untemplatized string to update the item with
  • name (str) –
    • The name of the master slide to update
update_slide_items(layout_idx, layout_def)[source]

Update items on a master slide.

Parameters:
  • layout_idx (int) –
    • The index of the layout slide to get from pptx_input_path
  • layout_def (dict) –
    • The layout definition for this slide

10.1.3.2. Class: TemplateEngine

class tanium_hat.pptx_builder.TemplateEngine(results, **kwargs)[source]

Bases: object

String templating engine.

Uses jinja2 to render all text templates.

Parameters:results (dict) –
  • results dictionary for use in templating
RESULTS

dict

  • results dictionary for use in templating
ENGINE

jinja2.Environment

  • jinja2 environment used for all templating
__init__(results, **kwargs)[source]

Constructor.

fetch(section, key)[source]

Custom method made available to the global jinja2 environment.

Examples

On render, if this is found in a template string:

“{{ fetch(‘config’, ‘prepared_on’) }}”

The value of results[config][prepared_on] will be substituted inline

Parameters:
Returns:

ret

  • The result of whatever results[section][key] is
  • An error string if section or key not found

Return type:

object

render(source, **kwargs)[source]

Render source as a jinja2 template using jinja2.Environment.from_string().

Parameters:source (str) –
  • Template string to render using jinja2
Returns:ret
  • Templatized string
Return type:str

10.1.3.3. Function: val_layouts

tanium_hat.pptx_builder.val_layouts(layouts)[source]

Validate a given set of layout definitions.

Parameters:layouts (dict) –
  • layout definitions to validate

10.1.3.4. Function: is_type

tanium_hat.pptx_builder.is_type(name, obj, attr_type)[source]

Validate that obj is of type attr_type.

Parameters:
  • name (str) –
    • name of this object
  • obj (object) –
    • object to validate is of attr_type
  • attr_type (obj:object) –
    • type or tuple of types to validate against obj

10.1.3.5. Function: has_key

tanium_hat.pptx_builder.has_key(name, obj, key)[source]

Validate that obj has key key.

Parameters:
  • name (str) –
    • name of this object
  • obj (dict) –
    • dict to validate has key
  • key (obj:str) –
    • str of key to look for in obj