1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
From patchwork Sun Feb 6 10:52:50 2011
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: [sugar] Notify on not sent feedbacks; fix issue with not auto resend
Date: Sun, 06 Feb 2011 15:52:50 -0000
From: Aleksey Lim <alsroot@activitycentral.org>
X-Patchwork-Id: 634
Message-Id: <1296989570-2997-1-git-send-email-alsroot@activitycentral.org>
To: dextrose@lists.sugarlabs.org
---
src/jarabe/model/feedback_collector.py | 32 ++++++++++++++++++++------------
1 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/src/jarabe/model/feedback_collector.py b/src/jarabe/model/feedback_collector.py
index 4671437..43540a0 100644
--- a/src/jarabe/model/feedback_collector.py
+++ b/src/jarabe/model/feedback_collector.py
@@ -25,12 +25,14 @@ from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
from email.generator import Generator
from email.encoders import encode_noop
+from gettext import gettext as _
import gconf
import gobject
import simplejson
from sugar import logger, feedback, util
+from jarabe import frame
_reports = {}
@@ -47,7 +49,7 @@ def start(host, port, auto_submit_delay):
_port = port
if auto_submit_delay > 0:
- gobject.timeout_add_seconds(auto_submit_delay, anonymous_submit)
+ gobject.timeout_add_seconds(auto_submit_delay, anonymous_submit, True)
def update(bundle_id, report, log_file):
@@ -86,24 +88,26 @@ def submit(message):
'nick': nick,
'jabber_server': jabber,
}
- _submit(data)
+ _submit(data, False)
-def anonymous_submit():
+def anonymous_submit(implicit=False):
from jarabe.journal import misc
data = {}
client = gconf.client_get_default()
if client.get_bool('/desktop/sugar/feedback/anonymous_with_sn'):
data['serial_number'] = misc.get_xo_serial()
- _submit(data)
+ _submit(data, implicit)
+
+ return True
-def _submit(data=None):
+def _submit(data, implicit):
if data:
_reports.update(data)
if is_empty():
- return True
+ return
logging.debug('Sending feedback report: %r', _reports)
@@ -126,16 +130,15 @@ def _submit(data=None):
tar.close()
- _SubmitThread(tar_file).run()
-
- return True
+ _SubmitThread(tar_file, implicit).run()
class _SubmitThread(threading.Thread):
- def __init__(self, tar_file):
+ def __init__(self, tar_file, implicit):
threading.Thread.__init__(self)
self._tar_file = tar_file
+ self._implicit = implicit
def run(self):
try:
@@ -151,11 +154,16 @@ class _SubmitThread(threading.Thread):
response = conn.getresponse()
if response.status != 200:
- logging.error('Incorrect feedback submit: %s, %s',
+ raise Exception('Incorrect feedback submit: %s, %s',
response.status, response.read())
except Exception:
- logging.exception('Cannot submit feedback')
+ title = _('Cannot submit feedback')
+ msg = _('Feedback was not sent to %s:%s.') % (_host, _port)
+ if not self._implicit:
+ gobject.idle_add(lambda:
+ frame.get_view().add_message(summary=title, body=msg))
+ logging.exception('%s: %s', title, msg)
finally:
os.unlink(self._tar_file)
self._tar_file = None
|