Completed
Push — master ( ef5eca...18a34e )
by Edward
20s
created

BuildPresentationAction   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 29
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
B run() 0 24 6
A __init__() 0 3 1
1
import os
2
from pptx import Presentation
3
4
from st2actions.runners.pythonrunner import Action
5
from st2common.exceptions.action import InvalidActionParameterException
6
7
__all__ = [
8
    'BuildPresentationAction',
9
]
10
11
12
class BuildPresentationAction(Action):
13
    def __init__(self, config):
14
        super(BuildPresentationAction, self).__init__(config)
15
        self.template = self.config['template']
16
17
    def run(self, path, slides):
18
        if self.template is not None and self.template != '':
19
            if os.path.exists(self.template):
20
                prs = Presentation(self.template)
21
        else:
22
            prs = Presentation()
23
24
        if not isinstance(slides, list):
25
            raise InvalidActionParameterException("slides must be a list")
26
27
        for slide in slides:
28
            slide = prs.slides.add_slide(slide.get('layout', 1))
29
            shapes = slide.shapes
30
31
            title_shape = shapes.title
32
            body_shape = shapes.placeholders[1]
33
34
            title_shape.text = slide.get('title', '')
35
36
            tf = body_shape.text_frame
37
            tf.text = slide.get('text', '')
38
39
        result = prs.save(path)
40
        return result
41