Skip to content
Snippets Groups Projects
Commit d517f333 authored by TH's avatar TH
Browse files

Config file generator updated to support new single config file to rule them all.

parent e48906e9
Branches
No related tags found
No related merge requests found
import os.path
import os
import copy
import json
def write_default_file(fname, description, content, existing_inputs=None, **inputs):
......@@ -24,6 +27,132 @@ def write_default_file(fname, description, content, existing_inputs=None, **inpu
return inputs
def ask_overwrite(fname, content):
overwrite = True
if os.path.exists(fname):
overwrite = input(f'Overwrite remote_config.json (y/n)? ') == 'y'
if overwrite:
print(f'Overwriting {fname}...')
print(json.dumps(content, indent=2))
with open(fname, 'w') as f:
f.write(json.dumps(content, indent=2))
print('Done.')
else:
print(f'Did not change {fname}.')
org = input('InfluxDB Organisation? ')
bucket = input('InfluxDB Bucket? ')
token = input('InfluxDB Token? ')
measurement = input('InfluxDB Measurement? ')
print('Remote URL example: https://influxdb.yourdomain.name')
remote_url = input('Remote InfluxDB URL? ')
remote_influx_instances = {
"local": {
"enabled": True,
"bucket": bucket,
"org": org,
"token": token,
"url": remote_url, # https://influxdb.yourdomain.name, for example
"measurement": measurement
}
}
print('Remote control URL example: https://control.yourdomain.name')
remote_control_url = input('Remote control URL? ')
print('Remote image URL example: https://images.yourdomain.name')
remote_images_url = input('Remote images URL? ')
remote_config = {
"influxdb_instances": remote_influx_instances,
"amigos_control": remote_control_url,
"amigos_images": remote_images_url
}
ask_overwrite('remote_config.json', remote_config)
print('Local URL example: http://192.168.0.219:8086')
print('Note: This should use the server static IP on the local network that the Raspberry Pis connect to.')
local_url = input('Local InfluxDB URL? ')
print('Local control URL example: http://192.168.0.219:10000')
control_url = input('Local control URL? ')
print('Local image URL example: http://192.168.0.219:10001')
images_url = input('Local images URL? ')
influx_instances = copy.deepcopy(remote_influx_instances)
influx_instances['local']['url'] = local_url
#images_url = input('Local images URL? ')
print('Local Grafana URL example: http://localhost:3000')
print('Note: This is used for the management back end to update Grafana.')
local_grafana_url = input('Local Grafana URL? ')
grafana_api_key = input('Grafana API key? ')
print('Example port: 8000')
fastapi_port = int(input('FastAPI internal port? '))
print('Example port: 10000')
control_port = int(input('Control port? '))
print('Example port: 10001')
images_port = int(input('Images port? '))
print('Example Grafana display URL: https://grafana.yourdomain.name')
print('Note: This is used for making clickable links in the management interface.')
grafana_display_url = input('Grafana display URL? ')
print('Example dashboard camera URL: https://camera.yourdomain.name')
print('Note: This is used for embedding camera streams into the dashboards.')
camera_url = input('Dashboard camera URL? ')
# print('Example port: 8001')
# camera_port = int(input('Camera port? ')) # TODO: Add this to config, so image_streaming_wrangler can use it...
# TODO:
# manage_port = int(input('Management interface port? '))
# TODO:
# redirector_port = int(input('Main URL redirector port? '))
default_config = {
"influxdb_instances": influx_instances,
"amigos_control": control_url,
"amigos_images": images_url,
"grafana": local_grafana_url,
"grafana_api_key": grafana_api_key,
"fastapi_internal_port": fastapi_port,
"amigos_control_port": control_port,
"amigos_images_port": images_port,
"grafana_display_url": grafana_display_url,
"dash_camera_url": camera_url,
"general_dashboards": {
"Test_Homepage": {
"name": "Test_Homepage",
"folder": "Homepage",
"type": "printer_info",
"config": {
"list_tag": "machine",
"list_folder": "Machine Info"
}
},
},
"default_machine_folder": "Machine Info",
"machine_folders": {
#"Sim Makerbot Printer": "Overridden Simulated Printers"
},
"email": {
}
}
ask_overwrite('config.json', default_config)
write_default_file(
'email.ini',
'This allows emailing of pdf reports and alerts.',
......@@ -39,6 +168,7 @@ password='Enter email password: ',
smtp='Enter SMTP server hostname: '
)
"""
write_default_file(
'grafanaconfig.ini',
'This allows dashboard generation automatically for new printers.',
......@@ -130,4 +260,4 @@ enable = True
''',
existing_inputs=inputs
)
"""
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment