Skip to content

Commit 1d4837e

Browse files
committed
get_texlive_version_information implemented and tested with TeXLive 2019
1 parent 88f83b1 commit 1d4837e

File tree

5 files changed

+64
-23
lines changed

5 files changed

+64
-23
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,25 @@ be processed and used from Python.
1414
pip install texlivemetadata
1515
```
1616

17+
## TeXLive version information
18+
19+
```python
20+
import texlivemetadata
21+
22+
# Get version information on current TeXLive installation.
23+
print(texlivemetadata.get_texlive_version_information())
24+
# --->
25+
# {'texlive': {'installation_path': '/opt/texlive/2019',
26+
# 'modules': [{'name': 'TLConfig', 'value': '50190'},
27+
# {'name': 'TLUtils', 'value': '50493'},
28+
# {'name': 'TLPOBJ', 'value': '50211'},
29+
# {'name': 'TLPDB', 'value': '51110'},
30+
# {'name': 'TLPaper', 'value': '45795'},
31+
# {'name': 'TLWinGoo', 'value': '47907'}],
32+
# 'version': '2019'},
33+
# 'tlmgr': {'revision': '51217', 'revision_date': '2019-05-24 23:47:41 +0200'}}
34+
```
35+
1736
## Package listing
1837

1938
```python

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name="texlivemetadata",
9-
version="0.1.2",
9+
version="0.1.3",
1010
url="https://github.com/YtoTech/python-texlivemetadata",
1111
license="MIT",
1212
author="Yoan Tournade",

test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
import pprint
12
from texlivemetadata import get_texlive_version_information
23

34
output = get_texlive_version_information()
4-
print(output)
5+
pprint.pprint(output)

texlivemetadata/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,4 @@
1414
get_package_info,
1515
get_ctan_link,
1616
)
17-
from .texlive import (
18-
get_texlive_version_information,
19-
)
17+
from .texlive import get_texlive_version_information

texlivemetadata/texlive.py

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,73 @@
1414
from functools import partial
1515

1616
# --------------------
17-
# Texlive installation specification
17+
# Texlive version information
1818
# --------------------
1919

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)
2222

2323

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)
2626
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+
)
2830
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),
3233
}
3334

35+
3436
def parse_tlmgr_version_verbose_line(line, line_index):
3537
if "tlmgr revision" in line:
3638
version, remaining = line.split("tlmgr revision ")[1].split(" (")
3739
return {
38-
"tlmgr_version": version,
39-
"tlmgr_revision_date": remaining.split(")")[0]
40+
"tlmgr_revision": version,
41+
"tlmgr_revision_date": remaining.split(")")[0],
4042
}
4143
if "tlmgr using installation" in line:
4244
return {
4345
"texlive_installation_path": line.split("tlmgr using installation: ")[1]
4446
}
4547
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+
}
5157

5258

5359
def parse_tlmgr_version_verbose(output):
5460
parsed_entries = {}
5561
for line_index, line in enumerate(output.splitlines()):
5662
parsed_entries = {
5763
**parsed_entries,
58-
**parse_tlmgr_version_verbose_line(line, line_index)
64+
**parse_tlmgr_version_verbose_line(line, line_index),
5965
}
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+
}
6184

6285

6386
def get_texlive_version_information():

0 commit comments

Comments
 (0)