~kevang/mnemosyne-proj/grade-shortcuts-improvements

« back to all changes in this revision

Viewing changes to mnemosyne/mnemosyne/libmnemosyne/config.py

  • Committer: pbienst
  • Date: 2008-07-21 12:57:43 UTC
  • Revision ID: svn-v3-trunk0:e5e6b78b-db40-0410-9517-b98c64f8d2c1:trunk:461
Progress dump.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 
13
13
##############################################################################
14
14
#
 
15
# The configuration data needs to be accessed by many different parts of
 
16
# the library, so we hold it in a global variable.
 
17
#
 
18
##############################################################################
 
19
 
 
20
config = None
 
21
 
 
22
 
 
23
 
 
24
##############################################################################
 
25
#
15
26
# Config
16
27
#
17
28
##############################################################################
25
36
    ##########################################################################
26
37
 
27
38
    def __init__(self, basedir=None):
28
 
 
 
39
            
29
40
        self._config = {}
30
41
 
31
 
        # Set up basedir.
 
42
        # Determine basedir.
32
43
 
33
44
        if basedir == None:
34
45
 
52
63
            
53
64
            self.basedir = basedir
54
65
 
55
 
        # Load config file from basedir if it exists.
56
 
 
57
 
        if os.path.exists(os.path.join(self.basedir, "config")):
58
 
            self.load()
 
66
        # Fill basedir with configuration files. Do this even if basedir
 
67
        # already exists, because we might have added new files since the
 
68
        # last version.
 
69
 
 
70
        self.fill_basedir()
 
71
            
 
72
        # Load config file from basedir.
 
73
 
 
74
        self.load()
59
75
 
60
76
        # Set defaults, even if a previous file exists, because we might
61
77
        # have added new keys since the last version.
136
152
 
137
153
    ##########################################################################
138
154
    #
 
155
    # fill_basedir
 
156
    #
 
157
    ##########################################################################
 
158
 
 
159
    def fill_basedir(self)
 
160
 
 
161
        join   = os.path.join
 
162
        exists = os.path.exists
 
163
 
 
164
        # Create default paths.
 
165
 
 
166
        if not exists(self.basedir):
 
167
            os.mkdir(self.basedir)
 
168
 
 
169
        if not exists(join(self.basedir, "history")):
 
170
            os.mkdir(join(self.basedir, "history"))
 
171
 
 
172
        if not exists(join(self.basedir, "latex")):
 
173
            os.mkdir(join(self.basedir, "latex"))
 
174
 
 
175
        if not exists(join(self.basedir, "plugins")):
 
176
            os.mkdir(join(self.basedir, "plugins"))
 
177
 
 
178
        if not exists(join(self.basedir, "backups")):
 
179
            os.mkdir(join(self.basedir, "backups"))
 
180
 
 
181
        # Create default latex preamble and postamble.
 
182
 
 
183
        latexdir  = join(self.basedir,  "latex")
 
184
        preamble  = join(latexdir, "preamble")
 
185
        postamble = join(latexdir, "postamble")
 
186
        dvipng    = join(latexdir, "dvipng")
 
187
 
 
188
        if not os.path.exists(preamble):
 
189
            f = file(preamble, 'w')
 
190
            print >> f, "\\documentclass[12pt]{article}"
 
191
            print >> f, "\\pagestyle{empty}" 
 
192
            print >> f, "\\begin{document}"
 
193
            f.close()
 
194
 
 
195
        if not os.path.exists(postamble):
 
196
            f = file(postamble, 'w')
 
197
            print >> f, "\\end{document}"
 
198
            f.close()
 
199
 
 
200
        if not os.path.exists(dvipng):
 
201
            f = file(dvipng, 'w')
 
202
            print >> f, "dvipng -D 200 -T tight tmp.dvi" 
 
203
            f.close()
 
204
 
 
205
        # Create default config.py.
 
206
 
 
207
        configfile = os.path.join(self.basedir, "config.py")
 
208
        if not os.path.exists(configfile):
 
209
            f = file(configfile, 'w')
 
210
        print >> f, \
 
211
"""# Mnemosyne configuration file.
 
212
 
 
213
# Align question/answers to the left (True/False)
 
214
left_align = False
 
215
 
 
216
# Keep detailed logs (True/False).
 
217
keep_logs = True
 
218
 
 
219
# Upload server. Only change when prompted by the developers.
 
220
upload_server = "mnemosyne-proj.dyndns.org:80"
 
221
 
 
222
# Set to True to prevent you from accidentally revealing the answer
 
223
# when clicking the edit button.
 
224
only_editable_when_answer_shown = False
 
225
 
 
226
# The translation to use, e.g. 'de' for German (including quotes).
 
227
# See http://www.mnemosyne-proj.org/help/translations.php for a list
 
228
# of available translations.
 
229
# If locale is set to None, the system's locale will be used.
 
230
locale = None
 
231
 
 
232
# The number of daily backups to keep. Set to -1 for no limit.
 
233
backups_to_keep = 5
 
234
 
 
235
# The moment the new day starts. Defaults to 3 am. Could be useful to
 
236
# change if you are a night bird.
 
237
day_starts_at = 3"""
 
238
        f.close()
 
239
 
 
240
        
 
241
 
 
242
    ##########################################################################
 
243
    #
139
244
    # set_defaults
140
245
    #
141
246
    #   TODO: prune unneeded keys.
253
358
            os.symlink(new, old)
254
359
        except OSError:
255
360
            print "Backwards compatibility symlink creation failed."
 
361
 
 
362