|
14 | 14 | from functools import partial
|
15 | 15 |
|
16 | 16 | # --------------------
|
17 |
| -# Texlive installation specification |
| 17 | +# Texlive version information |
18 | 18 | # --------------------
|
19 | 19 |
|
20 |
| -TLMGR_LIST_LINE_REGEX_PATTERN = r"^(i|\s)\s(\S+):\s(.+)$" |
21 |
| -TLMGR_LIST_LINE_REGEX = re.compile(TLMGR_LIST_LINE_REGEX_PATTERN) |
| 20 | +TEXLIVE_MODULE_REVISION_REGEX_PATTERN = r"^(\S+):\s+(\d+)$" |
| 21 | +TEXLIVE_MODULE_REVISION_REGEX = re.compile(TEXLIVE_MODULE_REVISION_REGEX_PATTERN) |
22 | 22 |
|
23 | 23 |
|
24 |
| -def parse_tlmgr_list_line(line): |
25 |
| - regex_match = TLMGR_LIST_LINE_REGEX.match(line) |
| 24 | +def parse_texlive_module_revision_line(line): |
| 25 | + regex_match = TEXLIVE_MODULE_REVISION_REGEX.match(line) |
26 | 26 | if not regex_match:
|
27 |
| - raise RuntimeError("Unable to parse tlmr list line ouput: {}".format(line)) |
| 27 | + raise RuntimeError( |
| 28 | + "Unable to parse TeXLive module revision line ouput: {}".format(line) |
| 29 | + ) |
28 | 30 | return {
|
29 |
| - "installed": regex_match.group(1) == "i", |
30 |
| - "name": regex_match.group(2), |
31 |
| - "shortdesc": regex_match.group(3), |
| 31 | + "module_name": regex_match.group(1), |
| 32 | + "module_revision": regex_match.group(2), |
32 | 33 | }
|
33 | 34 |
|
| 35 | + |
34 | 36 | def parse_tlmgr_version_verbose_line(line, line_index):
|
35 | 37 | if "tlmgr revision" in line:
|
36 | 38 | version, remaining = line.split("tlmgr revision ")[1].split(" (")
|
37 | 39 | return {
|
38 |
| - "tlmgr_version": version, |
39 |
| - "tlmgr_revision_date": remaining.split(")")[0] |
| 40 | + "tlmgr_revision": version, |
| 41 | + "tlmgr_revision_date": remaining.split(")")[0], |
40 | 42 | }
|
41 | 43 | if "tlmgr using installation" in line:
|
42 | 44 | return {
|
43 | 45 | "texlive_installation_path": line.split("tlmgr using installation: ")[1]
|
44 | 46 | }
|
45 | 47 | if "TeX Live" in line and "version" in line:
|
46 |
| - return { |
47 |
| - "texlive_version": line.split("version ")[1] |
48 |
| - } |
49 |
| - print(line, line_index) |
50 |
| - return {} |
| 48 | + return {"texlive_version": line.split("version ")[1]} |
| 49 | + if "Revisions of TeXLive:: modules:" in line: |
| 50 | + return {} |
| 51 | + parsed_module = parse_texlive_module_revision_line(line) |
| 52 | + return { |
| 53 | + "module_revision_{}".format(parsed_module["module_name"]): parsed_module[ |
| 54 | + "module_revision" |
| 55 | + ] |
| 56 | + } |
51 | 57 |
|
52 | 58 |
|
53 | 59 | def parse_tlmgr_version_verbose(output):
|
54 | 60 | parsed_entries = {}
|
55 | 61 | for line_index, line in enumerate(output.splitlines()):
|
56 | 62 | parsed_entries = {
|
57 | 63 | **parsed_entries,
|
58 |
| - **parse_tlmgr_version_verbose_line(line, line_index) |
| 64 | + **parse_tlmgr_version_verbose_line(line, line_index), |
59 | 65 | }
|
60 |
| - return parsed_entries |
| 66 | + # Reshape parsed entries. |
| 67 | + module_revisions = [] |
| 68 | + for entry_name, entry_value in parsed_entries.items(): |
| 69 | + if "module_revision_" in entry_name: |
| 70 | + module_revisions.append( |
| 71 | + {"name": entry_name.split("module_revision_")[1], "value": entry_value} |
| 72 | + ) |
| 73 | + return { |
| 74 | + "tlmgr": { |
| 75 | + "revision": parsed_entries["tlmgr_revision"], |
| 76 | + "revision_date": parsed_entries["tlmgr_revision_date"], |
| 77 | + }, |
| 78 | + "texlive": { |
| 79 | + "version": parsed_entries["texlive_version"], |
| 80 | + "installation_path": parsed_entries["texlive_installation_path"], |
| 81 | + "modules": module_revisions, |
| 82 | + }, |
| 83 | + } |
61 | 84 |
|
62 | 85 |
|
63 | 86 | def get_texlive_version_information():
|
|
0 commit comments