File: plugin-index.py

package info (click to toggle)
pyglossary 5.0.9-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,896 kB
  • sloc: python: 46,165; sh: 308; javascript: 100; xml: 42; makefile: 28
file content (73 lines) | stat: -rwxr-xr-x 1,647 bytes parent folder | download
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
#!/usr/bin/python3

import json
import sys
from os.path import abspath, dirname, join
from pathlib import Path
from typing import Any

rootDir = dirname(dirname(abspath(__file__)))
sys.path.insert(0, rootDir)

from pyglossary.core import userPluginsDir
from pyglossary.flags import DEFAULT_NO
from pyglossary.glossary import Glossary

Glossary.init(
	usePluginsJson=False,
	skipDisabledPlugins=False,
)

userPluginsDirPath = Path(userPluginsDir)
plugins = [
	p for p in Glossary.plugins.values() if userPluginsDirPath not in p.path.parents
]

data = []
for p in plugins:
	canRead = p.canRead
	canWrite = p.canWrite
	item: dict[str, Any] = {
		"module": p.module.__name__,
		"lname": p.lname,
		"name": p.name,
		"description": p.description,
		"extensions": p.extensions,
		"singleFile": p.singleFile,
		"optionsProp": {name: opt.toDict() for name, opt in p.optionsProp.items()},
		"canRead": canRead,
		"canWrite": canWrite,
	}
	if p.sortOnWrite != DEFAULT_NO:
		item["sortOnWrite"] = p.sortOnWrite
	if p.sortKeyName:
		item["sortKeyName"] = p.sortKeyName
	if canRead:
		item["readOptions"] = p.getReadOptions()
	if canWrite:
		item["writeOptions"] = p.getWriteOptions()
	if not p.enable:
		item["enable"] = False
	if p.readDepends:
		item["readDepends"] = p.readDepends
	if p.writeDepends:
		item["writeDepends"] = p.writeDepends
	if p.readCompressions:
		item["readCompressions"] = p.readCompressions

	data.append(item)


jsonText = json.dumps(
	data,
	sort_keys=False,
	indent="\t",
	ensure_ascii=True,
)
with open(
	join(rootDir, "plugins-meta", "index.json"),
	mode="w",
	encoding="utf-8",
	newline="\n",
) as _file:
	_file.write(jsonText)