From 441ec2418e5706ff3f4ef38a4d6b3c96ab0ab2e9 Mon Sep 17 00:00:00 2001 From: "kujiu (@ciredutemps)" Date: Wed, 17 Jun 2020 20:25:21 +0200 Subject: [PATCH] Send WeasyPrint logs to Sphinx logger --- README.rst | 2 +- .../weasyprint_builder.py | 6 ++-- sphinx_weasyprint_builder/.__init__.py.swp | Bin 12288 -> 0 bytes sphinx_weasyprint_builder/.pdf_signing.py.swp | Bin 12288 -> 0 bytes .../.weasyprint_builder.py.swp | Bin 12288 -> 12288 bytes sphinx_weasyprint_builder/loghandler.py | 30 ++++++++++++++++++ .../weasyprint_builder.py | 6 ++-- 7 files changed, 39 insertions(+), 5 deletions(-) delete mode 100644 sphinx_weasyprint_builder/.__init__.py.swp delete mode 100644 sphinx_weasyprint_builder/.pdf_signing.py.swp create mode 100644 sphinx_weasyprint_builder/loghandler.py diff --git a/README.rst b/README.rst index 967744c..6afe379 100644 --- a/README.rst +++ b/README.rst @@ -87,7 +87,7 @@ Following parameters are needed to sign: Signing methods are really limited. Do not hesitate to contribute ! - Available: `none` (no encryption), `pkcs11` + Available: `none` (no signing), `pkcs11` To be implemented: `p12`, `gpg` diff --git a/build/lib/sphinx_weasyprint_builder/weasyprint_builder.py b/build/lib/sphinx_weasyprint_builder/weasyprint_builder.py index e8d5225..21d4c18 100644 --- a/build/lib/sphinx_weasyprint_builder/weasyprint_builder.py +++ b/build/lib/sphinx_weasyprint_builder/weasyprint_builder.py @@ -9,6 +9,10 @@ from sphinx.util.osutil import os_path from sphinx.locale import __ import weasyprint +from .loghandler import init_wpsphinx_log + + +init_wpsphinx_log() class WeasyPrintPDFBuilder(SingleFileHTMLBuilder): @@ -70,7 +74,5 @@ class WeasyPrintPDFBuilder(SingleFileHTMLBuilder): self.config.weasyprint_basename + '.pdf' ) weasy_html = weasyprint.HTML(infile) - print('*********************') - print('%s ----- %s', (infile, outfile)) weasy_html.write_pdf(outfile) # progress_message('Signing PDF') diff --git a/sphinx_weasyprint_builder/.__init__.py.swp b/sphinx_weasyprint_builder/.__init__.py.swp deleted file mode 100644 index 8d2b0a722ae2f1f34d82e10ea2e8ef303f1832d1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2ONbmr7{@D%t6AeFVfT=O4?2n3Gcr3fNj$^_1IDnvNC<4ANU|0+(={`->8@_N zYG!sYQBV*R5kXNr=Aht3ka*LBdI)$D3FIOk6u|`1g9@HR|JB{&&JMFPSvPZ#t%6^_ z>g)Qx`q!gtn5vYYe&V=uxL77gy9xR7!SA0tK3gIA>wCz#=CWv-=Oa=qWROY zLD+1oz*bbCscUnGr^%s%2a=(_f8SnbcINa}RKnKTDqt0`3RnfK0#*U5fK|XMuw@m{ z(KhlTYCn-F5NGFYedp}fo~!~^0jq#jz$#!BunJfOtO8a6tAJI&Dqt1(A1c5+LhihU zkiRDpJpTXh{{Fwdi;!#J5_kth;8ActxDVV5c7t7DC-`wEA)kOt;8hTUr@-A{JD331 zrV059ybE3e=RpN500-;BX(2;K&701XyF4$OjS@cRxzz5(xpH^FNl0;j+N zD1&|AE-(RpxSf!z;0y36xCqVz37!Ru;32RFOo2b92>BKK0sD&QbpAm(V28?l)AKKE%m7MfGVYTTVq z^Kcw#cq(pkV|_!01+qcY-f}nQ#5h{5Tg;i)t(u8A4J5H?@mPsaqR!b>niq53jHUBD z=6j@kax_=&>SizZ--ndu+(l8B+;c*_qi{*FgN$D|E1Ayj{jkb39N}4|lRc}3QnRYY zqgohe&k(ADm7DL0an&bH%GP{EyJ~+wh?q}=vR8(F7g4B$ z33tqHM8N8Nvp(FcfWG!gwd(3VRwr3Qj@3unF~;hm%403OO}mijT3I0jn>|^-m6N{n((>WKt;|d9WNyc_Q~JV zC_{$7?)cs2`_HqB&w`4_9L4?Gd~z%{bl_9f2xCpP(EfUJ&#J)&Dm-vfUMB?I-~p!* z(~ZG`ujY>{fc0yi2s19XrrtxUd{f;9>>N+Jtz-eunO;!L_DrwyS*tL`jqOd1BJrE_ zyR=cm$b8Y%5D{o*GBS+rz{vJ{=bkZJz)zYj;3tnQ98EWY=hL-=F;!SiL=<0bF3n;i z=cbcWF?(Glqr=S;kJm6-V4K5R^Uh+jzdY~E9dV9{sy5@g;5;HbOY>MEX3G`lVJBBE zI0p(&84gJ;4g)7E-F*6d?ua15sB9|>xuQvd(} diff --git a/sphinx_weasyprint_builder/.pdf_signing.py.swp b/sphinx_weasyprint_builder/.pdf_signing.py.swp deleted file mode 100644 index 1025c5780a2dda6a316091d14993fda22637f522..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI&Jxjwt7zgmHyDuo>n%c!e?KN!`adCEV)I~5{l52W>xg5#0wv(fSy889RL2bW+ zlTS*zh}c0KO8*CcE_W9mazDrra(?aV{K7e@))=)d#y*>`H`lv9D^K@WchFITY<@vY zln&%jYP;Y*9ttaXJMK$9E6q(3cVu8wu4OVj%tt&mZKX%vtrY3lP;Kk^1Jw&<^2>?| zTVARnt#nj1;|0%wWeBXMz&dNx-Px;N+Algg+n1}!fL%iX0uX=z1Rwwb2tZ&(1*|Es zJKFnNzW>d^00Izz00bZa0SG_<0uX=z1eQ=hgpA#9F!n;p{{PRv|EF{@ zp?px@DQ}c#$`j?0@<2JG98-=cP0D0mX9*qf$Pj=41Rwwb2tWV=5P$##Ah6T|4mBgv zl!db8WCz5(?4)>PqJx&|NiF)a;si3WDy%pO9XO9Qjbm*^U@J~94un=$Nr>$GXA309{$7$N&HU diff --git a/sphinx_weasyprint_builder/.weasyprint_builder.py.swp b/sphinx_weasyprint_builder/.weasyprint_builder.py.swp index 874dd73107b2bda73ef990ab1b07857506e106a4..a6ca33853f1d5a1d61a0e025ee44db490fa6fd73 100644 GIT binary patch delta 578 zcma*k&uh|g7{KwzoH?Ct+8|*fe3zT6L$Y!sPeQeeha?zOLYr>nR8YV2{aU({LeLIw zJ7mW^M2tmsiSJ;rb#Is1kJA{eKOkt6yhL60Ugc${9(eJ2KA+F?@PX%3OV*O!`SCl^ zTS_=ME`&>D_V%~g_~5+M4{YzeEwkleY2k9%I5b~ym|}+8)fsR`Eh5dcf2(5+w-Ty; z=@#a;Abua`Q!#xmkKhmKWbAJ6d=8sZqikaa@j zJM;K}lew(o8qVVrFT#NV{JSMjN)oz zCE#Hl{*%`OKF{gie=l%<&zKzBu|^8nQlebciL3WwB!h>8& TQ?mJ@s+E-N>1yM5&|*3U_>Oi@ delta 431 zcmZwDyGud=7>4mr%wrd?G!zMPD7=N*A(xP*rVL#gB7#E90we6At!Z@G8p0uj{11XI z2fEA+Ezw}nR6{hC(NYi;L679v13&nNclwISV$zk;#$pL|Agl>FM7Db#r{>yI5_s-7 za$OsDG?V^j?6w%Q{!Df@Gd~kl7gqB1BM=a^QDfixUp~F&t(x_pu+i`fu!K>I diff --git a/sphinx_weasyprint_builder/loghandler.py b/sphinx_weasyprint_builder/loghandler.py new file mode 100644 index 0000000..a5d2bc8 --- /dev/null +++ b/sphinx_weasyprint_builder/loghandler.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +import logging +from sphinx.util import logging as sphinx_logging + + +logger = sphinx_logging.getLogger('weasyprint_builder') + + +def init_wpsphinx_log(): + """ + Initialize logging for WeasyPrint. + """ + wplogger = logging.getLogger('weasyprint') + wphandler = SphinxWPHandler() + wphandler.setLevel(logging.INFO) + formatter = logging.Formatter('%(message)s') + wphandler.setFormatter(formatter) + wplogger.addHandler(wphandler) + + +class SphinxWPHandler(logging.StreamHandler): + """ + Resend WeasyPrint logging to Sphinx output. + """ + def __init__(self): + super(SphinxWPHandler, self).__init__() + + def emit(self, record): + logger.handle(record) diff --git a/sphinx_weasyprint_builder/weasyprint_builder.py b/sphinx_weasyprint_builder/weasyprint_builder.py index e8d5225..21d4c18 100644 --- a/sphinx_weasyprint_builder/weasyprint_builder.py +++ b/sphinx_weasyprint_builder/weasyprint_builder.py @@ -9,6 +9,10 @@ from sphinx.util.osutil import os_path from sphinx.locale import __ import weasyprint +from .loghandler import init_wpsphinx_log + + +init_wpsphinx_log() class WeasyPrintPDFBuilder(SingleFileHTMLBuilder): @@ -70,7 +74,5 @@ class WeasyPrintPDFBuilder(SingleFileHTMLBuilder): self.config.weasyprint_basename + '.pdf' ) weasy_html = weasyprint.HTML(infile) - print('*********************') - print('%s ----- %s', (infile, outfile)) weasy_html.write_pdf(outfile) # progress_message('Signing PDF')