Changeset 297

Show
Ignore:
Timestamp:
06/10/06 17:34:49 (2 years ago)
Author:
nicfit
Message:

Prevented gst from intercepting --help, and added -l/--log-level

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/po/es.po

    r291 r297  
    88"Project-Id-Version: 0.1.1\n" 
    99"Report-Msgid-Bugs-To: \n" 
    10 "POT-Creation-Date: 2006-06-10 15:42-0600\n" 
     10"POT-Creation-Date: 2006-06-10 17:32-0600\n" 
    1111"PO-Revision-Date: 2006-04-15 17:38-0600\n" 
    1212"Last-Translator: Travis Shirk <travis@pobox.com>\n" 
     
    237237msgstr "Error: no puede abrir %s para la lectura" 
    238238 
    239 #: ../src/main.py:64 
    240 msgid "Select a specific profile other than the default" 
     239#: ../src/main.py:51 
     240#, fuzzy 
     241msgid "Select a specific profile." 
    241242msgstr "Seleccione un perfil específico con excepción del defecto" 
    242243 
     244#: ../src/main.py:54 
     245#, fuzzy 
     246msgid "" 
     247"Select the amount of terminal logging.  May be CRITICAL, ERROR, WARNING, " 
     248"INFO, VERBOSE, or DEBUG" 
     249msgstr "" 
     250"Registración llano. Puede ser CRITICAL, ERROR, WARNING, INFO, VERBOSE, o " 
     251"DEBUG" 
     252 
    243253#. TODO: Run version upgrade migration routines 
    244 #: ../src/main.py:93 
     254#: ../src/main.py:90 
    245255#, python-format 
    246256msgid "Upgrading config version %s to %s" 
    247257msgstr "Aumento de la versión %s de los config a %s" 
    248258 
    249 #: ../src/main.py:113 
     259#: ../src/main.py:110 
    250260msgid "Session management disabled (no gnome.ui module)" 
    251261msgstr "La gerencia de la sesión inhabilitó (ningún módulo de gnome.ui)" 
  • trunk/po/mesk.pot

    r291 r297  
    99"Project-Id-Version: PACKAGE VERSION\n" 
    1010"Report-Msgid-Bugs-To: \n" 
    11 "POT-Creation-Date: 2006-06-10 15:42-0600\n" 
     11"POT-Creation-Date: 2006-06-10 17:32-0600\n" 
    1212"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 
    1313"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" 
     
    236236msgstr "" 
    237237 
    238 #: ../src/main.py:64 
    239 msgid "Select a specific profile other than the default" 
     238#: ../src/main.py:51 
     239msgid "Select a specific profile." 
     240msgstr "" 
     241 
     242#: ../src/main.py:54 
     243msgid "" 
     244"Select the amount of terminal logging.  May be CRITICAL, ERROR, WARNING, " 
     245"INFO, VERBOSE, or DEBUG" 
    240246msgstr "" 
    241247 
    242248#. TODO: Run version upgrade migration routines 
    243 #: ../src/main.py:93 
     249#: ../src/main.py:90 
    244250#, python-format 
    245251msgid "Upgrading config version %s to %s" 
    246252msgstr "" 
    247253 
    248 #: ../src/main.py:113 
     254#: ../src/main.py:110 
    249255msgid "Session management disabled (no gnome.ui module)" 
    250256msgstr "" 
  • trunk/src/main.py

    r291 r297  
    2727 
    2828import mesk 
     29_ = mesk.common.i18n._ 
    2930import mesk.plugin 
    3031 
    31 from main_window import MainWindow 
    3232from optparse import OptionParser 
    3333 
     
    3535from mesk.info import APP_VERSION 
    3636 
    37 _ = mesk.common.i18n._ 
    38 class MeskApp: 
    39     def __init__(self): 
    40         '''Constructor''' 
    41  
    42     def run(self, opts, args): 
    43         self.opts = opts 
    44         self.args = args 
    45  
    46         self.main_window = MainWindow() 
    47         self.main_window.show() 
    48  
    49         # Initialize plugin manager 
    50         plugin_mgr = mesk.plugin.PluginMgr(mesk.config.get(mesk.CONFIG_MAIN, 
    51                                                            'plugins_dir')) 
    52         mesk.plugin.set_manager(plugin_mgr) 
    53          
    5437### Main function ### 
    5538def main(): 
     
    5841 
    5942    # Parse command line 
    60     # FIXME: gst is intercepting --help and not showing the real help 
    61     cmd_line = OptionParser(usage='%s [options]' % APP_NAME.lower(), 
    62                             version='%s %s' % (APP_NAME, APP_VERSION)) 
     43    version_str = '%s %s %s\n%s' % \ 
     44                  (APP_NAME, APP_VERSION, 
     45                   "(C) Copyright 2006 Travis Shirk <travis@pobox.com>", 
     46                   "This program comes with ABSOLUTELY NO WARRANTY! See " 
     47                   "COPYING for details.") 
     48    cmd_line = OptionParser(usage = '%s [options]' % APP_NAME.lower(), 
     49                            version = version_str) 
    6350    cmd_line.add_option('-p', '--profile', dest='profile', 
    64                         help=_('Select a specific profile other than ' 
    65                                'the default'), 
    66                         metavar='PROFILE', default='') 
     51                        help=_('Select a specific profile.'), 
     52                        metavar='name', default='') 
     53    cmd_line.add_option('-l', '--log-level', dest='log_level', 
     54                        help=_('Select the amount of terminal logging.  May be ' 
     55                               'CRITICAL, ERROR, WARNING, INFO, VERBOSE, or ' 
     56                               'DEBUG'), 
     57                        metavar='level', default='') 
    6758 
    6859    (opts, args) = cmd_line.parse_args() 
     
    8677    # Initialize logging 
    8778    mesk.log.init(mesk.config) 
     79    if opts.log_level: 
     80        lvl = mesk.log.string_to_level(opts.log_level) 
     81        if lvl is None: 
     82            mesk.log.error('Invalid log level: %s' % opts.log_level) 
     83            return 1 
     84        mesk.log.set_logging_level(lvl) 
    8885 
    8986    # Update config version 
     
    144141    mesk.log.debug('Exiting: %d' % retval) 
    145142    return retval 
     143 
     144class MeskApp: 
     145    def __init__(self): 
     146        '''Constructor''' 
     147 
     148    def run(self, opts, args): 
     149        self.opts = opts 
     150        self.args = args 
     151 
     152        # This results in an import of gst, which during initialization will 
     153        # look for command line arguments and handle them, preventing --help 
     154        # from displaying our usage.  Delaying until now for this reason. 
     155        from main_window import MainWindow 
     156 
     157        self.main_window = MainWindow() 
     158        self.main_window.show() 
     159 
     160        # Initialize plugin manager 
     161        plugin_mgr = mesk.plugin.PluginMgr(mesk.config.get(mesk.CONFIG_MAIN, 
     162                                                           'plugins_dir')) 
     163        mesk.plugin.set_manager(plugin_mgr) 
     164 
     165### Main ### 
    146166if __name__ == "__main__": 
    147    sys.exit(main()); 
     167   sys.exit(main()) 
  • trunk/src/mesk/log.py

    r127 r297  
    3030    logging.getLogger().addHandler(console) 
    3131 
    32     logging.getLogger().setLevel(get_logging_level(config)) 
     32    set_logging_level(get_logging_level(config)) 
    3333 
    3434VERBOSE = 15 
     
    4141                                   '<%(name)s>:[%(levelname)s] %(message)s') 
    4242 
    43 def get_logging_level(config): 
    44     lvl = config.get('mesk', 'log_level') 
    45     if lvl == 'INFO': 
     43def get_logging_level(config = None): 
     44    if config is None: 
     45        return logging.getLogger().getLevel() 
     46    else: 
     47        lvl = config.get('mesk', 'log_level') 
     48        return string_to_level(lvl) 
     49 
     50def string_to_level(lvl): 
     51    if lvl.upper() == 'INFO': 
    4652        return logging.INFO 
    47     elif lvl == 'WARNING': 
    48         return logging.WARRANTY 
    49     elif lvl == 'ERROR': 
     53    elif lvl.upper() == 'WARNING': 
     54        return logging.WARNING 
     55    elif lvl.upper() == 'ERROR': 
    5056        return logging.ERROR 
    51     elif lvl == 'CRITICAL': 
     57    elif lvl.upper() == 'CRITICAL': 
    5258        return logging.CRITICAL 
    53     elif lvl == 'DEBUG': 
     59    elif lvl.upper() == 'DEBUG': 
    5460        return logging.DEBUG 
    5561    # Custom levels 
    56     elif lvl == 'VERBOSE': 
     62    elif lvl.upper() == 'VERBOSE': 
    5763        return VERBOSE 
    5864    return None 
     65 
     66 
     67def set_logging_level(level): 
     68    logging.getLogger().setLevel(level)