Skip to content
Snippets Groups Projects
Commit f1bc086f authored by David Trattnig's avatar David Trattnig
Browse files

Refact: Migrate config parsing

parent 9b1ffdb3
No related branches found
No related tags found
1 merge request!3Liquidsoap 2 migration
...@@ -22,9 +22,7 @@ ...@@ -22,9 +22,7 @@
# Read INI File # # Read INI File #
################# #################
debug = ref(false)
debug = false
def read_ini(file) def read_ini(file)
# read ini file # read ini file
...@@ -33,20 +31,20 @@ def read_ini(file) ...@@ -33,20 +31,20 @@ def read_ini(file)
settings_map = list.map(string.split(separator="="), settings_file_content) settings_map = list.map(string.split(separator="="), settings_file_content)
def filter_pair(setting_pair) = def filter_pair(setting_pair) =
if debug then if !debug then
print(" +++ IN FILTER_PAIR +++") print(" +++ IN FILTER_PAIR +++")
end end
# get head of settings_pair # get head of settings_pair
setting_name = list.hd(default="", setting_pair) setting_name = list.hd(default="", setting_pair)
if debug then if !debug then
print(" -- setting_name:") print(" -- setting_name:")
print(setting_name) print(setting_name)
end end
# settings in ini are with '"', so read them with high comma # settings in ini are with '"', so read them with high comma
setting_unfiltered = list.nth(default="", setting_pair, 1) setting_unfiltered = list.nth(default="", setting_pair, 1)
if debug then if !debug then
print(" -- setting_unfiltered:") print(" -- setting_unfiltered:")
print(setting_unfiltered) print(setting_unfiltered)
end end
...@@ -54,13 +52,13 @@ def read_ini(file) ...@@ -54,13 +52,13 @@ def read_ini(file)
# filter high comma out. why the hell comes an array ["1", setting] returned? # filter high comma out. why the hell comes an array ["1", setting] returned?
# the filter patterns are perl regex # the filter patterns are perl regex
setting = string.extract(pattern='"(.*)"', setting_unfiltered) setting = string.extract(pattern='"(.*)"', setting_unfiltered)
if debug then if !debug then
print(" -- setting ( after string.extract):") print(" -- setting ( after string.extract):")
print(setting['1']) print(setting[1])
end end
filtered_pair = [(setting_name, setting['1'])] filtered_pair = [(setting_name, setting[1])]
if debug then if !debug then
print(" -- filter_pair returning: --") print(" -- filter_pair returning: --")
print(filtered_pair) print(filtered_pair)
end end
...@@ -70,7 +68,7 @@ def read_ini(file) ...@@ -70,7 +68,7 @@ def read_ini(file)
end end
def filter_map(filled_list, next_element) = def filter_map(filled_list, next_element) =
# if debug then # if !debug then
# print(" +++ IN FILTER_MAP +++") # print(" +++ IN FILTER_MAP +++")
# print(" .. length of filled_list: ") # print(" .. length of filled_list: ")
# print(list.length(filled_list)) # print(list.length(filled_list))
...@@ -80,7 +78,7 @@ def read_ini(file) ...@@ -80,7 +78,7 @@ def read_ini(file)
# the normal case: settingname and its setting # the normal case: settingname and its setting
if list.length(next_element) >= 2 then if list.length(next_element) >= 2 then
if debug then if !debug then
print(" ===> LENGTH list to insert in settings_list is equal TWO! <===") print(" ===> LENGTH list to insert in settings_list is equal TWO! <===")
print(" -- next_element") print(" -- next_element")
print(next_element) print(next_element)
...@@ -93,7 +91,7 @@ def read_ini(file) ...@@ -93,7 +91,7 @@ def read_ini(file)
list.append(setting_pair, filled_list) list.append(setting_pair, filled_list)
else else
if list.length(next_element) >= 1 then if list.length(next_element) >= 1 then
if debug then if !debug then
print(" ===> LENGTH of list to insert in settings_list is equal ONE! <===") print(" ===> LENGTH of list to insert in settings_list is equal ONE! <===")
print(" -- next_element") print(" -- next_element")
print(next_element) print(next_element)
...@@ -103,7 +101,7 @@ def read_ini(file) ...@@ -103,7 +101,7 @@ def read_ini(file)
list.append([(list.hd(default="",next_element), "")], filled_list) list.append([(list.hd(default="",next_element), "")], filled_list)
else else
if debug then if !debug then
print(" ===> LENGTH of list to insert in settings_list is greater then two or less than one <===") print(" ===> LENGTH of list to insert in settings_list is greater then two or less than one <===")
print(" -- next_element") print(" -- next_element")
print(next_element) print(next_element)
...@@ -134,14 +132,14 @@ def read_ini(file) ...@@ -134,14 +132,14 @@ def read_ini(file)
#settings = list.fold(filter_map, [], settings_map) #settings = list.fold(filter_map, [], settings_map)
if debug then if !debug then
print(settings) print(settings)
end end
settings settings
end end
if debug then if !debug then
ini = read_ini("/etc/aura/engine-core.ini") ini = read_ini("/etc/aura/engine-core.ini")
print(ini) print(ini)
......
#!/usr/bin/env liquidsoap
#
# Aura Engine (https://gitlab.servus.at/aura/engine)
#
# Copyright (C) 2017-now() - The Aura Engine Team.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
%include "../src/readini.liq"
set("log.file.path", "../logs/<script>.log")
set("log.level", 5)
set("ffmpeg.log.level", 5)
debug := true
config = "../config/sample-production.engine-core.ini"
print("Config file used: #{config}")
ini = read_ini(config)
log("Read configuration:\n${ini}")
print(ini)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment