DEV Community

Query Filter
Query Filter

Posted on

docker-198

for line in data["console"].split("\n"):
            clean_line = line.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
            color = "00FF00" if "[VERSION CONTROL]" in line or ">>" in line else "FFFFFF"
            if line.startswith("$"): color = "FFFF00"
            xml += f'<a:p><a:r><a:rPr sz="1100" typeface="Consolas"><a:solidFill><a:srgbClr val="{color}"/></a:solidFill></a:rPr><a:t>{clean_line}</a:t></a:r></a:p>'
        xml += '</p:txBody></p:sp>'
    else:
        # Layout for Standard Bullet Slides
        xml += (
            f'<p:sp><p:nvSpPr><p:cNvPr id="{slide_idx}1" name="Title"/><p:cNvSpPr><p:spLocks noGrp="1"/></p:cNvSpPr><p:nvPr/></p:nvSpPr>'
            '<p:spPr><a:xfrm><a:off x="711200" y="500000"/><a:ext cx="10668000" cy="1000000"/></a:xfrm></p:spPr>'
            '<p:txBody><a:bodyPr/><a:lstStyle/><a:p>'
            f'<a:r><a:rPr sz="3200" b="1"><a:solidFill><a:srgbClr val="0C2340"/></a:srgbClr></a:solidFill></a:rPr><a:t>{data["title"]}</a:t></a:r>'
            '</a:p></p:txBody></p:sp>'
            f'<p:sp><p:nvSpPr><p:cNvPr id="{slide_idx}2" name="Content"/><p:cNvSpPr><p:nvPr/></p:nvSpPr>'
            '<p:spPr><a:xfrm><a:off x="711200" y="1800000"/><a:ext cx="10668000" cy="5000000"/></a:xfrm></p:spPr>'
            '<p:txBody><a:bodyPr/><a:lstStyle/>'
        )
        for bullet in data["bullets"]:
            xml += '<a:p><a:pPr marL="457200" indent="-457200"><a:buNone/></p:pPr>'
            if "</b>" in bullet:
                parts = bullet.split("</b>")
                bold_txt = parts[0].replace("<b>", "").replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
                norm_txt = parts[1].replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
                xml += f'<a:r><a:rPr sz="1600" b="1"><a:solidFill><a:srgbClr val="009698"/></a:solidFill></a:rPr><a:t>{bold_txt}</a:t></a:r>'
                xml += f'<a:r><a:rPr sz="1600"><a:solidFill><a:srgbClr val="282828"/></a:solidFill></a:rPr><a:t>{norm_txt}</a:t></a:r>'
            else:
                clean_bullet = bullet.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
                xml += f'<a:r><a:rPr sz="1600"><a:solidFill><a:srgbClr val="282828"/></a:solidFill></a:rPr><a:t>{clean_bullet}</a:t></a:r>'
            xml += '</a:p><a:p><a:pPr><a:lnSpc><a:spcPct val="120000"/></a:lnSpc></a:pPr></a:p>'
        xml += '</p:txBody></p:sp>'

    xml += '</p:spTree></p:cSld></p:sld>'
    return xml

def create_presentation():
    """Generates structural files mapping required Open XML format criteria."""
    filename = "Java_Decompilation_Pipeline.pptx"

    pres_xml = (
        '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n'
        '<p:presentation xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" '
        'xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" '
        'xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">\n'
        '<p:sldIdLst>\n'
    )
    for i in range(len(SLIDES_DATA)):
        pres_xml += f'  <p:sldId id="{256 + i}" r:id="rId{i+1}"/>\n'
    pres_xml += '</p:sldIdLst>\n<p:sldSz cx="12192000" cy="6858000"/>\n<p:notesSz cx="6858000" cy="9144000"/>\n</p:presentation>'

    rels_xml = (
        '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n'
        '<Relationships xmlns="http://schemas.openxmlformats.org/relationships">\n'
    )
    for i in range(len(SLIDES_DATA)):
        rels_xml += f'  <Relationship id="rId{i+1}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide" Target="slides/slide{i+1}.xml"/>\n'
    rels_xml += '</Relationships>'

    content_types_xml = (
        '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n'
        '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">\n'
        '  <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>\n'
        '  <Default Extension="xml" ContentType="application/xml"/>\n'
        '  <Override PartName="/ppt/presentation.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"/>\n'
    )
    for i in range(len(SLIDES_DATA)):
        content_types_xml += f'  <Override PartName="/ppt/slides/slide{i+1}.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slide+xml"/>\n'
    content_types_xml += '</Types>'

    with zipfile.ZipFile(filename, 'w', zipfile.ZIP_DEFLATED) as pptx:
        pptx.writestr('ppt/presentation.xml', pres_xml)
        pptx.writestr('ppt/_rels/presentation.xml.rels', rels_xml)
        pptx.writestr('[Content_Types].xml', content_types_xml)

        for idx, slide_data in enumerate(SLIDES_DATA):
            slide_xml_content = build_slide_xml(idx + 1, slide_data)
            pptx.writestr(f'ppt/slides/slide{idx+1}.xml', slide_xml_content)

    print(f"Successfully generated pure PowerPoint asset: '{filename}' without any pip dependencies.")

if __name__ == "__main__":
    create_presentation()
Enter fullscreen mode Exit fullscreen mode

Top comments (0)