-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_settings_file.py
61 lines (47 loc) · 1.7 KB
/
generate_settings_file.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
import jinja2
import argparse
import os.path
parser = argparse.ArgumentParser(
description="Generate settings.yaml or settings_slackbot.yaml"
)
parser.add_argument(
"application",
nargs="?",
choices=["settings.yaml", "settings_slackbot.yaml"],
default="settings.yaml",
help="The kind of settings file you want to create."
)
parsed = parser.parse_args()
choice = parsed.application
nattmusikk_configfile = os.path.join(os.path.dirname(__file__), "settings.yaml")
slackbot_configfile = os.path.join(os.path.dirname(__file__), "settings_slackbot.yaml")
choices = dict()
if choice == "settings.yaml":
# SOCKETFILE
print("Path to the socket you've configured LiquidSoap to open:")
choices['socketfile'] = input("> ")
# LIQUIDSOAP_VAR_NAME
print("Name of the interactive.bool variable in LiquidSoap:")
choices['liquidsoap_var_name'] = input("> ")
# SLACK_CHANNEL
print("On which channel in Slack should messages be posted?")
choices['slack_channel'] = input("> ")
else:
# SLACK
print("Slack API Token?")
choices['slack_token'] = input("> ")
# LOGFILE
print("Where would you like the logfile to be?")
print("Must be writable by the user SlackBot will run as.")
choices['logfile'] = input("> ")
print("Generating the file...")
# Generate the files!
env = jinja2.Environment(loader=jinja2.FileSystemLoader('templates'))
if choice == "settings.yaml":
template = env.get_template("settings.yaml")
with open(nattmusikk_configfile, "w") as f:
f.write(template.render(**choices))
else:
template = env.get_template("settings_slackbot.yaml")
with open(slackbot_configfile, "w") as f:
f.write(template.render(**choices))