1
1
from cStringIO import StringIO
2
2
3
3
from configobj import ConfigObj , flatten_errors
4
- from validate import Validator
4
+ from validate import Validator , is_string_list
5
5
6
6
import logging
7
7
24
24
synchronization interval = integer(min=1, default=1440)
25
25
26
26
transcode = option("no", "unsupported", "all", default="no")
27
- transcode unsupported = list (default=list("flac"))
27
+ transcode unsupported = lowercase_string_list (default=list("flac"))
28
28
29
29
[Daap]
30
30
interface = string(default="0.0.0.0")
52
52
""" % CONFIG_VERSION
53
53
54
54
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
+
55
64
def get_config (config_file ):
56
65
"""
57
66
Parse the config file, validate it and convert types. Return a dictionary
@@ -62,7 +71,7 @@ def get_config(config_file):
62
71
config = ConfigObj (config_file , configspec = specs )
63
72
64
73
# Create validator
65
- validator = Validator ()
74
+ validator = Validator ({ 'lowercase_string_list' : lowercase_string_list } )
66
75
67
76
# Convert types and validate file
68
77
result = config .validate (validator , preserve_errors = True , copy = True )
@@ -79,10 +88,6 @@ def get_config(config_file):
79
88
"The following section was missing: %s." % (
80
89
", " .join (section_list )))
81
90
82
- # Post-process values
83
- config ["Provider" ]["item transcode unsupported" ] = [
84
- x .lower () for x in config ["Provider" ]["item transcode unsupported" ]]
85
-
86
91
# For now, no automatic update support.
87
92
if config ["version" ] != CONFIG_VERSION :
88
93
logger .warning (
0 commit comments