Skip to content

Commit 1a41f96

Browse files
tiesbasilfx
authored andcommitted
Use custom validator to validate transcode unsup.
* `transcode_unsupported` is now part of a Connection's settings instead of Provider * wrap `is_string_list` to return a lowercase list, and use this to validate.
1 parent 4fa9644 commit 1a41f96

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

subdaap/config.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from cStringIO import StringIO
22

33
from configobj import ConfigObj, flatten_errors
4-
from validate import Validator
4+
from validate import Validator, is_string_list
55

66
import logging
77

@@ -24,7 +24,7 @@
2424
synchronization interval = integer(min=1, default=1440)
2525
2626
transcode = option("no", "unsupported", "all", default="no")
27-
transcode unsupported = list(default=list("flac"))
27+
transcode unsupported = lowercase_string_list(default=list("flac"))
2828
2929
[Daap]
3030
interface = string(default="0.0.0.0")
@@ -52,6 +52,15 @@
5252
""" % CONFIG_VERSION
5353

5454

55+
def lowercase_string_list(value, min=None, max=None):
56+
"""
57+
Custom ConfigObj validator that returns a list of lowercase
58+
items.
59+
"""
60+
validated_string_list = is_string_list(value, min, max)
61+
return [x.lower() for x in validated_string_list]
62+
63+
5564
def get_config(config_file):
5665
"""
5766
Parse the config file, validate it and convert types. Return a dictionary
@@ -62,7 +71,7 @@ def get_config(config_file):
6271
config = ConfigObj(config_file, configspec=specs)
6372

6473
# Create validator
65-
validator = Validator()
74+
validator = Validator({'lowercase_string_list': lowercase_string_list})
6675

6776
# Convert types and validate file
6877
result = config.validate(validator, preserve_errors=True, copy=True)
@@ -79,10 +88,6 @@ def get_config(config_file):
7988
"The following section was missing: %s." % (
8089
", ".join(section_list)))
8190

82-
# Post-process values
83-
config["Provider"]["item transcode unsupported"] = [
84-
x.lower() for x in config["Provider"]["item transcode unsupported"]]
85-
8691
# For now, no automatic update support.
8792
if config["version"] != CONFIG_VERSION:
8893
logger.warning(

0 commit comments

Comments
 (0)