-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path__about__.py
More file actions
113 lines (93 loc) · 3.55 KB
/
__about__.py
File metadata and controls
113 lines (93 loc) · 3.55 KB
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
104
105
106
107
108
109
110
111
112
113
#! python3
"""Package metadata.
Contains package metadata constants used by the plugin (title, icon, etc.).
"""
# ############################################################################
# ########## Libraries #############
# ##################################
# standard library
from configparser import ConfigParser
from datetime import date
from pathlib import Path
# ############################################################################
# ########## Globals ###############
# ##################################
__all__: list = [
"__author__",
"__copyright__",
"__email__",
"__license__",
"__summary__",
"__title__",
"__uri__",
"__version__",
]
DIR_PLUGIN_ROOT: Path = Path(__file__).parent
PLG_METADATA_FILE: Path = DIR_PLUGIN_ROOT.resolve() / "metadata.txt"
# ############################################################################
# ########## Functions #############
# ##################################
def plugin_metadata_as_dict() -> dict:
"""Read plugin metadata.txt and return it as a Python dict.
Raises
------
IOError
If metadata.txt is not found.
Returns
-------
dict
Metadata sections as nested dictionaries.
"""
config = ConfigParser()
if PLG_METADATA_FILE.is_file():
config.read(PLG_METADATA_FILE.resolve(), encoding="UTF-8")
return {s: dict(config.items(s)) for s in config.sections()}
else:
raise IOError("Plugin metadata.txt not found at: %s" % PLG_METADATA_FILE)
# ############################################################################
# ########## Variables #############
# ##################################
# store full metadata.txt as dict into a var
__plugin_md__: dict = plugin_metadata_as_dict()
__author__: str = __plugin_md__.get("general").get("author")
__copyright__: str = "2024 - {0}, {1}".format(date.today().year, __author__)
__email__: str = __plugin_md__.get("general").get("email")
__icon_path__: Path = DIR_PLUGIN_ROOT.resolve() / __plugin_md__.get("general").get("icon")
__keywords__: list = [
t.strip() for t in __plugin_md__.get("general").get("repository").split("tags")
]
__license__: str = "GPLv2+"
__summary__: str = "{}\n{}".format(
__plugin_md__.get("general").get("description"),
__plugin_md__.get("general").get("about"),
)
__title__: str = __plugin_md__.get("general").get("name")
__title_clean__: str = "".join(e for e in __title__ if e.isalnum())
__uri_homepage__: str = __plugin_md__.get("general").get("homepage")
__uri_repository__: str = __plugin_md__.get("general").get("repository")
__uri_tracker__: str = __plugin_md__.get("general").get("tracker")
__uri__: str = __uri_repository__
__version__: str = __plugin_md__.get("general").get("version")
__version_info__: tuple = tuple(
[int(num) if num.isdigit() else num for num in __version__.replace("-", ".", 1).split(".")]
)
# #############################################################################
# ##### Main #######################
# ##################################
if __name__ == "__main__":
plugin_md = plugin_metadata_as_dict()
assert isinstance(plugin_md, dict)
assert plugin_md.get("general").get("name") == __title__
print(f"Plugin: {__title__}")
print(f"By: {__author__}")
print(f"Version: {__version__}")
print(f"Description: {__summary__}")
print(f"Icon: {__icon_path__}")
print(
"For: %s > QGIS > %s"
% (
plugin_md.get("general").get("qgisminimumversion"),
plugin_md.get("general").get("qgismaximumversion"),
)
)
print(__title_clean__)