1 # -*- coding: UTF-8 -*-
2 # vim: expandtab sw=4 ts=4 sts=4:
7 __author__
= 'Michal Čihař'
8 __email__
= 'michal@cihar.com'
10 Copyright © 2003 - 2009 Michal Čihař
12 This program is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License version 2 as published by
14 the Free Software Foundation.
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 if Wammu
.gammu_error
== None:
31 class Reader(Wammu
.Thread
.Thread
):
33 Generic thread for reading information from phone.
35 def FallBackStatus(self
):
37 Returns fall back status if real can not be obtained.
41 def GetNextStart(self
):
43 Initiates get next sequence.
45 Should be implemented in subclases.
47 raise Exception('Not implemented!')
49 def GetNext(self
, location
):
53 Should be implemented in subclases.
55 raise Exception('Not implemented!')
57 def Get(self
, location
):
61 Should be implemented in subclases.
63 raise Exception('Not implemented!')
67 Gets status of entries.
69 Should be implemented in subclases.
71 raise Exception('Not implemented!')
77 Should be implemented in subclases.
79 raise Exception('Not implemented!')
83 Sends entries to parent.
85 Should be implemented in subclases.
87 raise Exception('Not implemented!')
91 Main reader function, executed in thread.
97 total
= self
.GetStatus()
98 except gammu
.GSMError
, val
:
100 total
= self
.FallBackStatus()
109 self
.ShowProgress(100 * (total
- remain
) / total
)
116 value
= self
.GetNextStart()
119 value
= self
.GetNext(loc
)
121 loc
= value
['Location']
123 loc
= value
[0]['Location']
125 if type(value
) == list:
126 for i
in range(len(value
)):
127 value
[i
]['Synced'] = True
129 value
['Synced'] = True
131 except gammu
.ERR_UNKNOWN
:
133 _('Ignoring unknown'),
134 _('While reading, entry on location %d reported unknown error, ignoring it!') % loc
)
136 except gammu
.ERR_CORRUPTED
:
138 _('Ignoring corrupted'),
139 _('While reading, entry on location %d seems to be corrupted, ignoring it!') % loc
)
141 except gammu
.ERR_EMPTY
:
145 except (gammu
.ERR_NOTSUPPORTED
, gammu
.ERR_NOTIMPLEMENTED
):
149 self
.ShowProgress(100 * (total
- remain
) / total
)
154 value
= self
.Get(location
)
156 if type(value
) == list:
157 for i
in range(len(value
)):
158 value
[i
]['Synced'] = True
160 value
['Synced'] = True
163 # If we didn't know count and reached end, try some more entries
164 if remain
== 0 and guess
:
168 except gammu
.ERR_EMPTY
, val
:
170 # If we didn't know count and saw many empty entries, stop right now
171 if empty
>= Wammu
.configuration
.ReadInt('/Hacks/MaxEmptyGuess') and guess
:
173 # If we didn't read anything for long time, we bail out (workaround bad count reported by phone)
174 if empty
>= Wammu
.configuration
.ReadInt('/Hacks/MaxEmptyKnown') and remain
< 10:
175 self
.ShowError(val
[0])
177 except gammu
.ERR_CORRUPTED
:
179 _('Ignoring corrupted'),
180 _('While reading, entry on location %d seems to be corrupted, ignoring it!') % location
)
182 except gammu
.ERR_UNKNOWN
:
184 _('Ignoring unknown'),
185 _('While reading, entry on location %d reported unknown error, ignoring it!') % location
)
187 except gammu
.GSMError
, val
:
188 self
.ShowError(val
[0], True)
190 location
= location
+ 1
191 except gammu
.ERR_INVALIDLOCATION
, val
:
192 # if we reached end with guess, it is okay
194 self
.ShowError(val
[0], True)
196 except gammu
.GSMError
, val
:
197 self
.ShowError(val
[0], True)