Changeset 278 for trunk


Ignore:
Timestamp:
07/28/09 06:58:46 (3 years ago)
Author:
marc
Message:

Dir and type methods for debugging, fixed config print method, added logtimeformat and time prefix to log, fixed a bug when restarting the server on another port, better docs for twisted ports, bigger itaka notify icon but ubuntu osd still fails, less verbose sigint, minor changes

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/config.py

    r271 r278  
    4040 
    4141    if not pynotify.init('Itaka'): 
    42         print_warning(_('Pynotify module is failing, disabling notifications')) 
     42        print_w(_('Pynotify module is failing, disabling notifications')) 
    4343        notify_available = False 
    4444except ImportError: 
    45     print_warning(_('Pynotify module is missing, disabling notifications')) 
     45    print_w(_('Pynotify module is missing, disabling notifications')) 
    4646    notify_available = False 
    4747 
     
    5656 
    5757if not os.path.exists(image_dir): 
    58     print_error(_('Could not find images directory %s' % (image_dir))) 
     58    print_e(_('Could not find images directory %s' % (image_dir))) 
    5959    sys.exit(1) 
    6060 
     
    116116 
    117117        #: Default configuration sections and values 
     118        # WARNING: Don't forget to update configuration_dict in uigtk.py if you change this!  
    118119        self.default_options = (  
    119120                {'server': ( 
     
    127128                    ('currentwindow', False), ('scale', False), 
    128129                    ('scalepercent', 100) 
     130                )}, 
     131                 
     132                {'log': ( 
     133                    ('logtimeformat', '[%d/%b/%Y %H:%M:%S]'), 
     134                    ('logfile', '~/.itaka/access.log') 
    129135                )}, 
    130136                 
     
    171177 
    172178        except: 
    173             if console_verbosity['normal']: print_error(_('Could not read configuration file (%s)' % (self.config_file))) 
     179            if console_verbosity['normal']: print_e(_('Could not read configuration file (%s)' % (self.config_file))) 
    174180            if console_verbosity['debug']: traceback.print_exc() 
    175181 
     
    196202                if not configuration_values.has_key(section): 
    197203                    if not console_verbosity['quiet'] and not brokenwarning:  
    198                         print_warning(_('Detected old or broken configuration file. Fixing')) 
     204                        print_w(_('Upgrading configuration file.')) 
    199205                        brokenwarning = True 
    200206                    config_instance.add_section(section) 
     
    210216                        if not configuration_values[section].has_key(key): 
    211217                            if not console_verbosity['quiet'] and not brokenwarning: 
    212                                 print_warning(_('Detected old or broken configuration file. Fixing')) 
     218                                print_w(_('Detected old or broken configuration file. Fixing')) 
    213219                            self.update(section, key, val) 
    214220                            configuration_values[section][key] = val 
     
    234240            if console_verbosity['normal']: print_m(_('Saving configuration'))   
    235241        except:          
    236             if not console_verbosity['quiet']: print_error(_('Could not write configuration file %s' % (self.config_file))) 
     242            if not console_verbosity['quiet']: print_e(_('Could not write configuration file %s' % (self.config_file))) 
    237243            if console_verbosity['debug']: traceback.print_exc() 
    238244 
     
    255261            if console_verbosity['debug']: print_m(_("Updating configuration key '%(key)s' to '%(value)s'") % {'key': key, 'value': value}) 
    256262        except: 
    257             if not console_verbosity['quiet']: print_error(_('Could not write configuration file %s' % (self.config_file))) 
     263            if not console_verbosity['quiet']: print_e(_('Could not write configuration file %s' % (self.config_file))) 
    258264            if console_verbosity['debug']: traceback.print_exc() 
    259265 
     
    282288            config_instance.write(open(path, 'w')) 
    283289        except: 
    284             if not console_verbosity['quiet']: print_error(_('Could not write configuration file %s' % (path))) 
     290            if not console_verbosity['quiet']: print_e(_('Could not write configuration file %s' % (path))) 
    285291            if console_verbosity['debug']: traceback.print_exc() 
    286292 
  • trunk/console.py

    r277 r278  
    6666    print_message('DEBUG: %s' % (" - ".join(str(item) for item in strings))) 
    6767 
     68def print_type(*strings): 
     69    """ 
     70    Print type wrapper. 
     71 
     72    @type *strings: anything 
     73    @param *strings: Anything 
     74    """ 
     75 
     76    print_message('DEBUG: %s' % (" - ".join(str(type(item)) for item in strings))) 
     77 
     78def print_dir(*strings): 
     79    """ 
     80    Print dir wrapper. 
     81 
     82    @type *strings: anything 
     83    @param *strings: Anything 
     84    """ 
     85 
     86    print_message('DEBUG: %s' % (" - ".join(str(dir(item)) for item in strings))) 
     87 
    6888# Register them for global use 
    6989__builtin__.print_m = print_message 
     
    7191__builtin__.print_w = print_warning 
    7292__builtin__.print_d = print_debug 
     93__builtin__.print_t = print_type 
     94__builtin__.print_dir = print_dir 
    7395 
    7496class BaseMessage: 
  • trunk/server.py

    r277 r278  
    118118 
    119119        try: 
    120             if hasattr(self, 'server'): 
    121                 self.server.startListening() 
    122             else: 
    123                 self.server = reactor.listenTCP(port, self.site) 
     120            # We need to create a new instance because of server port changes, don't use hasattr() 
     121            # Returns a 'twisted.internet.tcp.Port' 
     122            self.server = reactor.listenTCP(port, self.site) 
    124123        except twisted.internet.error.CannotListenError, e: 
    125124            raise error.ItakaServerCannotListenError, e 
     
    149148        Add a twisted.log observer 
    150149         
     150        See: http://twistedmatrix.com/projects/core/documentation/howto/logging.html  
    151151        @type observer: method 
    152152        @param observer: A method to send the logs to 
     
    481481            import pynotify 
    482482            # 48x48 image by default looks bad in Ubuntu 
    483             uri = "file://" + (os.path.join(self.itaka_globals.image_dir, "itaka-take.png"))  
    484  
     483            uri = "file://" + (os.path.join(self.itaka_globals.image_dir, "itaka512x512-take.png"))  
     484             
    485485            n = pynotify.Notification(_('Screenshot taken'), _('%s captured the screen' % (self.ip)), uri) 
    486486 
  • trunk/uigtk.py

    r277 r278  
    9393        A log observer for our Twisted server 
    9494 
     95        Interestingly it carries a time timestamp. 
     96        datetime.datetime.fromtimestamp(args['time']).strftime("%b %d %H:%M:%S") 
     97 
    9598        @type args: dict 
    9699        @param args: dict {'key': [str(message)]} 
    97100        """ 
    98  
     101         
    99102        # Handle twisted errors 
    100103        # 'isError': 1, 'failure': <twisted.python.failure.Failure <type 'exceptions.AttributeError'>>  
     
    116119        @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) 
    117120        """ 
    118         
     121       
     122        if self.configuration['log']['logtimeformat']: 
     123            message = "%s %s" % (datetime.datetime.now().strftime(self.configuration['log']['logtimeformat']), message) 
     124 
    119125        self.console.message(message) 
    120126        self._write_gui_log(message, None, icon, False) 
     
    134140        """ 
    135141 
     142        if self.configuration['log']['logtimeformat']: 
     143            message = "%s %s" % (datetime.datetime.now().strftime(self.configuration['log']['logtimeformat']), message) 
     144            detailed_message = "%s %s" % (datetime.datetime.now().strftime(self.configuration['log']['logtimeformat']), detailed_message) 
     145 
    136146        self.console.message(detailed_message) 
    137147        self._write_gui_log(message, detailed_message, icon, False, False) 
     
    153163        self.simple_message = message[0] 
    154164        self.detailed_message = message[1] 
     165 
     166        if self.configuration['log']['logtimeformat']: 
     167            self.simple_message = "%s %s" % (datetime.datetime.now().strftime(self.configuration['log']['logtimeformat']), self.simple_message) 
     168            self.detailed_message = "%s %s" % (datetime.datetime.now().strftime(self.configuration['log']['logtimeformat']), self.detailed_message) 
    155169 
    156170        self.console.failure(caller, self.detailed_message, failure_type) 
     
    728742        # Build a configuration dictionary to send to the configuration engine's 
    729743        # save method. Redundant values must be included for the comparison 
    730         self.configurationdict = { 
     744        self.configuration_dict = { 
    731745            'html': 
    732746                {'html': '<img src="screenshot" alt="If you are seeing this message it means there was an error in Itaka or you are using a text-only browser.">', 
     
    741755                'scalepercent': self.scale_value[0]}, 
    742756 
     757            'log':  
     758                {'logtimeformat': '[%d/%b/%Y %H:%M:%S]', 
     759                'logfile': '~/.itaka/access.log'}, 
     760 
    743761            'server':  
    744762                {'username': self.entry_preferences_user.get_text(), 
     
    767785 
    768786        # Check if the configuration changed 
    769         if (self.configurationdict != self.current_configuration): 
     787        if (self.configuration_dict != self.current_configuration): 
    770788 
    771789            # Update the needed keys 
    772790            try: 
    773                 # self.config_instance.save(self.configurationdict) 
    774                 for section in self.configurationdict: 
    775                     [self.config_instance.update(section, key, value) for key, value in self.configurationdict[section].iteritems() if key not in self.current_configuration[section] or self.current_configuration[section][key] != value] 
     791                # self.config_instance.save(self.configuration_dict) 
     792                for section in self.configuration_dict: 
     793                    [self.config_instance.update(section, key, value) for key, value in self.configuration_dict[section].iteritems() if key not in self.current_configuration[section] or self.current_configuration[section][key] != value] 
    776794            except: 
    777795                self.log.failure(('Gui', '_save_preferences'), _('Could not save preferences'), 'ERROR') 
     
    11921210        if not self.expander.get_property("sensitive"): 
    11931211            self.expander.set_sensitive(True) 
     1212        self.expander.set_expanded(True) 
     1213 
    11941214 
    11951215    def stop_server(self, widget=None, foreign=False): 
     
    12541274        del self.status_icon 
    12551275 
    1256         self.log.verbose_message(_('Itaka Shutting down'), _('Received SIGINT, shutting down'), ['stock', 'STOCK_DISCONNECT']) 
    1257  
    12581276        self.console.message(_('Itaka shutting down')) 
    12591277 
Note: See TracChangeset for help on using the changeset viewer.