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