Пример #1
0
def main():
    """
    [es] Inicialización de Hermes.
         Se siguen los siguientes pasos:
             1. Inicialización del subsistema de soprte a i18n
             2. Lectura de parametros de configuracion
             3. Segun los parametros ponemos en marcha el modo de 
                funcionamiento correspondiente:
                        -d: Registro a nivel DEPURACION
                    sin -d: Registro a nivel INFORMACION
                        -c: Captura de Log
                    sin -c: MODO PASIVO
             4. Lanzamiento de Hermes
    ---------------------------------------------------------------------------
    [en] Hermes initialization.
         We follow the next steps:
             1. i18n support subsystem initialization
             2. Configuration params reading
             3. Depending on the params we need to setup the corresponding
                operation mode:
                       -d: DEBUG log level
                    no -d: INFO log level 
                       -c: Log Capture
                    no -c: PASIVE MODE
             4. Hermes launch
    """
    # 1.
    # [es] Intentamos inicializar el soporte de multiples idiomas de hermes
    #      Si falla, mostramos un error en ingles y continuamos la ejecución
    #      de hermes sin soporte de i18n. En este caso, la interfaz se
    #      mostrará en ingles únicamente.
    # [en] We try to start and configure hermes' multiple languages support
    #      If we fail, we show up an english error message and continue with
    #      hermes execution without i18n support. In this case, interface will
    #      show in english only.
    try:
        import defs
        setup_gettext('hermes-hardware', defs.DATA_DIR)
    except ImportError:
        print 'WARNING: Running uninstalled, no gettext support'

    # 2.
    # [es] Extraemos las opciones de configuración de los argumentos
    #      pasados por la linea de comandos.
    # [en] We extract configuration options from the commands line
    #      arguments
    parser = OptionParser(usage=_('usage: %prog [options]'))
    parser.set_defaults(debug=False)
    parser.set_defaults(capture_log=False)

    parser.add_option('-d',
                      '--debug',
                      action='store_true',
                      dest='debug',
                      help=_('Starts in debug mode.'))

    parser.add_option('-c',
                      '--capture-log',
                      action='store_true',
                      dest='capture_log',
                      help=_('Capture device logs.'))

    (options, args) = parser.parse_args()
    del args

    # 3.
    # [es] Activamos el registro de actividad a nivel de depuración si se
    #      recibió el parámetro -d o a nivel informativo si no se recibio -d.
    #      Iniciamos en modo captura de cadenas de identificación de hardware
    #      si se recibio -c o en modo pasivo en caso contrario
    # [en] We start activity log in debug mode if we got -d param or in info
    #      mode if we didn´t.
    #      We start in hardware identification strings capture mode if we got
    #      -c param or in passive mode otherwise.

    if options.debug:
        level = logging.DEBUG
    else:
        level = logging.INFO

    logfilename = '/var/tmp/hermes-hardware-' + \
                  os.environ['USER'] + str(os.getuid()) + '.log'

    logging.basicConfig(level=level,
                        format='%(asctime)s %(levelname)s %(message)s',
                        filename=logfilename,
                        filemode='a')

    if options.capture_log:
        filepath = '/var/tmp/filenotification-' + \
                os.environ['USER'] + str(os.getuid()) + \
                '.log'
        iface = FileNotification(filepath)
        capture_log_gui = CaptureLogGui()
    else:
        iface = NotificationDaemon()

    logging.getLogger().info(_("------------ Hermes started."))

    # 4.
    # [es] Iniciamos el dispositivo de escucha, creamos el icono en la barra
    #      de iconos del escritorio e iniciamos soporte multihilo para Hermes.
    #      Finalmente lanzamos el proceso principal de la aplicacion GTK.
    # [en] We start devices listener, create an icon inside TrayIcon Bar and
    #      start multithreading support for Hermes.
    #      Finally we launch the main GTK application process.

    global DeviceActor
    from actors.deviceactor import DeviceActor

    DeviceListener(iface, with_cold=False)
    HermesTrayIcon()
    gtk.gdk.threads_init()
    try:
        gtk.main()
    except:
        # [es] Antes de terminar debemos cerrar el fichero de registro de
        #      dispositivos
        # [en] Before finishing we must close the device log file
        if 'capture_log_gui' in locals():
            capture_log_gui.logfile.close()

        logging.getLogger().info(_("------------ Hermes finished."))
Пример #2
0
def main():
    try:
        import defs
        setup_gettext('hermes-hardware', defs.DATA_DIR)
    except ImportError:
        print 'WARNING: Running uninstalled, no gettext support'

    # Configure options
    parser = OptionParser(usage='usage: %prog [options]')
    parser.set_defaults(debug=False)
    parser.set_defaults(capture_log=False)

    parser.add_option('-d',
                      '--debug',
                      action='store_true',
                      dest='debug',
                      help='start in debug mode')

    parser.add_option('-c',
                      '--capture-log',
                      action='store_true',
                      dest='capture_log',
                      help='Capture device logs.')

    (options, args) = parser.parse_args()
    del args

    # Option debug for logging
    if options.debug:
        level = logging.DEBUG
    else:
        level = logging.INFO

    logfilename = '/var/tmp/hermes-hardware-' + \
            os.environ['USER'] + str(os.getuid()) + \
            '.log'

    logging.basicConfig(level=level,
                        format='%(asctime)s %(levelname)s %(message)s',
                        filename=logfilename,
                        filemode='a')

    # Set capture log
    if options.capture_log:
        filepath = '/var/tmp/filenotification-' + \
                os.environ['USER'] + str(os.getuid()) + \
                '.log'
        iface = FileNotification(filepath)
        capture_log_gui = CaptureLogGui()
    else:
        iface = NotificationDaemon()

    logging.getLogger().info("----------------------------- Hermes init.")

    global DeviceActor
    from actors.deviceactor import DeviceActor

    DeviceListener(iface)
    gtk.gdk.threads_init()
    try:
        gtk.main()
    except:
        if 'capture_log_gui' in locals():
            # Close file for write in hd.
            capture_log_gui.logfile.close()

        logging.getLogger().info(
            "----------------------------- Hermes finish.")
Пример #3
0
 def setUp(self):
     if not ActorTest.devicelistener:
         iface =  NotificationDaemon()
         ActorTest.devicelistener = hermes_hardware.DeviceListener(iface)
         ActorTest.devicelistener.bus = dbus.SessionBus()
         VirtualHal.get_instance()
 def setUp(self):
     self.msg_render = NotificationDaemon()
class NotifyTest(unittest.TestCase):
    def setUp(self):
        self.msg_render = NotificationDaemon()

    def test_show_stock_icon(self):
        """Testing NotificationDaemon.show method with stock icons
        """

        actions = {"Click me": None}
        # Test stock icons
        nid = self.msg_render.show(_("Test"), _("Test message"), "gtk-dialog-info", actions=actions)
        self.failUnless(isinstance(nid, int))
        time.sleep(TIMEOUT)
        self.msg_render.close(nid)

    def test_show_file_icon(self):
        """Testing NotificationDaemon.show method with icon file 
        """

        actions = {"Click me": None}
        # Test stock icons
        nid = self.msg_render.show(_("Test"), _("Test message"), ICON, actions=actions)
        self.failUnless(isinstance(nid, int))
        time.sleep(TIMEOUT)
        self.msg_render.close(nid)

    def test_info(self):
        """Testing NotificationDaemon.show_info method
        """

        nid = self.msg_render.show_info(_("Information"), _("Test message"))
        self.failUnless(isinstance(nid, int))
        time.sleep(TIMEOUT)
        self.msg_render.close(nid)

    def test_warning(self):
        """Testing NotificationDaemon.show_info method
        """

        nid = self.msg_render.show_warning(_("Warning"), _("Test message"))
        self.failUnless(isinstance(nid, int))
        time.sleep(TIMEOUT)
        self.msg_render.close(nid)

    def test_error(self):
        """Testing NotificationDaemon.show_info method
        """
        nid = self.msg_render.show_error(_("Error"), _("Test message"))
        self.failUnless(isinstance(nid, int))
        time.sleep(TIMEOUT)
        self.msg_render.close(nid)
Пример #6
0
 def setUp(self):
     self.msg_render = NotificationDaemon()
Пример #7
0
class NotifyTest(unittest.TestCase):
    def setUp(self):
        self.msg_render = NotificationDaemon()

    def test_show_stock_icon(self):
        """Testing NotificationDaemon.show method with stock icons
        """

        actions = {"Click me": None}
        # Test stock icons
        nid = self.msg_render.show("Test",
                                   "Test message",
                                   "gtk-dialog-info",
                                   actions=actions)
        self.failUnless(isinstance(nid, int))
        time.sleep(TIMEOUT)
        self.msg_render.close(nid)

    def test_show_file_icon(self):
        """Testing NotificationDaemon.show method with icon file 
        """

        actions = {"Click me": None}
        # Test stock icons
        nid = self.msg_render.show("Test",
                                   "Test message",
                                   ICON,
                                   actions=actions)
        self.failUnless(isinstance(nid, int))
        time.sleep(TIMEOUT)
        self.msg_render.close(nid)

    def test_info(self):
        """Testing NotificationDaemon.show_info method
        """

        nid = self.msg_render.show_info("Information", "Test message")
        self.failUnless(isinstance(nid, int))
        time.sleep(TIMEOUT)
        self.msg_render.close(nid)

    def test_warning(self):
        """Testing NotificationDaemon.show_info method
        """

        nid = self.msg_render.show_warning("Warning", "Test message")
        self.failUnless(isinstance(nid, int))
        time.sleep(TIMEOUT)
        self.msg_render.close(nid)

    def test_error(self):
        """Testing NotificationDaemon.show_info method
        """
        nid = self.msg_render.show_error("Error", "Test message")
        self.failUnless(isinstance(nid, int))
        time.sleep(TIMEOUT)
        self.msg_render.close(nid)