forked from wikimedia/pywikibot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.py
executable file
·103 lines (80 loc) · 2.94 KB
/
version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python3
"""Script to determine the Pywikibot version (tag, revision and date).
.. versionchanged:: 7.0
version script was moved to the framework scripts folder
"""
#
# (C) Pywikibot team, 2007-2022
#
# Distributed under the terms of the MIT license.
#
from __future__ import annotations
import codecs
import os
import sys
import pywikibot
from pywikibot.version import getversion
class DummyModule:
"""Fake module instance."""
__version__ = 'n/a'
try:
import setuptools
except ImportError:
setuptools = DummyModule()
try:
import mwparserfromhell
except ImportError:
mwparserfromhell = DummyModule()
try:
import wikitextparser
except ImportError:
wikitextparser = DummyModule()
try:
import requests
except ImportError:
requests = DummyModule()
WMF_CACERT = 'MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBs'
def main(*args: str) -> None:
"""Print pywikibot version and important settings."""
pywikibot.info(f'Pywikibot: {getversion()}')
pywikibot.info(f'Release version: {pywikibot.__version__}')
pywikibot.info(f'setuptools version: {setuptools.__version__}')
pywikibot.info(f'mwparserfromhell version: {mwparserfromhell.__version__}')
pywikibot.info(f'wikitextparser version: {wikitextparser.__version__}')
pywikibot.info(f'requests version: {requests.__version__}')
has_wikimedia_cert = False
if (not hasattr(requests, 'certs')
or not hasattr(requests.certs, 'where')
or not callable(requests.certs.where)):
pywikibot.info(' cacerts: not defined')
elif not os.path.isfile(requests.certs.where()):
pywikibot.info(f' cacerts: {requests.certs.where()} (missing)')
else:
pywikibot.info(f' cacerts: {requests.certs.where()}')
with codecs.open(requests.certs.where(), 'r', 'utf-8') as cert_file:
text = cert_file.read()
if WMF_CACERT in text:
has_wikimedia_cert = True
pywikibot.info(
f" certificate test: {'ok' if has_wikimedia_cert else 'not ok'}"
)
if not has_wikimedia_cert:
pywikibot.info(' Please reinstall requests!')
pywikibot.info(f'Python: {sys.version}')
# check environment settings
settings = {key for key in os.environ if key.startswith('PYWIKIBOT')}
settings.update(['PYWIKIBOT_DIR', 'PYWIKIBOT_DIR_PWB',
'PYWIKIBOT_NO_USER_CONFIG'])
for environ_name in sorted(settings):
pywikibot.info(
f"""{environ_name}: {os.environ.get(environ_name, 'Not set') or "''"}"""
)
pywikibot.info(f'Config base dir: {pywikibot.config.base_dir}')
for family, usernames in pywikibot.config.usernames.items():
if not usernames:
continue
pywikibot.info(f'Usernames for family {family!r}:')
for lang, username in usernames.items():
pywikibot.info(f'\t{lang}: {username}')
if __name__ == '__main__':
main()