2121from __future__ import annotations
2222
2323import argparse
24- import os
2524import subprocess
2625import sys
2726import zipfile
2827
2928from pathlib import Path
3029
3130from utils .common import ROOT_DIR , writeFile
32-
33-
34- def buildPdfManual (args : argparse .Namespace | None = None ) -> None :
35- """This function will build the documentation as manual.pdf."""
36- print ("" )
37- print ("Building PDF Manual" )
38- print ("===================" )
39- print ("" )
40-
41- buildFile = ROOT_DIR / "docs" / "build" / "latex" / "manual.pdf"
42- finalFile = ROOT_DIR / "novelwriter" / "assets" / "manual.pdf"
43- finalFile .unlink (missing_ok = True )
44-
45- try :
46- subprocess .call (["make" , "clean" ], cwd = "docs" )
47- exCode = subprocess .call (["make" , "latexpdf" ], cwd = "docs" )
48- if exCode == 0 :
49- print ("" )
50- buildFile .rename (finalFile )
51- else :
52- raise Exception (f"Build returned error code { exCode } " )
53-
54- print ("PDF manual build: OK" )
55- print ("" )
56-
57- except Exception as exc :
58- print ("PDF manual build: FAILED" )
59- print ("" )
60- print (str (exc ))
61- print ("" )
62- print ("Dependencies:" )
63- print (" * pip install sphinx" )
64- print (" * Package latexmk" )
65- print (" * LaTeX build system" )
66- print ("" )
67- print (" On Debian/Ubuntu, install: python3-sphinx latexmk texlive texlive-latex-extra" )
68- print ("" )
69- sys .exit (1 )
70-
71- if not finalFile .is_file ():
72- print ("No output file was found!" )
73- print ("" )
74- sys .exit (1 )
75-
76- return
31+ from utils .docs import buildPdfDocAssets
7732
7833
7934def buildSampleZip (args : argparse .Namespace | None = None ) -> None :
@@ -90,7 +45,9 @@ def buildSampleZip(args: argparse.Namespace | None = None) -> None:
9045
9146 if srcSample .is_dir ():
9247 dstSample .unlink (missing_ok = True )
93- with zipfile .ZipFile (dstSample , "w" ) as zipObj :
48+ with zipfile .ZipFile (
49+ dstSample , mode = "w" , compression = zipfile .ZIP_DEFLATED , compresslevel = 3
50+ ) as zipObj :
9451 print ("Compressing: nwProject.nwx" )
9552 zipObj .write (srcSample / "nwProject.nwx" , "nwProject.nwx" )
9653 for doc in (srcSample / "content" ).iterdir ():
@@ -249,84 +206,6 @@ def buildTranslationAssets(args: argparse.Namespace | None = None) -> None:
249206 return
250207
251208
252- def updateDocsTranslationSources (args : argparse .Namespace ) -> None :
253- """Build the documentation .po files."""
254- print ("" )
255- print ("Building Docs Translation Files" )
256- print ("===============================" )
257- print ("" )
258-
259- docsDir = ROOT_DIR / "docs"
260- locsDir = ROOT_DIR / "docs" / "source" / "locales"
261- locsDir .mkdir (exist_ok = True )
262-
263- print ("Generating POT Files" )
264- subprocess .call (["make" , "gettext" ], cwd = docsDir )
265- print ("" )
266-
267- lang = args .lang
268- update = []
269- if lang == ["all" ]:
270- update = [i .stem for i in locsDir .iterdir () if i .is_dir ()]
271- else :
272- update = lang
273-
274- print ("Generating PO Files" )
275- print ("Languages: " , update )
276- print ("" )
277-
278- for code in update :
279- subprocess .call (["sphinx-intl" , "update" , "-p" , "build/gettext" , "-l" , code ], cwd = docsDir )
280- print ("" )
281-
282- print ("Done" )
283- print ("" )
284-
285- return
286-
287-
288- def buildDocsTranslationAssets (args : argparse .Namespace | None = None ) -> None :
289- """Build the documentation i18n PDF files."""
290- from PyQt6 .QtCore import QLocale
291-
292- print ("" )
293- print ("Building Docs Manuals" )
294- print ("=====================" )
295- print ("" )
296-
297- docsDir = ROOT_DIR / "docs"
298- locsDir = ROOT_DIR / "docs" / "source" / "locales"
299- pdfFile = ROOT_DIR / "docs" / "build" / "latex" / "manual.pdf"
300- locsDir .mkdir (exist_ok = True )
301-
302- lang = args .lang if args else ["all" ]
303- build = []
304- if lang == ["all" ]:
305- build = [i .stem for i in locsDir .iterdir () if i .is_dir ()]
306- else :
307- build = lang
308-
309- for code in build :
310- data = (locsDir / f"authors_{ code } .conf" ).read_text (encoding = "utf-8" )
311- authors = [x for x in data .splitlines () if x and not x .startswith ("#" )]
312- env = os .environ .copy ()
313- env ["SPHINX_I18N_AUTHORS" ] = ", " .join (authors )
314- exCode = subprocess .call (
315- f"make -e SPHINXOPTS=\" -D language='{ code } '\" clean latexpdf" ,
316- cwd = docsDir , env = env , shell = True
317- )
318- if exCode == 0 :
319- print ("" )
320- name = f"manual_{ QLocale (code ).name ()} .pdf"
321- pdfFile .rename (ROOT_DIR / "novelwriter" / "assets" / name )
322- else :
323- raise Exception (f"Build returned error code { exCode } " )
324-
325- print ("" )
326-
327- return
328-
329-
330209def cleanBuiltAssets (args : argparse .Namespace | None = None ) -> None :
331210 """Remove assets built by this script."""
332211 print ("" )
@@ -350,8 +229,7 @@ def cleanBuiltAssets(args: argparse.Namespace | None = None) -> None:
350229def buildAllAssets (args : argparse .Namespace ) -> None :
351230 """Build all assets."""
352231 cleanBuiltAssets ()
353- buildPdfManual ()
354232 buildSampleZip ()
355233 buildTranslationAssets ()
356- buildDocsTranslationAssets ()
234+ buildPdfDocAssets ()
357235 return
0 commit comments