Beispiel #1
0
def get_backend(instance_id=None):
    '''Get the cache configuration information.'''
    config = Config(instance_id)
    config.set_schema('cache', {'backend': str, 'hostname': str, 'port': int})
    cache_config = config.get('cache')

    retval = cache_config.get('backend', 'none')
    return retval
Beispiel #2
0
def get_db(instance_id=None):
    if not instance_id:
        instance_id = getInstanceId()
    # FIXME: USE LOCKING!
    if instance_id not in databases:
        config = Config(instance_id)
        config.set_schema('database', {'dsn': str})
        dsn = config.get('database')['dsn']

        top = time()
        databases[instance_id] = init_db(dsn)
        bottom = time()
        log.info("Initialised database for instance %s in %.2fs" %
                 (instance_id, (bottom - top)))
    return databases[instance_id]
Beispiel #3
0
def get_relay_address_prefix_from_config(configSet, configFileName):
    '''Get the prefix used to mark email addresses to relay from the config.

:param str configSet: The name of the configuration set to look up (see
                      :class:`gs.config.Config`)
:param str configFileName: The name of the configuration file that contains
                           the token.
:return: The address prefix for ``configSet`` in ``configFileName``, or 'p-'
         if absent.
:rtype: ``str``
'''
    config = Config(configSet, configFileName)
    config.set_schema('smtp', {'relay-address-prefix': str})
    ws = config.get('smtp', strict=False)
    retval = ws.get('relay-address-prefix', 'p-')
    return retval
Beispiel #4
0
def get_token_from_config(configSet, configFileName):
    '''Get the authentication token from the config.

:param str configSet: The name of the configuration set to look up (see
                      :class:`gs.config.Config`)
:param str configFileName: The name of the configuration file that contains
                           the token.
:return: The authentication token for ``configSet`` in ``configFileName``
:rtype: ``str``
:raises ValueError: The token was not present in ``configSet``.
'''
    config = Config(configSet, configFileName)
    config.set_schema('webservice', {'token': str})
    ws = config.get('webservice')
    retval = ws['token']
    if not retval:
        m = 'The token was not set.'
        raise ValueError(m)
    return retval
Beispiel #5
0
    def __init__(self, options):
        
        prefsfile = os.path.abspath(options.preferences)
        messagesfile = os.path.abspath(options.messages)
        settingsfile = os.path.abspath(options.settings)
        plugindir = os.path.abspath(options.plugin_dir)
        disable_plugins = options.disable_plugins

        if not os.path.exists(messagesfile):
            message_dialog("Could not find messages.xml", None, secondary="%s does not exist." % messagesfile)
            sys.exit(1)
        if not os.path.exists(settingsfile):
            message_dialog("Could not find settings.xml", None, secondary="%s does not exist." % settingsfile)
            sys.exit(1)
    
        #connect our log buffer to the python logging subsystem
        self._logbuffer = LogBuffer()
        handler = logging.StreamHandler(self._logbuffer)
        defaultFormatter = logging.Formatter(self._logbuffer.FORMAT)
        handler.setFormatter(defaultFormatter)
        logging.root.addHandler(handler)

        LOG.info("Groundstation loading")
        LOG.info("Restored preferences: %s" % prefsfile)
        LOG.info("Messages file: %s" % messagesfile)
        LOG.info("Settings file: %s" % settingsfile)
        LOG.info("Installed: %d" % gs.IS_INSTALLED)
        LOG.info("Windows: %d" % gs.IS_WINDOWS)

        try:
            GtkBuilderWidget.__init__(self, "groundstation.ui")
        except Exception:
            LOG.critical("Error loading ui file", exc_info=True)
            sys.exit(1)

        icon = get_icon_pixbuf("rocket.svg")
        gtk.window_set_default_icon(icon)

        self._tried_to_connect = False
        self._home_lat = self.CONFIG_LAT_DEFAULT
        self._home_lon = self.CONFIG_LON_DEFAULT
        self._home_zoom = self.CONFIG_ZOOM_DEFAULT

        self.window = self.get_resource("main_window")
        self.window.set_title(gs.NAME)

        self._config = Config(filename=prefsfile)
        ConfigurableIface.__init__(self, self._config)

        self._messagesfile = MessagesFile(path=messagesfile, debug=False)
        self._messagesfile.parse()

        self._settingsfile = SettingsFile(path=settingsfile)

        self._source = UAVSource(self._config, self._messagesfile, options)
        self._source.connect("source-connected", self._on_source_connected)
        self._source.connect("uav-selected", self._on_uav_selected)

        #track the UAVs we have got data from
        self._source.connect("uav-detected", self._on_uav_detected)
        self._uav_detected_model = gtk.ListStore(str,int)
        self._uav_detected_model.append( ("All UAVs", wasp.ACID_ALL) )

        #track the state of a few key variables received from the plane
        self._state = {}
        self._source.register_interest(self._on_gps, 2, "GPS_LLH")

        #All the menus in the UI. Get them the first time a plugin tries to add a submenu
        #to the UI to save startup time.
        self._menus = {
                "File"      :   None,
                "Window"    :   None,
                "Map"       :   None,
                "UAV"       :   None,
                "Help"      :   None,
        }

        self._map = Map(self._config, self._source)
        self._msgarea = MsgAreaController()
        self._sb = StatusBar(self._source)
        self._info = InfoBox(self._source, self._settingsfile)
        self._statusicon = StatusIcon(icon, self._source)

        #raise the window when the status icon clicked
        self._statusicon.connect("activate", lambda si, win: win.present(), self.window)

        self.get_resource("main_left_vbox").pack_start(self._info.widget, False, False)
        self.get_resource("window_vbox").pack_start(self._msgarea, False, False)
        self.get_resource("window_vbox").pack_start(self._sb, False, False)

        #The telemetry tab page
        self.telemetrycontroller = TelemetryController(self._config, self._source, self._messagesfile, self.window)
        self.get_resource("telemetry_hbox").pack_start(self.telemetrycontroller.widget, True, True)

        #The settings tab page
        self.settingscontroller = SettingsController(self._source, self._settingsfile, self._messagesfile)
        self.get_resource("settings_hbox").pack_start(self.settingscontroller.widget, True, True)

        #The command and control tab page
        self.commandcontroller = CommandController(self._source, self._messagesfile, self._settingsfile)
        self.get_resource("command_hbox").pack_start(self.commandcontroller.widget, False, True)
        self.controlcontroller = ControlController(self._source, self._messagesfile, self._settingsfile)
        self.get_resource("control_hbox").pack_start(self.controlcontroller.widget, True, True)
        #Track ok/failed command messages
        self._source.connect("command-ok", self._on_command_ok)
        self._source.connect("command-fail", self._on_command_fail)
        #Track logging of source
        self._source.connect("logging-started", self._on_logging_started)

        #Lazy initialize the following when first needed
        self._plane_view = None
        self._horizon_view = None
        self._prefs_window = None

        #create the map
        self.get_resource("map_holder").add(self._map.get_widget())
        self._map.connect("notify::auto-center", self.on_map_autocenter_property_change)
        self._map.connect("notify::show-trip-history", self.on_map_show_trip_history_property_change)

        #initialize the plugins
        self._plugin_manager = PluginManager(plugindir)
        if not disable_plugins:
            self._plugin_manager.initialize_plugins(self._config, self._source, self._messagesfile, self._settingsfile, self)
    
        #Setup those items which are configurable, or depend on configurable
        #information, and implement config.ConfigurableIface
        self._configurable = [
            self,
            self._source,
            self._map,
            self.telemetrycontroller.graphmanager,
        ]
        #Add those plugins that can also be configured
        self._configurable += self._plugin_manager.get_plugins_implementing_interface(ConfigurableIface)

        for c in self._configurable:
            if c:
                c.update_state_from_config()

        self.get_resource("menu_item_disconnect").set_sensitive(False)
        self.get_resource("menu_item_autopilot_disable").set_sensitive(False)
        self.builder_connect_signals()

        self.window.show_all()
Beispiel #6
0
def create_emailUtilities(instance_id=None):
    '''Create the utilities to send the email messages

:param str instance_id: The indentifier for the GroupServer instance
:returns: ``None``

The :func:`create_emailUtilities` function loads the ``smtp`` section of the
configuration of the instance specified by ``instance_id``. If no instance
is specified then :func:`gs.config.getInstanceId` is used to determine the
current instance. It then loads the following configuration options:

* ``hostname``
* ``port``
* ``username``
* ``password``
* ``no_tls``
* ``force_tls``
* ``queuepath``
* ``processorthread``
* ``xverp``

If the XVERP option is ``True`` then
:class:`gs.email.mailer.XVERPSMTPMailer` is registered as the utility used
to connect to the SMTP host; otherwise
:class:`zope.sendmail.mailer.SMTPMailer` is used. In either case the mailer
is configured with the options in the config file.'''
    if not instance_id:
        instance_id = getInstanceId()

    config = Config(instance_id)
    config.set_schema('smtp', {'hostname': str, 'port': int,
                               'username': str, 'password': str,
                               'no_tls': bool_, 'force_tls': bool_,
                               'queuepath': str, 'processorthread': bool_,
                               'xverp': bool_})
    smtpconfig = config.get('smtp', strict=False)
    name = ''
    for key in ('hostname', 'port', 'username', 'password', 'no_tls',
                'force_tls'):
        name += '+%s+' % smtpconfig.get(key, None)

    gsm = getGlobalSiteManager()
    if not queryUtility(IMailer, 'gs.mailer.%s' % name):
        if smtpconfig.get('xverp', False):
            Mailer = XVERPSMTPMailer
        else:
            Mailer = SMTPMailer

        gsm.registerUtility(
            Mailer(
                hostname=smtpconfig.get('hostname', None),
                port=smtpconfig.get('port', None),
                username=smtpconfig.get('username', None),
                password=smtpconfig.get('password', None),
                no_tls=smtpconfig.get('no_tls', None),
                force_tls=smtpconfig.get('force_tls', None)),
            IMailer, name='gs.mailer.%s' % name)
    queuePath = smtpconfig.get('queuepath', '/tmp/mailqueue')
    if not queryUtility(IMailDelivery, name='gs.maildelivery'):
        delivery = QueuedMailDelivery(queuePath)
        gsm.registerUtility(delivery, IMailDelivery, name='gs.maildelivery')
        if smtpconfig.get('processorthread', True):
            mailerObject = getUtility(IMailer, 'gs.mailer.%s' % name)
            thread = QueueProcessorThread()
            thread.setMailer(mailerObject)
            thread.setQueuePath(queuePath)
            thread.start()
Beispiel #7
0
    def __init__(self, options, show_tabs=False):

        prefsfile = os.path.abspath(options.preferences)
        messagesfile = os.path.abspath(options.messages)
        settingsfile = os.path.abspath(options.settings)
        plugindir = os.path.abspath(options.plugin_dir)
        disable_plugins = options.disable_plugins

        if not os.path.exists(messagesfile):
            message_dialog("Could not find messages.xml",
                           None,
                           secondary=gs.CONFIG_DIR)
            sys.exit(1)
        if not os.path.exists(settingsfile):
            message_dialog("Could not find settings.xml",
                           None,
                           secondary=gs.CONFIG_DIR)
            sys.exit(1)

        LOG.info("Groundstation loading")
        LOG.info("Restored preferences: %s" % prefsfile)
        LOG.info("Messages file: %s" % messagesfile)
        LOG.info("Settings file: %s" % settingsfile)

        self._messagesfile = MessagesFile(path=messagesfile, debug=False)
        self._messagesfile.parse()

        self._settingsfile = SettingsFile(path=settingsfile)

        self._config = Config(filename=prefsfile)
        ConfigurableIface.__init__(self, self._config)
        self.autobind_config("command_button", "enabled_plugins")

        self._source = UAVSource(self._config, self._messagesfile, options)
        self._tm = TabletGraphManager(self._config, self._source,
                                      self._messagesfile, self)

        self._plugin_manager = PluginManager(
            plugindir, plugin_whitelist=self._enabled_plugins)
        if not disable_plugins:
            self._plugin_manager.initialize_plugins(self._config, self._source,
                                                    self._messagesfile,
                                                    self._settingsfile, self)

        self._in_fullscreen = False

        if HILDON_AVAILABLE:
            self._win = hildon.Window()
            self._win.fullscreen()
            self._win.connect("key-press-event", self._on_hildon_key_press)
        else:
            self._win = gtk.Window()
            self._win.set_default_size(800, 480)

        self._win.set_title("Wasp Groundstation")
        self._win.connect("window-state-event", self._on_window_state_change)
        self._win.connect("destroy", self._on_close)

        vb = gtk.VBox(spacing=5)
        self._notebook = gtk.Notebook()
        if not show_tabs:
            self._notebook.set_show_tabs(False)

        self._bb = gtk.HBox()

        vb.pack_start(self._notebook, expand=True, fill=True)
        vb.pack_start(self._bb, expand=False, fill=True)
        self._win.add(vb)

        self.add_page(
            "Status",
            self.make_status_page(show_uav_info=True,
                                  show_build=True,
                                  show_comm_status=True))
        self.add_page("Telemetry", self.make_telemetry_page())

        self._configurable = [
            self._source,
            self._tm,
        ]
        for c in self._configurable:
            if c:
                c.update_state_from_config()

        gobject.timeout_add(2000, lambda: self._source.connect_to_uav())
        gobject.timeout_add(3000, lambda: self._source.refresh_uav_info())

        self._win.show_all()