-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTardisUtil.py
60 lines (43 loc) · 1.59 KB
/
TardisUtil.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import configparser
import os
from plugnplay import Interface
class TardisOptions:
"""
Class for handling options.
Has a getter and setter for every property and saves changes automatically.
Current keys are:
- start_time
"""
def __init__(self, optionFileName=".tardisrc"):
self.config = TardisOptions.generateDefaultConfig()
#Make path
home_dir = os.path.expanduser("~")
self._optionFilePath = os.path.join(home_dir, optionFileName)
#Try to load config file
filesLoaded = self.config.read(self._optionFilePath)
if len(filesLoaded) == 0: # No option file found
self._saveOptionFile()
self.options = self.config['TardisDiff']
def isStartTimeAuto(self):
return self._getOption('start_time') == 'auto'
def getStartTime(self):
return self._getOption('start_time')
def setStartTime(self, start_time):
self._setOption('start_time', start_time)
def _setOption(self, option_name, option_value):
self.options[option_name] = option_value
self._saveOptionFile()
def _getOption(self, option_name):
return self.options[option_name]
def _saveOptionFile(self):
with open(self._optionFilePath, 'w') as configFile:
self.config.write(configFile)
@staticmethod
def generateDefaultConfig():
config = configparser.ConfigParser()
config['TardisDiff'] = {'start_time': 'auto',
}
return config
class TimeSubmitter(Interface):
def submit_time(self, duration):
pass