-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
plugin-generate.py
executable file
·39 lines (30 loc) · 1.04 KB
/
plugin-generate.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
#!/usr/bin/env python3
CONFIG_FILENAME = "plugin.cfg"
LOADER_FILENAME = "pkg/process/pluginloader.go"
plugins = []
replacements = ""
with open(CONFIG_FILENAME, "r") as config_file:
for line in config_file:
line = line.strip()
if line != "" and not line.startswith("#"):
replacement_split = line.split("=")
if len(replacement_split) > 1:
replacements += f"replace {replacement_split[0]} => {replacement_split[1]}\n"
line = replacement_split[0]
plugins.append(line)
loader = """// This file is autogenerated. Do not edit.
package process
"""
if len(plugins) > 0:
loader += "import (\n"
for plugin in plugins:
loader += f" _ \"{plugin}\"\n"
loader += ")\n"
with open(LOADER_FILENAME, "w") as loader_file:
loader_file.write(loader)
r = ""
with open("go.mod", "r") as go_mod_file:
go_mod = go_mod_file.read()
r += go_mod.replace("\ngo ", replacements + "\ngo ") + "\n"
with open("go.mod", "w") as go_mod_file:
go_mod_file.write(r)