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