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