Completed
Pull Request — master (#572)
by Anthony
02:23
created

BuildPresentationAction.__init__()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
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