Rename
[maegirls] / trunk / src / config.py
1 #!/usr/bin/env python
2 # coding=UTF-8
3
4 # Copyright (C) 2010 Stefanos Harhalakis
5 #
6 # This file is part of mydays.
7 #
8 # mydays is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # mydays is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with mydays.  If not, see <http://www.gnu.org/licenses/>.
20 #
21 # $Id: 0.py 2265 2010-02-21 19:16:26Z v13 $
22
23 __version__ = "$Id: 0.py 2265 2010-02-21 19:16:26Z v13 $"
24
25 import pickle
26 import time
27 import algo
28
29 fn="/home/user/.maedays"
30
31 defaults={
32     'cycle':    28,
33     'day0':     algo.today(),
34     }
35
36 def store(name, cycle, day0):
37     # Load old
38     all=loadAll()
39     # Override
40     all[name]={
41         'cycle':    cycle,
42         'day0':     day0,
43         }
44
45     st=pickle.dumps(all)
46     f=file(fn, "w")
47     f.write(st)
48     f.close()
49
50 def loadOne(name):
51     all=loadAll()
52     if all.has_key(name):
53         ret=all[name]
54     else:
55         ret=defaults
56
57     return(ret)
58
59 def loadAll():
60     try:
61         f=file(fn, "r")
62         st=f.read()
63         f.close()
64         ret=pickle.loads(st)
65     except:
66         ret={}
67
68     return(ret)
69
70 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent:
71