@@ -48,11 +48,17 @@ def __init__(self):
48
48
self .patterns = {}
49
49
self .warned = False
50
50
51
+ # We'll only handle `fields` or `keep_fields`, but not both.
52
+ if self .config ['fields' ] and self .config ['keep_fields' ]:
53
+ self ._log .warn (u'cannot blacklist and whitelist at the same time' )
54
+
55
+ # Blacklist mode.
51
56
if self .config ['fields' ]:
52
57
self .validate_config ('fields' )
53
58
for field in self .config ['fields' ].as_str_seq ():
54
59
self .set_pattern (field )
55
60
61
+ # Whitelist mode.
56
62
elif self .config ['keep_fields' ]:
57
63
self .validate_config ('keep_fields' )
58
64
@@ -61,15 +67,17 @@ def __init__(self):
61
67
continue
62
68
self .set_pattern (field )
63
69
64
- # These fields should be preserved
70
+ # These fields should always be preserved.
65
71
for key in ('id' , 'path' , 'album_id' ):
66
72
if key in self .patterns :
67
73
del self .patterns [key ]
68
74
69
75
def validate_config (self , mode ):
70
- """Check if fields written in config are correct."""
71
- if self .config ['fields' ] and self .config ['keep_fields' ]:
72
- self ._log .warn (u'cannot blacklist and whitelist at the same time' )
76
+ """Check whether fields in the configuration are valid.
77
+
78
+ `mode` should either be "fields" or "keep_fields", indicating
79
+ the section of the configuration to validate.
80
+ """
73
81
for field in self .config [mode ].as_str_seq ():
74
82
if field not in MediaFile .fields ():
75
83
self ._log .error (u'invalid field: {0}' , field )
0 commit comments