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 - 2010 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()
117 if guess
and remain
== 1:
118 # Read more things if there are some
122 value
= self
.GetNext(loc
)
124 loc
= value
['Location']
126 loc
= value
[0]['Location']
128 if type(value
) == list:
129 for i
in range(len(value
)):
130 value
[i
]['Synced'] = True
132 value
['Synced'] = True
134 except gammu
.ERR_UNKNOWN
:
136 _('Ignoring unknown'),
137 _('While reading, entry on location %d reported unknown error, ignoring it!') % loc
)
139 except gammu
.ERR_CORRUPTED
:
141 _('Ignoring corrupted'),
142 _('While reading, entry on location %d seems to be corrupted, ignoring it!') % loc
)
144 except gammu
.ERR_EMPTY
:
148 except (gammu
.ERR_NOTSUPPORTED
, gammu
.ERR_NOTIMPLEMENTED
):
152 self
.ShowProgress(100 * (total
- remain
) / total
)
157 value
= self
.Get(location
)
159 if type(value
) == list:
160 for i
in range(len(value
)):
161 value
[i
]['Synced'] = True
163 value
['Synced'] = True
166 # If we didn't know count and reached end, try some more entries
167 if remain
== 0 and guess
:
171 except gammu
.ERR_EMPTY
, val
:
173 # If we didn't know count and saw many empty entries, stop right now
174 if empty
>= Wammu
.configuration
.ReadInt('/Hacks/MaxEmptyGuess') and guess
:
176 # If we didn't read anything for long time, we bail out (workaround bad count reported by phone)
177 if empty
>= Wammu
.configuration
.ReadInt('/Hacks/MaxEmptyKnown') and remain
< 10:
178 self
.ShowError(val
[0])
180 except gammu
.ERR_CORRUPTED
:
182 _('Ignoring corrupted'),
183 _('While reading, entry on location %d seems to be corrupted, ignoring it!') % location
)
185 except gammu
.ERR_UNKNOWN
:
187 _('Ignoring unknown'),
188 _('While reading, entry on location %d reported unknown error, ignoring it!') % location
)
190 except gammu
.GSMError
, val
:
191 self
.ShowError(val
[0], True)
193 location
= location
+ 1
194 except gammu
.ERR_INVALIDLOCATION
, val
:
195 # if we reached end with guess, it is okay
197 self
.ShowError(val
[0], True)
199 except gammu
.GSMError
, val
:
200 self
.ShowError(val
[0], True)