Moved into src.
[drlaunch] / src / apps.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
27 from gettext import translation
28 #import locale
29
30 #from xdg.IconTheme import getIconPath
31
32 appdir="/usr/share/applications/hildon"
33
34 def readOneFn(fn):
35     global appdir
36
37     fn2=appdir + '/' + fn
38
39     f=open(fn2, 'rt')
40
41     ret={
42         'id':       fn[:-8],
43         'name':     None,
44         'exec':     None,
45         'icon':     None,
46         'iconpath': None,
47         'domain':   None,
48         }
49     inde=False
50     for line in f:
51         line=line.strip()
52         if line=='[Desktop Entry]':
53             inde=True
54             continue
55
56         if inde==False:
57             continue
58
59         # Reached another block
60         if line.startswith('[') and inde:
61             break
62
63         elif line.startswith('Name='):
64             l=line[5:]
65             ret['name']=l
66         elif line.startswith('Exec='):
67             l=line[5:]
68             ret['exec']=l
69         elif line.startswith('Icon='):
70             l=line[5:]
71             ret['icon']=l
72             # ret['iconpath']=getIconPath(l)
73         elif line.startswith('X-Text-Domain='):
74             l=line[14:]
75             ret['domain']=l
76
77     if ret['domain']!=None:
78         try:
79             c=translation(ret['domain'])
80         except IOError, e:
81             c=None
82
83         if c!=None:
84             ret['name0']=ret['name']
85             ret['name']=c.gettext(ret['name0'])
86
87     return(ret)
88
89 def readOne(name):
90     fn=name + ".desktop"
91
92     ret=readOneFn(fn)
93
94     return(ret)
95
96 def scan():
97     global appdir
98
99     files=os.listdir(appdir)
100
101     ret={}
102
103     for f in files:
104         if not f.endswith('.desktop'):
105             continue
106         if f.startswith('catorise-'):
107             continue
108         dt=readOneFn(f)
109         t=f[:-8]
110         ret[t]=dt
111
112     return(ret)
113
114 if __name__=="__main__":
115     #locale.setlocale(locale.LC_ALL, '')
116     print scan()
117
118 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent:
119