Changeset 277


Ignore:
Timestamp:
07/28/09 05:01:31 (3 years ago)
Author:
marc
Message:

Enhanced console logging functions to support multiple arguments and better concatenation of them. Changed names for quicker testing. Don't import the reactor twice, better handling of a single reactor, a bug fix. Build shot file path for screenshots on request, this fixes a bug where the screenshot file name locally wasn't changed while the app was running. Better clean up of stale screenshot files. Added handling of SIGINT (ctrl-c) which shuts down the server and cleans up stale screenshot files.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/console.py

    r274 r277  
    2626 
    2727# Global output functions 
    28 def print_m(string): 
     28def print_message(string): 
    2929    """ 
    3030    Print wrapper. 
     
    4444    """ 
    4545 
    46     print_m('WARNING: %s' % (" - ".join(str(item) for item in strings))) 
     46    print_message('WARNING: %s' % (" - ".join(str(item) for item in strings))) 
    4747 
    4848def print_error(*strings): 
     
    5454    """ 
    5555 
    56     print_m('ERROR: %s' % (" - ".join(str(item) for item in strings))) 
     56    print_message('ERROR: %s' % (" - ".join(str(item) for item in strings))) 
    5757 
    5858def print_debug(*strings): 
     
    6464    """ 
    6565 
    66     print_m('DEBUG: %s' % (" - ".join(str(item) for item in strings))) 
     66    print_message('DEBUG: %s' % (" - ".join(str(item) for item in strings))) 
    6767 
    6868# Register them for global use 
    69 __builtin__.print_m = print_m 
    70 __builtin__.print_error = print_error 
    71 __builtin__.print_warning = print_warning 
    72 __builtin__.print_debug = print_debug 
     69__builtin__.print_m = print_message 
     70__builtin__.print_e = print_error 
     71__builtin__.print_w = print_warning 
     72__builtin__.print_d = print_debug 
    7373 
    7474class BaseMessage: 
     
    8686 
    8787        self.message = message 
    88         print_m(self.message) 
     88        print_message(self.message) 
    8989 
    9090class BaseFailureMessage(BaseMessage): 
  • trunk/screenshot.py

    r274 r277  
    5656        self.current_window_failed = False 
    5757 
    58         #: Final absolute path to the screenshot file 
    59         self.shot_file = os.path.join(self.configuration['screenshot']['path'], 'itakashot.%s' % (self.configuration['screenshot']['format'])) 
    60          
    6158        self.root_screen = gtk.gdk.screen_get_default() 
    6259        self.root_window = gtk.gdk.get_default_root_window() 
     
    104101        """ 
    105102 
    106         # Get up to date configuration values everytime there is a request 
    107          
     103        # Get up to date configuration values and build shot file path everytime there is a request 
    108104        self.configuration = self.gui.configuration 
    109105 
     106        #: Final absolute path to the screenshot file 
     107        self.shot_file = os.path.join(self.configuration['screenshot']['path'], 'itakashot.%s' % (self.configuration['screenshot']['format'])) 
     108         
    110109        if self.configuration['screenshot']['currentwindow'] and not self.itaka_globals.system == 'nt': 
    111110            try: 
  • trunk/server.py

    r274 r277  
    3232    import error 
    3333except ImportError: 
    34     print_error(_('Failed to import Itaka modules')) 
     34    print_e(_('Failed to import Itaka modules')) 
    3535    traceback.print_exc() 
    3636    sys.exit(1) 
     
    3939    from twisted.python import log 
    4040    from twisted.web import server, static, http, resource 
    41     from twisted.internet import reactor 
    4241    import twisted.internet.error 
    4342except ImportError: 
    44     print_error(_('Could not import Twisted Network Framework')) 
     43    print_e(_('Could not import Twisted Network Framework')) 
    4544    traceback.print_exc() 
    4645    sys.exit(1) 
     
    107106        self.site = server.Site(resource) 
    108107 
    109     def start_server(self, port): 
     108    def start_server(self, reactor, port): 
    110109        """ 
    111110        Start the server 
     111 
     112        @type reactor: twisted.internet.gtk2reactor.Gtk2Reactor 
     113        @param reactor: An instance of a reactor already run() 
    112114 
    113115        @type port: int 
     
    116118 
    117119        try: 
    118             self.server = reactor.listenTCP(port, self.site) 
     120            if hasattr(self, 'server'): 
     121                self.server.startListening() 
     122            else: 
     123                self.server = reactor.listenTCP(port, self.site) 
    119124        except twisted.internet.error.CannotListenError, e: 
    120125            raise error.ItakaServerCannotListenError, e 
  • trunk/uigtk.py

    r275 r277  
    2323""" Itaka GTK+ GUI """ 
    2424 
     25import copy 
     26import datetime 
     27import os 
    2528import sys 
    26 import os 
    27 import datetime 
     29import signal 
    2830import traceback 
    29 import copy 
    3031 
    3132try: 
     
    3435        gtk2reactor.install() 
    3536    except Exception, e: 
    36         print_error(_('Could not initiate GTK modules: %s' % (e))) 
     37        print_e(_('Could not initiate GTK modules: %s' % (e))) 
    3738        sys.exit(1) 
    3839    from twisted.internet import reactor 
    3940except ImportError: 
    40     print_error(_('Could not import Twisted Network Framework')) 
     41    print_e(_('Could not import Twisted Network Framework')) 
    4142    sys.exit(1) 
    4243 
     
    4546    import error 
    4647except ImportError: 
    47     print_error(_('Failed to import Itaka modules')) 
     48    print_e(_('Failed to import Itaka modules')) 
    4849    traceback.print_exc() 
    4950    sys.exit(1) 
     
    5354    pygtk.require("2.0") 
    5455except ImportError: 
    55     print_warning(_('Pygtk module is missing')) 
     56    print_w(_('Pygtk module is missing')) 
    5657    pass 
    5758try: 
    5859    import gtk, gobject, pango 
    5960except ImportError: 
    60     print_error(_('GTK+ bindings are missing')) 
     61    print_e(_('GTK+ bindings are missing')) 
    6162    sys.exit(1) 
    6263 
    6364if gtk.gtk_version[1] < 10: 
    64     print_error(_('Itaka requires GTK+ 2.10, you have %s installed' % (".".join(str(x) for x in gtk.gtk_version)))) 
     65    print_e(_('Itaka requires GTK+ 2.10, you have %s installed' % (".".join(str(x) for x in gtk.gtk_version)))) 
    6566    sys.exit(1) 
    6667 
     
    115116        @param icon: The first argument is a string of either 'stock' or 'pixbuf', and the second is a string of gtk.STOCK_ICON or a gtk.gdk.pixbuf object (without the 'gtk.' prefix) 
    116117        """ 
    117          
     118        
    118119        self.console.message(message) 
    119120        self._write_gui_log(message, None, icon, False) 
     
    307308        self.icon_pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.join(self.itaka_globals.image_dir, 'itaka.png')) 
    308309        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) 
    309         self.window.connect('destroy', self.destroy) 
     310        self.window.connect('destroy', self._destroy) 
    310311        self.window.connect('size-allocate', self._window_size_changed) 
    311312        self.window.set_title('Itaka') 
     
    352353        self.menu_item_separator1 = gtk.SeparatorMenuItem() 
    353354        self.menu_item_quit = gtk.ImageMenuItem(gtk.STOCK_QUIT) 
    354         self.menu_item_quit.connect('activate', self.destroy) 
     355        self.menu_item_quit.connect('activate', self._destroy) 
    355356 
    356357        self.status_menu.append(self.menu_item_start) 
     
    679680            self.format_value = 'jpeg' 
    680681            self.configuration['screenshot']['format'] = 'jpeg' 
     682 
     683        # Delete stale old screenshot 
     684        if (self.current_configuration['screenshot']['format'] != self.configuration['screenshot']['format']): 
     685            if os.path.exists(os.path.join(self.current_configuration['screenshot']['path'], 'itakashot.%s' % (self.current_configuration['screenshot']['format']))):  
     686                os.remove(os.path.join(self.current_configuration['screenshot']['path'], 'itakashot.%s' % (self.current_configuration['screenshot']['format']))) 
     687                if self.itaka_globals.console_verbosity['debug']: print_m(_("Deleting stale screenshot file '%s'" % ((os.path.join(self.current_configuration['screenshot']['path'], 'itakashot.%s' % (self.current_configuration['screenshot']['format'])))))) 
     688 
    681689 
    682690        if self.itaka_globals.notify_available: 
     
    10711079        """ 
    10721080 
    1073         # Server reactor (interacts with the Twisted reactor)    
    1074         self.sreact = reactor.run() 
    1075  
     1081        # Run the gtk.main() loop and start a reactor for our server. 
     1082        # False can be passed for it to not register to it's SIGINT handler. 
     1083        # Register our own handler to send to _destroy 
     1084        signal.signal(signal.SIGINT, self._destroy) 
     1085        reactor.run() 
     1086         
    10761087    def _preferences_combo_changed(self, widget): 
    10771088        """ 
     
    11481159 
    11491160        try: 
    1150             self.server.start_server(self.configuration['server']['port']) 
     1161            self.server.start_server(reactor, self.configuration['server']['port']) 
    11511162        except error.ItakaServerCannotListenError, e: 
    11521163            self.log.failure(('Gui', 'start_server'), (_('Failed to start server on port %(port)s: %(errorstring)s' % {'port': e.value.port, 'errorstring': e.value.args[-1][-1]}), _('Failed to start server: %s') % e.value), 'ERROR') 
     
    12281239            self.start_server(None, True) 
    12291240 
    1230     def destroy(self, *args): 
     1241    def _destroy(self, *args): 
    12311242        """ 
    12321243        Main window destroy event 
     
    12431254        del self.status_icon 
    12441255 
     1256        self.log.verbose_message(_('Itaka Shutting down'), _('Received SIGINT, shutting down'), ['stock', 'STOCK_DISCONNECT']) 
     1257 
    12451258        self.console.message(_('Itaka shutting down')) 
    1246         gtk.main_quit() 
     1259 
     1260        reactor.stop() 
    12471261 
    12481262    def _literal_time_difference(self, dtime): 
Note: See TracChangeset for help on using the changeset viewer.