From 818eaaf08dcdf4dea41f004084536984f2d193a7 Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Sun, 20 Sep 2009 15:46:08 +0200 Subject: [PATCH] Aggiunta gestione degli errori di I/O --- DrPrintBackend.py | 22 ++++++++++++++++++++-- DrPrintGui/MainWin.py | 12 ++++++++++++ DrPrintGui/MainWin.pyc | Bin 4096 -> 4493 bytes 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/DrPrintBackend.py b/DrPrintBackend.py index 12944d4..3438add 100644 --- a/DrPrintBackend.py +++ b/DrPrintBackend.py @@ -9,6 +9,7 @@ class Backend(gobject.GObject): super(Backend, self).__init__() gobject.signal_new("auth_failed", Backend, gobject.SIGNAL_RUN_FIRST, None, ()) + gobject.signal_new('io_error', Backend, gobject.SIGNAL_RUN_FIRST, None, ()) def send_print(self, printer, username, password, page_per_page, filename, page_range): # Get printer name @@ -30,7 +31,12 @@ class Backend(gobject.GObject): channel = client.get_transport().open_session() print "Printing %s" % filename - f = open(filename, 'r') + + try: + f = open(filename, 'r') + except IOError: + self.emit('io_error') + return # Questo è inevitabile.. :) cmd = "lpr -P%s " % printer @@ -51,8 +57,20 @@ class Backend(gobject.GObject): ## Diamo il comando sul canale e infiliamo il file ## dentro lo stdin :) + print "Eseguo %s" % cmd + channel.exec_command(cmd) - channel.sendall( f.read() ) + try: + content = f.read() + except IOError: + self.emit('io_error') + return + + try: + channel.sendall( content ) + except socket.timeout, socket.error: + self.emit('io_error') + return f.close() channel.close() diff --git a/DrPrintGui/MainWin.py b/DrPrintGui/MainWin.py index 5c0a385..282f2ec 100644 --- a/DrPrintGui/MainWin.py +++ b/DrPrintGui/MainWin.py @@ -86,6 +86,7 @@ class MainWin(gtk.Window): def connect_all(self): self.print_button.connect('clicked', self.print_button_clicked_callback) self.backend.connect('auth_failed', self.auth_failed_callback) + self.backend.connect('io_error', self.io_error_callback) def print_button_clicked_callback(self, widget): if not self.backend == None: @@ -115,6 +116,17 @@ class MainWin(gtk.Window): corretti. L'autenticazione su ssh.dm.unipi.it\nnon è andata a buon fine.") dialog.run() dialog.destroy() + + def io_error_callback(self, obj): + + self.debug("Errore di I/O") + dialog = ErrorDialog("Errore di I/O", + "Errore di I/O\n\ +C'è stato un errore nella lettura o nella\n \ +trasmissione del file.") + + dialog.run() + dialog.destroy() diff --git a/DrPrintGui/MainWin.pyc b/DrPrintGui/MainWin.pyc index 6f72302aae2a917e4a6647f28a4bb1708ed1f747..ffaef119f56771eea26a733e721a91bbaf5f8347 100644 GIT binary patch delta 512 zcmY+A&r2IY6vy98lF9BS<7!e;D4`7g%4#)13TZ6SLq(+re=r^d6(k|6ENrv5yJ8Oo z3#~`-FsIT(OHW=Ue?tC(p8Ny6_uwB;`d)fz5A)&s{l1yUoA*&&Pl=z8(s@|A6FaQ5 z3jjXA0fQcrL(ej&?3L{0;WK&%^qyxAey}fsZJ4&zsD1zlG7#YP43N&jCk_nX?s-{r zW+^wduwxJ%`*9q_o-oGRlIg@hnYp))@&W^3l|jp1;mx|ZZsD&NG6C`{K{8Ar z8Ad-1uF0YTI`TR|P7pVU5CRdxAOd7+5Xht;lgS!_?vvLDa0&4Nxokkwcmz3(IaxS` LIe8|Z5;zP11pg?k -- 2.1.4