Just for the kicks
Last active
December 28, 2017 06:33
-
-
Save zrks/1d5bb58b823185131c23f816d2ec4b8e to your computer and use it in GitHub Desktop.
DevOps for powerpoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import yaml | |
| from pptx import Presentation | |
| from pptx.util import Inches | |
| from pptx.enum.shapes import MSO_SHAPE | |
| def read_configuration(config_file): | |
| with open(config_file) as f: | |
| cfg = yaml.load(f) | |
| return cfg | |
| def generate_presentation(): | |
| cfg = read_configuration( | |
| os.getenv('CONFIGURATION_FILENAME', 'presentation.yml')) | |
| prs = Presentation() | |
| title_slide = prs.slide_layouts[0] | |
| slide = prs.slides.add_slide(title_slide) | |
| title = slide.shapes.title | |
| title.text = cfg['title_page']['title'] | |
| prs.save(os.getenv('PRESENTATION_NAME', 'devops-for-powerpoint.pptx')) | |
| def layout_handler(layout_name, presentation_object): | |
| for layout in presentation_object.slide_layouts: | |
| if layout.name == layout_name: | |
| return layout | |
| def generate_slides(): | |
| cfg = read_configuration( | |
| os.getenv('CONFIGURATION_FILENAME', 'presentation.yml')) | |
| prs = Presentation() | |
| for i in sorted(cfg): | |
| slide = prs.slides.add_slide( | |
| layout_handler(cfg[i]['slide_layout'], prs)) | |
| title = slide.shapes.title | |
| title.text = cfg[i]['title'] | |
| if 'content' in cfg[i]: | |
| content = slide.placeholders[1] | |
| content.text = cfg[i]['content'] | |
| if 'position' in cfg[i]: | |
| shapes = slide.shapes | |
| left = Inches(cfg[i]['position']['left']) | |
| top = Inches(cfg[i]['position']['top']) | |
| width = Inches(cfg[i]['position']['width']) | |
| height = Inches(cfg[i]['position']['height']) | |
| shape = shapes.add_shape( | |
| MSO_SHAPE.CHEVRON, left, top, width, height) | |
| left = left + width - Inches(0.4) | |
| width = Inches(2.0) | |
| for n in range(2, 6): | |
| shape = shapes.add_shape( | |
| MSO_SHAPE.CHEVRON, left, top, width, height) | |
| shape.text = 'Step yo: %d' % n | |
| left = left + width - Inches(0.4) | |
| prs.save(os.getenv('PRESENTATION_NAME', 'devops-for-powerpoint.pptx')) | |
| if __name__ == '__main__': | |
| # generate_presentation() | |
| generate_slides() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| from pptx import Presentation | |
| prs = Presentation(os.getenv('PRESENTATION_NAME', | |
| 'devops-for-powerpoint.pptx')) | |
| # text_runs will be populated with a list of strings, | |
| # one for each text run in presentation | |
| text_runs = [] | |
| for slide in prs.slides: | |
| for shape in slide.shapes: | |
| if not shape.has_text_frame: | |
| continue | |
| for paragraph in shape.text_frame.paragraphs: | |
| for run in paragraph.runs: | |
| text_runs.append(run.text) | |
| for i in text_runs: | |
| print(i) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pipeline { | |
| agent { | |
| label "master" | |
| } | |
| environment { | |
| CONFIGURATION_FILENAME = "presentation.yml" | |
| PRESENTATION_NAME = "devops-for-powerpoint.pptx" | |
| } | |
| stages { | |
| stage('Checkout') { | |
| steps { | |
| git url: 'https://gist.github.com/1d5bb58b823185131c23f816d2ec4b8e.git' | |
| } | |
| } | |
| stage('Create virtualenv') { | |
| steps { | |
| sh 'virtualenv venv' | |
| } | |
| } | |
| stage('Fetch dependencies') { | |
| steps { | |
| sh '. venv/bin/activate && pip install -r requirements.txt' | |
| } | |
| } | |
| stage('Lint source') { | |
| steps { | |
| sh "flake8 --show-source --ignore=E999,E113 *.py *.yml" | |
| } | |
| } | |
| stage('Build presentation') { | |
| steps { | |
| sh ". venv/bin/activate && python generate-presentation.py" | |
| } | |
| } | |
| stage('Lint presentation text') { | |
| steps { | |
| sh ". venv/bin/activate && python get-text.py > text.txt" | |
| sh ". venv/bin/activate && grammar-check --disable=WHITESPACE_RULE,CD_NN[1] text.txt" | |
| } | |
| } | |
| stage('Archive artifacts') { | |
| steps { | |
| archive "$PRESENTATION_NAME" | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| page_1: | |
| slide_layout: Title Slide | |
| title: DevOps for PowerPoint | |
| page_2: | |
| slide_layout: Title and Content | |
| title: Current approach | |
| content: | | |
| Current problems | |
| Version control | |
| page_3: | |
| slide_layout: Title Only | |
| title: PowerPoint Pipeline | |
| position: | |
| left: 0.93 | |
| top: 3.0 | |
| width: 1.75 | |
| height: 1.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 3to2==1.1.1 | |
| appdirs==1.4.3 | |
| autopep8==1.3.1 | |
| configparser==3.5.0 | |
| enum34==1.1.6 | |
| flake8==3.3.0 | |
| grammar-check==1.3.1 | |
| lxml==3.7.3 | |
| mccabe==0.6.1 | |
| olefile==0.44 | |
| packaging==16.8 | |
| Pillow==4.1.0 | |
| pycodestyle==2.3.1 | |
| pyflakes==1.5.0 | |
| pyparsing==2.2.0 | |
| python-pptx==0.6.5 | |
| PyYAML==3.12 | |
| six==1.10.0 | |
| XlsxWriter==0.9.6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment