Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
engine-core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
engine-core
Commits
f1bc086f
Commit
f1bc086f
authored
2 years ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
Refact: Migrate config parsing
parent
9b1ffdb3
No related branches found
No related tags found
1 merge request
!3
Liquidsoap 2 migration
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/readini.liq
+14
-16
14 additions, 16 deletions
src/readini.liq
tests/test_config.liq
+32
-0
32 additions, 0 deletions
tests/test_config.liq
with
46 additions
and
16 deletions
src/readini.liq
+
14
−
16
View file @
f1bc086f
...
@@ -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)
...
...
This diff is collapsed.
Click to expand it.
tests/test_config.liq
0 → 100755
+
32
−
0
View file @
f1bc086f
#!/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)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment