Merge lp:~dobey/ubuntuone-client/sync-fatale into lp:ubuntuone-client

Proposed by dobey
Status: Merged
Approved by: Tim Cole
Approved revision: 175
Merged at revision: not available
Proposed branch: lp:~dobey/ubuntuone-client/sync-fatale
Merge into: lp:ubuntuone-client
Diff against target: None lines
To merge this branch: bzr merge lp:~dobey/ubuntuone-client/sync-fatale
Reviewer Review Type Date Requested Status
Tim Cole (community) Approve
Rodrigo Moya (community) Approve
Review via email: mp+10625@code.launchpad.net

Commit message

Handle the fatal error a lot better and try to run syncdaemon

To post a comment you must log in.
Revision history for this message
Rodrigo Moya (rodrigo-moya) :
review: Approve
Revision history for this message
Tim Cole (tcole) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile.am'
2--- Makefile.am 2009-08-05 18:01:19 +0000
3+++ Makefile.am 2009-08-24 20:22:32 +0000
4@@ -38,7 +38,10 @@
5 pyfiles = $(shell SRCDIR="$(top_srcdir)/ubuntuone"; for i in `find $$SRCDIR -type f -name "*.py"`; do if [ ! -f $$i.in ]; then printf "$$i "; fi; done)
6
7 $(clientdefs_DATA): $(clientdefs_in_files) ubuntuone
8- sed -e 's|\@localedir\@|$(localedir)|g' -e 's|\@GETTEXT_PACKAGE\@|$(GETTEXT_PACKAGE)|g' -e 's|\@VERSION\@|$(VERSION)|g' < $< > $@
9+ sed -e 's|\@localedir\@|$(localedir)|g' \
10+ -e 's|\@libexecdir\@|$(libexecdir)|g' \
11+ -e 's|\@GETTEXT_PACKAGE\@|$(GETTEXT_PACKAGE)|g' \
12+ -e 's|\@VERSION\@|$(VERSION)|g' < $< > $@
13
14 pylintrc: Makefile
15 if test "x$(builddir)" != "x$(srcdir)"; then \
16
17=== modified file 'bin/ubuntuone-client-applet'
18--- bin/ubuntuone-client-applet 2009-08-24 01:12:37 +0000
19+++ bin/ubuntuone-client-applet 2009-08-24 20:22:32 +0000
20@@ -52,9 +52,6 @@
21
22 _ = gettext.gettext
23
24-# Wait for 30 seconds to get a proper login request
25-LOGIN_TIMEOUT = 30
26-
27 DBUS_IFACE_NAME = "com.ubuntuone.SyncDaemon"
28 DBUS_IFACE_SYNC_NAME = "com.ubuntuone.SyncDaemon.SyncDaemon"
29 DBUS_IFACE_STATUS_NAME = "com.ubuntuone.SyncDaemon.Status"
30@@ -80,6 +77,9 @@
31 login = Login(dbus.service.BusName(DBUS_IFACE_AUTH_NAME,
32 bus=dbus.SessionBus()))
33
34+ logger.debug(_("Starting Ubuntu One client version %s") %
35+ clientdefs.VERSION)
36+
37 # Whether or not we are authorized
38 self.is_authorized = False
39
40@@ -114,22 +114,26 @@
41 client = self.__bus.get_object(DBUS_IFACE_NAME, "/")
42 iface = dbus.Interface(client, DBUS_IFACE_SYNC_NAME)
43 iface.connect(reply_handler=dbus_async,
44- error_handler=self.dbus_error)
45+ error_handler=self.sd_dbus_error)
46 except DBusException, e:
47- self.dbus_error(e)
48+ self.sd_dbus_error(e)
49
50 def __auth_denied(self):
51 """Signal callback for when auth was denied by user."""
52 self.is_authorized = False
53 self.remove_from_autostart()
54
55+ def quit_error(e):
56+ """Only log when quit fails."""
57+ logger.error(_("Quit Error: %s") % e.get_dbus_message())
58+
59 try:
60 client = self.__bus.get_object(DBUS_IFACE_NAME, "/")
61 iface = dbus.Interface(client, DBUS_IFACE_SYNC_NAME)
62 iface.quit(reply_handler=dbus_async,
63- error_handler=self.dbus_error)
64+ error_handler=quit_error)
65 except DBusException, e:
66- self.dbus_error(e)
67+ quit_error(e)
68
69 from twisted.internet import reactor
70 reactor.stop()
71@@ -188,19 +192,23 @@
72
73 dialog.show()
74 else:
75- logger.error("Got an error with no message!")
76+ logger.error(_("Got an OAuth error with no message."))
77
78 def check_for_token(self, do_login=False):
79 """Method to check for an existing token."""
80+ def local_dbus_error(e):
81+ """Can't talk to ourself?"""
82+ logger.error(_("Internal Error: %s") % e.get_dbus_message())
83+
84 try:
85 client = self.__bus.get_object(DBUS_IFACE_AUTH_NAME, "/")
86 iface = dbus.Interface(client, DBUS_IFACE_AUTH_NAME)
87 iface.maybe_login(OAUTH_REALM, OAUTH_CONSUMER,
88 do_login,
89 reply_handler=dbus_async,
90- error_handler=self.dbus_error)
91+ error_handler=local_dbus_error)
92 except DBusException, e:
93- self.dbus_error(e)
94+ local_dbus_error(e)
95 return False
96
97 return False
98@@ -211,9 +219,9 @@
99 client = self.__bus.get_object(DBUS_IFACE_NAME, "/")
100 iface = dbus.Interface(client, DBUS_IFACE_SYNC_NAME)
101 iface.get_rootdir(reply_handler=dbus_async,
102- error_handler=self.dbus_error)
103+ error_handler=self.sd_dbus_error)
104 except DBusException, e:
105- self.dbus_error(e)
106+ self.sd_dbus_error(e)
107 return False
108
109 return False
110@@ -264,9 +272,9 @@
111 """Are we authorized?"""
112 return self.is_authorized
113
114- def dbus_error(self, error):
115+ def sd_dbus_error(self, error):
116 """Got an error from DBus."""
117- self.__icon.dbus_error(error)
118+ self.__icon.sd_dbus_error(error)
119
120
121
122@@ -274,7 +282,7 @@
123 """Utility method to run xdg-open with path_or_url."""
124 ret = subprocess.call(["xdg-open", path_or_url])
125 if ret != 0:
126- logger.debug("Failed to run 'xdg-open %s'" % path_or_url)
127+ logger.error(_("Failed to run 'xdg-open %s'") % path_or_url)
128
129 class AppletIcon(gtk.StatusIcon):
130 """
131@@ -460,25 +468,34 @@
132 self.__visible = False
133 state = status['name']
134
135+ if self.__fatal_error and state != "UNKNOWN_ERROR":
136+ # Just blow your nose, and it's fixed, isn't it.
137+ self.__fatal_error = False
138+ self.__litems["connect"].set_sensitive(True)
139+ self.__litems["disconnect"].set_sensitive(True)
140+
141 if state == "OFFLINE" or state.startswith("INIT") or \
142 state.startswith("READY"):
143 self.set_from_icon_name("ubuntuone-client-offline")
144 self.__connected = False
145 self.__visible = True
146+
147 elif state == "IDLE" or state.startswith("READING") or \
148 state.startswith("SCANNING"):
149 self.__connected = True
150 self.__visible = False
151+
152 elif state == "AUTH_FAILED":
153 self.set_from_icon_name("ubuntuone-client-error")
154 self.set_tooltip(_("Authentication failed"))
155 self.__connected = False
156 self.__visible = True
157+
158+ def reauthorize_error(e):
159+ """Simple dbus error handler."""
160+ logger.error(_("Error clearing token: %s") % str(e))
161+
162 try:
163- def reauthorize_error(error):
164- """Simple dbus error handler."""
165- pass
166-
167 def token_cleared():
168 """Do the next step."""
169 if self.__main:
170@@ -487,12 +504,12 @@
171 client = self.__bus.get_object(DBUS_IFACE_AUTH_NAME,
172 "/")
173 iface = dbus.Interface(client, DBUS_IFACE_AUTH_NAME)
174- logger.debug("Clearing the token!")
175 iface.clear_token(OAUTH_REALM, OAUTH_CONSUMER,
176 reply_handler=token_cleared,
177 error_handler=reauthorize_error)
178- except DBusException:
179- pass
180+ except DBusException, e:
181+ reauthorize_error(e)
182+
183 elif state == "UNKNOWN_ERROR":
184 # Disable some menu items
185 self.__litems["connect"].set_sensitive(False)
186@@ -520,6 +537,7 @@
187 # Set the tooltip and icon on the applet
188 self.set_tooltip(_("Fatal Error"))
189 self.set_from_icon_name("ubuntuone-client-error")
190+
191 else:
192 self.__connected = True
193 self.set_from_icon_name("ubuntuone-client")
194@@ -572,7 +590,7 @@
195
196 def got_err(error):
197 """Handle error from the dbus callback."""
198- self.dbus_error(error)
199+ self.sd_dbus_error(error)
200 self.__managed_dir = None
201 self.__ritems["open"].set_sensitive(False)
202
203@@ -583,9 +601,9 @@
204 client = self.__bus.get_object(DBUS_IFACE_NAME, "/status")
205 iface = dbus.Interface(client, DBUS_IFACE_STATUS_NAME)
206 iface.current_status(reply_handler=self.__status_changed,
207- error_handler=self.dbus_error)
208+ error_handler=self.sd_dbus_error)
209 except DBusException, e:
210- self.dbus_error(e)
211+ self.sd_dbus_error(e)
212 return False
213
214 return False
215@@ -676,14 +694,17 @@
216
217 def __quit_applet(self, menuitem, data=None):
218 """Quit the daemon and closes the applet."""
219+ def quit_error(e):
220+ """Just log and ignore."""
221+ logger.error(_("Quit Error: %s") % e.get_dbus_message())
222
223 try:
224 client = self.__bus.get_object(DBUS_IFACE_NAME, "/")
225 iface = dbus.Interface(client, DBUS_IFACE_SYNC_NAME)
226 iface.quit(reply_handler=dbus_async,
227- error_handler=self.dbus_error)
228+ error_handler=quit_error)
229 except DBusException, e:
230- self.dbus_error(e)
231+ quit_error(e)
232
233 from twisted.internet import reactor
234 reactor.stop()
235@@ -695,14 +716,14 @@
236 iface = dbus.Interface(client, DBUS_IFACE_SYNC_NAME)
237 if self.__connected:
238 iface.disconnect(reply_handler=dbus_async,
239- error_handler=self.dbus_error)
240+ error_handler=self.sd_dbus_error)
241 else:
242 if self.__main and self.__main.authorized is False:
243 self.__main.check_for_token(do_login=True)
244 iface.connect(reply_handler=dbus_async,
245- error_handler=self.dbus_error)
246+ error_handler=self.sd_dbus_error)
247 except DBusException, e:
248- self.dbus_error(e)
249+ self.sd_dbus_error(e)
250
251 def __open_folder(self, data=None):
252 """Opens the storage folder in the file manager."""
253@@ -730,7 +751,7 @@
254 args = ["ubuntu-bug", "ubuntuone-client"]
255 ret = subprocess.call(args)
256 if ret != 0:
257- logger.error("Failed to run 'ubuntu-bug'")
258+ logger.error(_("Failed to run 'ubuntu-bug'"))
259
260 def __open_website(self, data=None, url=None):
261 """Opens the ubuntuone.com web site."""
262@@ -769,10 +790,30 @@
263 output = "".join(lines)
264 f.write(output)
265
266- def dbus_error(self, error):
267- """Handle DBus errors and change the applet behavior slightly."""
268- logger.debug("DBusError: %s" % error.get_dbus_message())
269- self.__status_changed({'name' : 'UNKNOWN_ERROR'})
270+ def sd_dbus_error(self, error):
271+ """
272+ Handle DBus errors for crucial syncdaemon calls,
273+ and change the applet behavior slightly.
274+ """
275+ logger.error(_("DBus Error: %s") % error.get_dbus_message())
276+ sd_path = os.path.join(clientdefs.LIBEXECDIR,
277+ "ubuntuone-syncdaemon")
278+ try:
279+ p = subprocess.Popen([sd_path],
280+ bufsize=4096,
281+ stderr=subprocess.PIPE)
282+ if p.returncode:
283+ errors = "".join(p.stderr.readlines())
284+ if errors != "":
285+ print "Failure to launch:\n%s" % errors
286+ self.__status_changed({'name' : 'UNKNOWN_ERROR'})
287+ else:
288+ self.__status_changed({'name' : 'OFFLINE'})
289+ except (OSError, IOError), e:
290+ logger.error(_("Failed to launch syncdaemon: %s") %
291+ str(e))
292+ self.__status_changed({'name' : 'UNKNOWN_ERROR'})
293+
294
295 if __name__ == "__main__":
296 gettext.bindtextdomain(clientdefs.GETTEXT_PACKAGE, clientdefs.LOCALEDIR)
297
298=== modified file 'ubuntuone/clientdefs.py.in'
299--- ubuntuone/clientdefs.py.in 2009-07-15 21:47:57 +0000
300+++ ubuntuone/clientdefs.py.in 2009-08-24 20:22:32 +0000
301@@ -25,4 +25,5 @@
302 # pylint: disable-msg=C0301
303 VERSION = "@VERSION@"
304 LOCALEDIR = "@localedir@"
305+LIBEXECDIR = "@libexecdir@"
306 GETTEXT_PACKAGE = "@GETTEXT_PACKAGE@"

Subscribers

People subscribed via source and target branches