Change all hashbangs
[time-slider.git] / usr / share / time-slider / lib / time_slider / linux / timesliderconfig.py
1 #!/usr/bin/python3
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 import configparser
24 import sys
25 import time_slider.util as util
26
27 # Default config file name position
28 configfile = "/etc/time-slider/timesliderd.conf"
29
30 # Default values
31 default_properties = {
32     'application/time-slider': {
33         'zpool/emergency-level': 95,
34         'zpool/critical-level': 90,
35         'zpool/warning-level': 80,
36         'zfs/sep': '_',
37         'daemon/verbose': 'true',
38         'state': 'online',
39     },
40     'system/filesystem/zfs/auto-snapshot:monthly': {
41         'zfs/interval': 'months',
42         'zfs/period': 1,
43         'zfs/keep': 2,
44         'state': 'online',
45     },
46     'system/filesystem/zfs/auto-snapshot:weekly': {
47         'zfs/interval': 'days',
48         'zfs/period': 7,
49         'zfs/keep': 4,
50         'state': 'online',
51     },
52     'system/filesystem/zfs/auto-snapshot:daily': {
53         'zfs/interval': 'days',
54         'zfs/period': 1,
55         'zfs/keep': 6,
56         'state': 'online',
57     },
58     'system/filesystem/zfs/auto-snapshot:hourly': {
59         'zfs/interval': 'hours',
60         'zfs/period': 1,
61         'zfs/keep': 23,
62         'state': 'online',
63     },
64     'system/filesystem/zfs/auto-snapshot:frequent': {
65         'zfs/interval': 'minutes',
66         'zfs/period': 15,
67         'zfs/keep': 3,
68         'state': 'online',
69     },
70 }
71
72 class MyConfigParser(configparser.ConfigParser):
73     def __init__(self):
74         configparser.ConfigParser.__init__(self)
75
76         for section, content in default_properties.items():
77             if not self.has_section(section):
78                 self.add_section(section)
79             for k,v in content.items():
80                 self.set(section, k, str(v))
81
82 class Config:
83     def __init__(self):
84         self.config = MyConfigParser()
85         self.config.read(configfile)
86
87     def get(self, section, option):
88         try:
89             result = self.config.get(section, option)
90             util.debug('CONFIG: GET section %s, option %s with value %s\n' % (section, option, result), 1)
91             return result
92         except (configparser.NoOptionError, configparser.NoSectionError):
93             util.debug('CONFIG: NOTFOUND section %s, option %s\n' % (section, option), 1)
94             return ''
95
96     def sections(self):
97         return self.config.sections()
98
99 def configdump():
100     MyConfigParser().write(sys.stdout)