Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
feat(config): Detect unexpected config items from config files.
Browse files Browse the repository at this point in the history
  • Loading branch information
TerryGeng committed Jan 22, 2022
1 parent 9ba2720 commit 37666c7
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 96 deletions.
168 changes: 86 additions & 82 deletions configuration.default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,70 +18,73 @@
# ========================================================

[server]
certificate =
channel =
host = 127.0.0.1
port = 64738
password =
channel =
port = 64738
tokens =
certificate =


[bot]
username = botamusique
comment = "Hi, I'm here to play radio, local music or youtube/soundcloud music. Have fun!"
<<<<<<< HEAD
admin =
allow_other_channel_message = False
allow_private_message = True
announce_current_music = True
auto_check_update = True
autoplay_length = 5
avatar =
# default volume from 0 to 1.
=======
>>>>>>> 5d58f6d (fix(config): Reorganize)
volume = 0.1
stereo = True
bandwidth = 96000
playback_mode = one-shot
autoplay_length = 5
clear_when_stop_in_oneshot = False
target_version = git
admin =
music_folder = music_folder/
tmp_folder = /tmp/
pip3_path = venv/bin/pip
auto_check_update = True
logfile =
tmp_folder_max_size = 10
comment = "Hi, I'm here to play radio, local music or youtube/soundcloud music. Have fun!"
database_path =
delete_allowed = True
download_attempts = 2
ignored_folders = tmp
ducking = False
ducking_threshold = 3000
ducking_volume = 0.05
ignored_files = Thumbs.db
announce_current_music = True
allow_other_channel_message = False
allow_private_message = True
save_music_library = True
ignored_folders = tmp
language = en_US
logfile =
max_track_duration = 60
max_track_playlist = 20
music_database_path =
music_folder = music_folder/
pip3_path = venv/bin/pip
playback_mode = one-shot
redirect_stderr = True
refresh_cache_on_startup = True
save_music_library = True
save_playlist = True
max_track_playlist = 20
max_track_duration = 60
ducking = False
ducking_volume = 0.05
ducking_threshold = 3000
stereo = True
target_version = git
tmp_folder = /tmp/
tmp_folder_max_size = 10
username = botamusique
volume = 0.1
when_nobody_in_channel = nothing
youtube_query_cookie =

[webinterface]
access_address = http://127.0.0.1:8181
auth_method = none
enabled = False
flask_secret = ChangeThisPassword
is_web_proxified = True
listening_addr = 127.0.0.1
listening_port = 8181
web_logfile =
auth_method = none
user =
password =
max_attempts = 10
access_address = http://127.0.0.1:8181
flask_secret = ChangeThisPassword
upload_enabled = True
max_upload_file_size = 30M
password =
upload_enabled = True
user =
web_logfile =

[debug]
ffmpeg = False
mumble_connection = False
redirect_ffmpeg_log = True
mumbleConnection = False
youtube_dl = False

[radio]
Expand All @@ -91,64 +94,65 @@ radiobrony = http://62.210.138.34:8000/live "Brony music of a friend"
jazz = http://jazz-wr04.ice.infomaniak.ch/jazz-wr04-128.mp3 "Jazz Yeah !"

[youtube_dl]
cookie_file =
source_address =
cookiefile =
user_agent =

[commands]
add_from_shortlist = shortlist, sl
add_tag = addtag
add_webinterface_user = webuseradd
change_user_password = password
clear = clear
command_symbol = !:!
split_username_at_space = False
current_music = np, now
delete_from_library = delete
drop_database = dropdatabase
ducking = duck
ducking_threshold = duckthres
ducking_volume = duckv
find_tagged = findtagged, ft
help = help
joinme = joinme
kill = kill
last = last
list_file = listfile
list_webinterface_user = webuserlist
mode = mode
pause = pause
play = p, play
play_file = file, f
play_file_match = filematch, fm
play_url = url
play_radio = radio
play_playlist = playlist
rb_query = rbquery
play_radio = radio
play_tag = tag
play_url = url
queue = queue
random = random
rb_play = rbplay
yt_search = ysearch
yt_play = yplay
help = help
pause = pause
play = p, play
stop = stop
rb_query = rbquery
remove = rm
clear = clear
remove_tag = untag
remove_webinterface_user = webuserdel
repeat = repeat
requests_webinterface_access = web
rescan = rescan
search = search
skip = skip
last = last
current_music = np, now
volume = volume
kill = kill
split_username_at_space = False
stop = stop
stop_and_getout = oust
joinme = joinme
queue = queue
repeat = repeat
random = random
version = version
mode = mode
update = update
list_file = listfile
play_tag = tag
add_tag = addtag
remove_tag = untag
find_tagged = findtagged, ft
search = search
delete_from_library = delete
add_from_shortlist = shortlist, sl
user_ban = userban
user_unban = userunban
url_ban = urlban
url_ban_list = urlbanlist
url_unban = urlunban
url_whitelist = urlwhitelist, urlw
url_unwhitelist = urlunwhitelist, urlunw
url_whitelist = urlwhitelist, urlw
url_whitelist_list = urlwhitelistlist, urlwls
ducking = duck
ducking_threshold = duckthres
ducking_volume = duckv
drop_database = dropdatabase
rescan = rescan
requests_webinterface_access = web
list_webinterface_user = webuserlist
add_webinterface_user = webuseradd
remove_webinterface_user = webuserdel
change_user_password = password
user_ban = userban
user_unban = userunban
version = version
volume = volume
yt_play = yplay
yt_search = ysearch

6 changes: 3 additions & 3 deletions configuration.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ port = 64738
# [debug] stores some debug settings.
[debug]
#ffmpeg = False # Set ffmpeg to True if you want to display DEBUG level log of ffmpeg.
#mumbleConnection = False # Set to True if you need to debug mumble connection (pymumble lib)
#mumble_connection = False # Set to True if you need to debug mumble connection (pymumble lib)
#youtube_dl = False # Set to True if you need debug log from youtube-dl

# [radio] is a list of default radio stations.
Expand All @@ -193,8 +193,8 @@ port = 64738
[youtube_dl]
# source_address , use '::' to force ipv6, "0.0.0.0" to force ipv4, or put the ip addresse you want to use.
# source_address = '::'
# cookiefile , path of the cookie file (usefull if you reach youtube limits https://github.com/ytdl-org/youtube-dl#http-error-429-too-many-requests-or-402-payment-required)
# cookiefile = '/tmp/cooke_ydl'
# cookie_file , path of the cookie file (usefull if you reach youtube limits https://github.com/ytdl-org/youtube-dl#http-error-429-too-many-requests-or-402-payment-required)
# cookie_file = '/tmp/cooke_ydl'
# user-agent allow the user to force the user-agent of youtube-dl
# user-agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:87.0) Gecko/20100101 Firefox/87.0"

Expand Down
4 changes: 2 additions & 2 deletions media/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ def _download(self):
'verbose': var.config.getboolean('debug', 'youtube_dl')
}

cookie = var.config.get('youtube_dl', 'cookiefile', fallback=None)
cookie = var.config.get('youtube_dl', 'cookie_file', fallback=None)
if cookie:
ydl_opts['cookiefile'] = var.config.get('youtube_dl', 'cookiefile', fallback=None)
ydl_opts['cookiefile'] = var.config.get('youtube_dl', 'cookie_file', fallback=None)

user_agent = var.config.get('youtube_dl', 'user_agent', fallback=None)
if user_agent:
Expand Down
4 changes: 2 additions & 2 deletions media/url_from_playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def get_playlist_info(url, start_index=0, user=""):
'verbose': var.config.getboolean('debug', 'youtube_dl')
}

cookie = var.config.get('youtube_dl', 'cookiefile', fallback=None)
cookie = var.config.get('youtube_dl', 'cookie_file', fallback=None)
if cookie:
ydl_opts['cookiefile'] = var.config.get('youtube_dl', 'cookiefile', fallback=None)
ydl_opts['cookiefile'] = var.config.get('youtube_dl', 'cookie_file', fallback=None)

user_agent = var.config.get('youtube_dl', 'user_agent', fallback=None)
if user_agent:
Expand Down
31 changes: 24 additions & 7 deletions mumbleBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def __init__(self, args):

self.mumble = pymumble.Mumble(host, user=self.username, port=port, password=password, tokens=tokens,
stereo=self.stereo,
debug=var.config.getboolean('debug', 'mumbleConnection'),
debug=var.config.getboolean('debug', 'mumble_connection'),
certfile=certificate)
self.mumble.callbacks.set_callback(pymumble.constants.PYMUMBLE_CLBK_TEXTMESSAGERECEIVED, self.message_received)

Expand Down Expand Up @@ -798,11 +798,28 @@ def start_web_interface(addr, port):
# ======================

config = configparser.ConfigParser(interpolation=None, allow_no_value=True)
default_config = configparser.ConfigParser(interpolation=None, allow_no_value=True)
var.config = config
parsed_configs = config.read([util.solve_filepath('configuration.default.ini'), util.solve_filepath(args.config)],
encoding='utf-8')
if len(parsed_configs) == 0:
logging.error('Could not read configuration from file \"{}\"'.format(args.config))

if len(default_config.read(
util.solve_filepath('configuration.default.ini'),
encoding='utf-8')) == 0:
logging.error("Could not read default configuration file 'configuration.default.ini', please check"
"your installation.")
sys.exit()

if len(config.read(
[util.solve_filepath('configuration.default.ini'), util.solve_filepath(args.config)],
encoding='utf-8')) == 0:
logging.error(f'Could not read configuration from file "{args.config}"')
sys.exit()

extra_configs = util.check_extra_config(config, default_config)
if extra_configs:
extra_str = ", ".join([f"'[{k}] {v}'" for (k, v) in extra_configs])
logging.error(f'Unexpected config items {extra_str} defined in your config file. '
f'This is likely caused by a recent change in the names of config items, '
f'or the removal of obsolete config items. Please refer to the changelog.')
sys.exit()

# ======================
Expand Down Expand Up @@ -845,9 +862,9 @@ def start_web_interface(addr, port):

sanitized_username = "".join([x if x.isalnum() else "_" for x in username])
var.settings_db_path = args.db if args.db is not None else util.solve_filepath(
config.get("bot", "database_path", fallback=f"settings-{sanitized_username}.db"))
config.get("bot", "database_path", fallback="") or f"settings-{sanitized_username}.db")
var.music_db_path = args.music_db if args.music_db is not None else util.solve_filepath(
config.get("bot", "music_database_path", fallback="music.db"))
config.get("bot", "music_database_path", fallback="") or "music.db")

var.db = SettingsDatabase(var.settings_db_path)

Expand Down
13 changes: 13 additions & 0 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,3 +561,16 @@ def clear_tmp_folder(path, size):
except (FileNotFoundError, OSError):
continue
return


def check_extra_config(config, template):
extra = []

for key in config.sections():
if key in ['radio']:
continue
for opt in config.options(key):
if not template.has_option(key, opt):
extra.append((key, opt))

return extra

0 comments on commit 37666c7

Please sign in to comment.