File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+
3+ """Contains validating functions used to check whether valid values
4+ are given when changing preferencs. ValidationError is raised
5+ if value to be tested doesn't pass the test.
6+ """
7+
8+ import os
9+
10+ class ValidationError (Exception ):
11+ """Raised when validation fails"""
12+ pass
13+
14+ def music_dir (test ):
15+ """Checks whether `test` exists and is a directory.
16+
17+ Args:
18+ test(str): path to be tested.
19+
20+ Raises:
21+ ValidationError: if `test` doesn't exist or is not directory
22+ """
23+ if not os .path .isdir (test ):
24+ raise ValidationError ('"' + test + '"' + ' is not a directory' )
25+ if not os .path .exists (test ):
26+ raise ValidationError ('"' + test + '"' + ' doesn\' t exist' )
27+
28+
29+ VALIDATORS = {
30+ 'music_dir' : music_dir
31+ }
You can’t perform that action at this time.
0 commit comments