Added version to config.py
[drlaunch] / 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 wifieye.
7 #
8 # wifieye 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 # wifieye 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 wifieye.  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 os
26 import pickle
27
28 version = "0.1"
29
30 try:
31     from glib import get_user_config_dir
32 except:
33     def get_user_config_dir():
34         home=os.environ['HOME']
35         if home=='':
36             home="/home/user"
37         cfg="%s/.config" % (home)
38
39         return(cfg)
40
41 size = 2
42 iconsize = 64
43 iconspace = 42
44 apps=None
45
46 def setSize(sz):
47     global size
48
49     size=sz
50
51 def getSize():
52     global size
53
54     return(size)
55
56 def setApps(aps):
57     """ apps is a dictionary of (x,y)=>appname """
58     global apps
59
60     apps=aps
61
62 def getApps():
63     global apps
64
65     if apps==None:
66         tmp={
67             (0,0):  'rtcom-call-ui',
68             (0,1):  'rtcom-messaging-ui',
69             (1,0):  'browser',
70             (1,1):  'osso-addressbook',
71             }
72         setApps(tmp)
73
74     return(apps)
75
76 def ensure_dir():
77     dir0=get_user_config_dir()
78     dir=dir0+'/drlaunch'
79     if not os.path.exists(dir):
80         os.mkdir(dir)
81     if not os.path.isdir(dir):
82         raise Exception('Failed to ensure directory' + dir)
83
84     return(dir)
85
86 def get_config_fn():
87     dir=ensure_dir()
88     ret=dir + '/config'
89
90     return(ret)
91
92 def save():
93     fn=get_config_fn()
94     print "save", fn
95
96     dt={
97         'version':  1,
98         'size':     getSize(),
99         'apps':     getApps()
100         }
101
102     print "save:", dt
103
104     st=pickle.dumps(dt)
105     f=file(fn, 'w')
106     f.write(st)
107     f.close()
108
109 def load():
110     fn=get_config_fn()
111     print "load", fn
112
113     try:
114         f=file(fn, 'r')
115         st=f.read()
116         f.close()
117         dt=pickle.loads(st)
118     except:
119         return
120
121     print "load:", dt
122
123     setSize(dt['size'])
124     setApps(dt['apps'])
125
126 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent:
127