aboutsummaryrefslogtreecommitdiff
blob: 89c86d565970fc1a1e0cff8de3baa16b154a7858 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""Abstraction of a tatt configuration"""

import os
import sys

# from configobj
from configobj import ConfigObj
from validate  import Validator
# To access the specfile:
from pkg_resources import resource_filename

# resource_filename will give us platform-independent access to the specfile
specfile = resource_filename('tatt', 'dot-tatt-spec')

# this validator will also do type conversion according to the spec file!
class tattConfig (ConfigObj):
    """Nothing special here, just a checked ConfigObj"""
    def __init__(self):
        # Read the config from ~/.tatt and create ConfigObj
        ConfigObj.__init__(self, os.path.join(os.path.expanduser("~"), ".tatt"), configspec=specfile)

        # Validate against the specfile
        validator = Validator()
        result = self.validate(validator)

        if result != True:
            print ("Config file validation failed!")
            print ("The following items could not be parsed")
            for k in result.keys():
                if result[k] == False:
                    print (k)
            sys.exit(1)