|
2 | 2 | Custom code to handle documentation versions from the main repo. |
3 | 3 | """ |
4 | 4 |
|
| 5 | +import os |
5 | 6 | import shutil |
6 | 7 | import subprocess |
7 | 8 | import urllib.request |
@@ -104,51 +105,68 @@ def writeDocsCopy(self): |
104 | 105 | ## |
105 | 106 |
|
106 | 107 | def _buildPdfManual(self): |
107 | | - """This function will build the documentation as manual.pdf.""" |
108 | | - buildDir = str(self._extPath / "docs") |
109 | | - buildFile = self._extPath / "docs" / "build" / "latex" / "manual.pdf" |
110 | | - buildFile.unlink(missing_ok=True) |
111 | | - |
112 | | - print("Building PDF manual ... ", end="") |
113 | | - subprocess.call(["make", "clean"], cwd=buildDir) |
114 | | - exCode = subprocess.call( |
115 | | - ["make", "latexpdf"], cwd=buildDir, |
116 | | - stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT |
117 | | - ) |
118 | | - if exCode != 0: |
119 | | - raise Exception(f"Build returned error code {exCode}") |
120 | | - |
121 | | - if buildFile.exists(): |
122 | | - newDoc = self._pdfPath / f"novelWriter-{self._nwMajor}.{self._nwMinor}.pdf" |
123 | | - newDoc.unlink(missing_ok=True) |
124 | | - buildFile.rename(newDoc) |
125 | | - print("Done") |
126 | | - else: |
127 | | - print("FAILED") |
| 108 | + """Build the documentation as manual.pdf.""" |
| 109 | + docsDir = self._extPath / "docs" |
| 110 | + locsDir = self._extPath / "docs" / "source" / "locales" |
| 111 | + pdfFile = self._extPath / "docs" / "build" / "latex" / "manual.pdf" |
| 112 | + locsDir.mkdir(exist_ok=True) |
| 113 | + |
| 114 | + build = ["en"] + [i.stem for i in locsDir.iterdir() if i.is_dir()] |
| 115 | + |
| 116 | + for code in build: |
| 117 | + print(f"Building PDF manual ({code}) ... ", end="", flush=True) |
| 118 | + env = os.environ.copy() |
| 119 | + cmd = "make clean latexpdf" |
| 120 | + name = "novelWriter" |
| 121 | + if code != "en": |
| 122 | + data = (locsDir / f"authors_{code}.conf").read_text(encoding="utf-8") |
| 123 | + authors = [x for x in data.splitlines() if x and not x.startswith("#")] |
| 124 | + env["SPHINX_I18N_AUTHORS"] = ", ".join(authors) |
| 125 | + cmd += f" -e SPHINXOPTS=\"-D language='{code}'\"" |
| 126 | + name = f"novelWriter-{code}" |
| 127 | + |
| 128 | + if subprocess.call(cmd, cwd=docsDir, env=env, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) == 0: |
| 129 | + newDoc = self._pdfPath / f"{name}-{self._nwMajor}.{self._nwMinor}.pdf" |
| 130 | + newDoc.unlink(missing_ok=True) |
| 131 | + pdfFile.rename(newDoc) |
| 132 | + print("Done") |
| 133 | + else: |
| 134 | + print("FAILED") |
128 | 135 |
|
129 | 136 | return |
130 | 137 |
|
131 | 138 | def _createPdfPage(self): |
132 | 139 | """Create the index of PDF manuals.""" |
133 | | - pdfs = [] |
| 140 | + pdfs: list[tuple[str, str, str, str]] = [] |
134 | 141 | for item in self._pdfPath.iterdir(): |
135 | 142 | if item.is_file() and item.suffix == ".pdf": |
136 | | - _, _, version = item.stem.partition("-") |
137 | | - key = ".".join(version.split(".")[:2]) |
138 | | - pdfs.append((key, item.name)) |
139 | | - |
140 | | - docsPDF = [] |
141 | | - specPDF = [] |
142 | | - for _, pdf in sorted(pdfs, key=lambda x: x[0], reverse=True): |
143 | | - if pdf.startswith("novelWriter"): |
144 | | - docsPDF.append(pdf) |
145 | | - elif pdf.startswith("FileFormat"): |
146 | | - specPDF.append(pdf) |
| 143 | + kind, _, spec = item.stem.partition("-") |
| 144 | + one, _, two = spec.partition("-") |
| 145 | + if two: |
| 146 | + lang = one |
| 147 | + version = ".".join(two.split(".")[:2]) |
| 148 | + else: |
| 149 | + lang = "en" |
| 150 | + version = ".".join(one.split(".")[:2]) |
| 151 | + pdfs.append((kind, lang, version, item.name)) |
| 152 | + |
| 153 | + docsPdfEn = [] |
| 154 | + docsPdfTr = [] |
| 155 | + specPdfEn = [] |
| 156 | + for kind, lang, version, pdf in sorted(pdfs, key=lambda x: x[2], reverse=True): |
| 157 | + if kind == "novelWriter": |
| 158 | + if lang == "en": |
| 159 | + docsPdfEn.append(pdf) |
| 160 | + else: |
| 161 | + docsPdfTr.append(pdf) |
| 162 | + elif kind == "FileFormatSpec": |
| 163 | + specPdfEn.append(pdf) |
147 | 164 |
|
148 | 165 | with open(self._pdfPath / "index.rst", mode="w", encoding="utf-8") as of: |
149 | 166 | of.write((self._tplPath / "more_docs.rst").read_text(encoding="utf-8").format( |
150 | | - doc_pdfs="\n".join(f"| :download:`{pdf}`" for pdf in docsPDF), |
151 | | - spec_pdfs="\n".join(f"| :download:`{pdf}`" for pdf in specPDF), |
| 167 | + doc_pdfs="\n".join(f"| :download:`{pdf}`" for pdf in docsPdfEn), |
| 168 | + doc_pdfs_i18n="\n".join(f"| :download:`{pdf}`" for pdf in docsPdfTr), |
| 169 | + spec_pdfs="\n".join(f"| :download:`{pdf}`" for pdf in specPdfEn), |
152 | 170 | )) |
153 | 171 |
|
154 | 172 | return |
@@ -241,5 +259,3 @@ def _extractReleaseInfo(self): |
241 | 259 | print("Done") |
242 | 260 |
|
243 | 261 | return |
244 | | - |
245 | | -# END Class Documentation |
|
0 commit comments