Beispiel #1
0
 def translate(self, msg):
     assert issubclass(msg, BaseMessage)
     show("In %d" % msg.payload)
     if 0 == msg.payload % 2:
         msg.payload = 0 - msg.payload
     show("Out %d" % msg.payload)
     return msg
Beispiel #2
0
    def run(self):
        trace()
        n = 0
        s = 0
        _max = 0
        _min = None

        for msg in self.iter:
            trace()
            assert issubclass(
                type(msg),
                WireMessage), "unexpected message type: %s" % str(type(msg))
            n += 1
            s += len(msg)
            if len(msg) > _max:
                _max = len(msg)
            if not _min or _min > len(msg):
                _min = len(msg)
            self.file.write(msg)

        self.file.close()

        show("%d messages read" % n)
        show("%d bytes read" % s)
        show("%d = average message size" % int(s / n))
        show("%d = minimum message size" % _min)
        show("%d = maximum message size" % _max)
Beispiel #3
0
    def run(self):
        n = 0
        peers = {}
        for msg in self.iter:
            assert issubclass(
                type(msg),
                BGPMessage), "unexpected message type: %s" % str(type(msg))
            n += 1
            bgp_msg = None
            bgp_msg_type = -1
            bmp_msg_type = msg.msg_type
            #trace(str( msg.peer ))
            peer = msg.peer['hash']
            if not peer in peers:
                show("adding new BMP peer context")
                peers[peer] = bgplib.bgpcontext.BGP_context(msg.peer)
                #peers[peer] = bgplib.bgpcontext.new_headless_context()

            if not msg.msg is None:
                bgp_msg = BGP_message(msg.msg)
                peers[peer].consume(msg.msg)
                bgp_msg_type = bgp_msg.bgp_type
            trace("message %d type %d/%d" % (n, bmp_msg_type, bgp_msg_type))

        show("%d messages read" % n)
        for peer in peers.values():
            info(str(peer))
Beispiel #4
0
 def __gen__(self):
     info("GEN START")
     for n in range(4):
         info("GEN NEXT")
         msg = BaseMessage()
         msg.payload = n
         show("Out %d" % msg.payload)
         yield msg
     info("GEN END (%d cycles)" % (n + 1))
Beispiel #5
0
 def __next__(self):
     info("ITER NEXT")
     if self.n > 3:
         info("ITER END (%d cycles)" % self.n)
         raise StopIteration
     msg = BaseMessage()
     msg.payload = self.n
     show("Out %d" % msg.payload)
     self.n += 1
     return msg
Beispiel #6
0
def startMainLoop():
    """Start the wxWidgets main loop."""

    # Before we give wxPython all control, update the layout of UI
    # areas.
    app.showMainWindow()

    # Display any issues that came up during init.
    logger.show()

    # Notify everyone that the main loop is about to kick in.
    events.send(events.Notify('init-done'))

    app.MainLoop()
Beispiel #7
0
def startMainLoop():
    """Start the wxWidgets main loop."""

    # Before we give wxPython all control, update the layout of UI
    # areas.
    app.showMainWindow()

    # Display any issues that came up during init.
    logger.show()

    # Notify everyone that the main loop is about to kick in.
    events.send(events.Notify('init-done'))

    app.MainLoop()
def send(event):
    """Broadcast an event to all listeners of the appropriate type.
    The event is processed synchronously: all listeners will be
    notified immediately during the execution of this function.

    @param event The event to send.  All listeners will get the same
    event object.
    """
    if areEventsMuted:
        return # Discard.

    global sendDepth, queuedEvents

    sendDepth += 1
    
    # Commands and Notifys go to a different set of listeners.
    if event.myClass == Command:
        listeners = commandListeners
    else:
        listeners = notifyListeners

    # The identifier of the event to be sent.
    sendId = event.getId()
    
    # Always include the unfiltered callbacks.
    callbacks = [c for c in listeners[None]]
    
    if listeners.has_key(sendId):
        # The specialized callbacks.
        callbacks += listeners[sendId]

    #print "Sending " + sendId + ":"
    #print callbacks

    # Send the event to all the appropriate listeners.
    for callback in callbacks:
        try:
            callback(event)
        except Exception, x:
			# Report errors.
            import logger
            logger.add(logger.HIGH, 'error-runtime-exception-during-event',
					   sendId, str(x), logger.formatTraceback())
            logger.show()
Beispiel #9
0
    def run(self):
        trace("")
        n = 0
        s = 0
        _max = 0
        _min = None

        for msg in self.iter:
            if n == 0:
                info("message type = %s" % str(type(msg)))
            n += 1
            s += len(msg)
            if len(msg) > _max:
                _max = len(msg)
            if not _min or _min > len(msg):
                _min = len(msg)

        show("%d messages read" % n)
        show("%d bytes read" % s)
        show("%d = average message size" % int(s / n))
        show("%d = minimum message size" % _min)
        show("%d = maximum message size" % _max)
Beispiel #10
0
 def run(self):
     show("run starts")
     n = 0
     for msg in self.next:
         show("message received, type %s" % str(type(msg)))
         n += 1
         trace("process message %d" % n)
     show("run ends - %d cycles" % n)
Beispiel #11
0
import sb.addon
import logger


def run():
    # Open the file selection dialog.
    for selection in chooseAddons('install-addon-dialog',
                                  language.translate('install-addon-title'),
                                  'install'):
        try:
            ao.install(selection)
        except Exception, ex:
            logger.add(logger.HIGH, 'error-addon-installation-failed',
                       selection, str(ex))

    logger.show()


def chooseAddons(dialogId, title, actionButton):
    """Opens an addon selection dialog.

    @param title Title of the dialog.

    @param actionButton The button that will perform the affirmative
    action of the dialog.
    """
    dialog, area = sb.util.dialog.createButtonDialog(dialogId, 
        ['cancel', actionButton], 
        actionButton)

    dialog.addEndCommand('addon-dialog-add-to-custom-folders')
import sb.addon
import logger


def run():
    # Open the file selection dialog.
    for selection in chooseAddons('install-addon-dialog',
                                  language.translate('install-addon-title'),
                                  'install'):
        try:
            ao.install(selection)
        except Exception, ex:
            logger.add(logger.HIGH, 'error-addon-installation-failed',
                       selection, str(ex))

    logger.show()


def chooseAddons(dialogId, title, actionButton):
    """Opens an addon selection dialog.

    @param title Title of the dialog.

    @param actionButton The button that will perform the affirmative
    action of the dialog.
    """
    dialog, area = sb.util.dialog.createButtonDialog(dialogId,
                                                     ['cancel', actionButton],
                                                     actionButton)

    dialog.addEndCommand('addon-dialog-add-to-custom-folders')
def restore():
    """Reads all the profiles from disk.  Restores the currently active
    profile as well.  This function has to be called after starting
    the program before any profiles are accessed.

    System profiles that aren't present in the user's profile
    directory are copied to the user's profile directory.
    """
    global defaults
    global profiles
    global restoredActiveId

    # By default, restore selection to the Defaults profile.
    restoredActiveId = 'defaults'

    # Clear the current profile list.
    profiles = []

    systemProfilePaths = [paths.getSystemPath(paths.PROFILES)] + \
                          paths.getBundlePaths(paths.PROFILES)
    userProfilePath = paths.getUserPath(paths.PROFILES)

    # List all the system and user profiles.
    availSystem = _listProfilesIn(systemProfilePaths)
    availUser = _listProfilesIn([userProfilePath])

    # We are going to load only the profiles in the user's direcory,
    # but before that make sure that the user has an instance of each
    # system profile.
    for sysFile in availSystem:
        identifier = paths.getBase(sysFile)

        # Does this exist in the user's directory?
        gotIt = False
        for userFile in availUser:
            if paths.getBase(userFile) == identifier:
                gotIt = True
                break

        if not gotIt:
            # Since the system profile does not exist on the user,
            # copy it to the user profile directory.
            shutil.copyfile(
                sysFile,
                os.path.join(userProfilePath, os.path.basename(sysFile)))

    # Find every profile in system's and user's profile directories.
    # Files in the user's directory augment the files in the system
    # directory.
    for name in _listProfilesIn([userProfilePath]):
        load(os.path.join(userProfilePath, name), False)
    logger.show()

    defaults = get('defaults')

    if defaults is None:
        # Recreate the Defaults profile.
        load(os.path.join(systemProfilePath, "defaults.prof"), False)
        defaults = get('defaults')
        logger.show()

    # Set the default language.
    lang = defaults.getValue('language')
    if lang:
        language.change(lang.getValue())

    # Send profile-loaded notifications.
    for p in profiles:
        if not p.isHidden():
            events.send(events.ProfileNotify(p))

    # Restore the previously active profile.
    prof = get(restoredActiveId)
    if prof:
        setActive(prof)
    else:
        setActive(defaults)
Beispiel #14
0
def restore():
    """Reads all the profiles from disk.  Restores the currently active
    profile as well.  This function has to be called after starting
    the program before any profiles are accessed.

    System profiles that aren't present in the user's profile
    directory are copied to the user's profile directory.
    """
    global defaults
    global profiles
    global restoredActiveId

    # By default, restore selection to the Defaults profile.
    restoredActiveId = 'defaults'

    # Clear the current profile list.
    profiles = []

    systemProfilePaths = [paths.getSystemPath(paths.PROFILES)] + \
                          paths.getBundlePaths(paths.PROFILES)
    userProfilePath = paths.getUserPath(paths.PROFILES)

    # List all the system and user profiles.
    availSystem = _listProfilesIn(systemProfilePaths)
    availUser = _listProfilesIn([userProfilePath])

    # We are going to load only the profiles in the user's direcory,
    # but before that make sure that the user has an instance of each
    # system profile.
    for sysFile in availSystem:
        identifier = paths.getBase(sysFile)

        # Does this exist in the user's directory?
        gotIt = False
        for userFile in availUser:
            if paths.getBase(userFile) == identifier:
                gotIt = True
                break

        if not gotIt:
            # Since the system profile does not exist on the user,
            # copy it to the user profile directory.
            shutil.copyfile(sysFile,
                            os.path.join(userProfilePath,
                                         os.path.basename(sysFile)))

    # Find every profile in system's and user's profile directories.
    # Files in the user's directory augment the files in the system
    # directory.
    for name in _listProfilesIn([userProfilePath]):
        load(os.path.join(userProfilePath, name), False)
    logger.show()

    defaults = get('defaults')

    if defaults is None:
        # Recreate the Defaults profile.
        load(os.path.join(systemProfilePath, "defaults.prof"), False)
        defaults = get('defaults')
        logger.show()

    # Set the default language.
    lang = defaults.getValue('language')
    if lang:
        language.change(lang.getValue())

    # Send profile-loaded notifications.
    for p in profiles:
        if not p.isHidden():
            events.send(events.ProfileNotify(p))

    # Restore the previously active profile.
    prof = get(restoredActiveId)
    if prof:
        setActive(prof)
    else:
        setActive(defaults)