-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
executable file
·116 lines (94 loc) · 3.61 KB
/
settings.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# -*- coding: iso-8859-1 -*-
# Skapat av Christian Davén 2004
import os
import os.path
import sys
import error
import configfileparser
from i18n import *
__filename = "settings"
timetablefile = os.path.join(os.getcwd(), "timetable")
daybegin = None
dayend = None
lastweekday = 4
eventtype_examination = ["Salsskrivning", "Kontrollskrivning", "Dugga", "Tentamen"]
event_export_category = "KTHTimeTable"
language = "en"
preferred_system = "Daisy"
publish_userid = ""
publish = False
maximized = False
size_x = -1
size_y = -1
# -----------------------------------------------------------
def _setDefaultCalendarValues():
global daybegin, dayend, lastweekday
import calendar
daybegin = calendar.Time("080000")
dayend = calendar.Time("200000")
lastweekday = calendar.FRI
def load():
global __filename, language
setLanguage(language)
loadFromFile(__filename)
def loadFromFile(filename):
global daybegin, dayend, lastweekday, event_export_category, language
global preferred_system, publish_userid, publish
global maximized, size_x, size_y
config = configfileparser.ConfigParserX()
try:
config.readfp(file(__filename))
except IOError:
sys.stderr.write("Settings missing, using default values.\n")
_setDefaultCalendarValues()
return
try:
language = config.get("main", "language")
setLanguage(language)
except (error.DataError, IOError):
sys.stderr.write("Settings missing or invalid, using default values.\n")
try:
publish = config.getboolean("main", "publish")
publish_userid = config.get("main", "publish_userid")
except error.DataError:
sys.stderr.write("Settings missing or invalid, using default values.\n")
import calendar
try:
daybegin = calendar.Time(config.get("main", "daybegin"))
dayend = calendar.Time(config.get("main", "dayend"))
lastweekday = config.getint("main", "lastweekday")
except (error.DataError, ValueError):
_setDefaultCalendarValues()
sys.stderr.write("Settings missing or invalid, using default values.\n")
try:
preferred_system = config.get("main", "preferred_system")
event_export_category = config.get("main", "event_export_category")
except (error.DataError, IOError):
sys.stderr.write("Settings missing or invalid, using default values.\n")
try:
maximized = config.getboolean("main", "maximized")
size_x = config.getint("main", "size_x")
size_y = config.getint("main", "size_y")
except (error.DataError, IOError):
sys.stderr.write("Settings missing or invalid, using default values.\n")
def save():
global daybegin, dayend, lastweekday, event_export_category, language
global preferred_system, __filename, publish_userid, publish
global maximized, size_x, size_y
config = configfileparser.ConfigParserX()
config.add_section("main")
config.set("main", "daybegin", str(daybegin))
config.set("main", "dayend", str(dayend))
config.set("main", "lastweekday", str(lastweekday))
config.set("main", "event_export_category", event_export_category)
config.set("main", "language", language)
config.set("main", "preferred_system", preferred_system)
config.set("main", "publish_userid", publish_userid)
config.set("main", "publish", str(publish))
config.set("main", "maximized", str(maximized))
config.set("main", "size_x", str(size_x))
config.set("main", "size_y", str(size_y))
try:
config.write(file(__filename, "w+"))
except IOError:
raise error.WriteError(U_("Could not write to"), __filename)