Browse Source

Interface priority. fixes #176

master
Julio Biason 15 years ago
parent
commit
20d03d427f
  1. 19
      HACKING
  2. 15
      mitterlib/ui/__init__.py
  3. 1
      mitterlib/ui/ui_cmd.py
  4. 1
      mitterlib/ui/ui_pygtk.py
  5. 1
      mitterlib/ui/ui_tty.py
  6. 1
      mitterlib/ui/ui_zork.py

19
HACKING

@ -82,6 +82,11 @@ phase to populate the interface options. To add an option, use the
``add_option``; if your interface don't have any options, simply ``add_option``; if your interface don't have any options, simply
return. Again, refer to the ConfigOpt_ documentation on how to use it. return. Again, refer to the ConfigOpt_ documentation on how to use it.
NAMESPACE
---------
The namespace is a class variable used to identify the name of the
network. It should also be used in the config as the group name.
Creating Networks Creating Networks
================= =================
Naming and Location Naming and Location
@ -119,6 +124,20 @@ the ``NetworkManager`` section, ``proxy`` value. The network manager
itself will install a urllib2 proxy handler, so you don't need to itself will install a urllib2 proxy handler, so you don't need to
worry about manually installing a handler yourself if you use urllib2. worry about manually installing a handler yourself if you use urllib2.
NAMESPACE
---------
The namespace is a class variable used to name the interface. It's
also used in the ``--interface`` so the user can name the interfaces
they want.
PRIORITY
--------
Interface priority, as a class variable. It's used by the interface
manager to select an interface in case the user doesn't have one. The
higher this value, the higher the priority. Be sure to put interfaces
with more dependencies with higher priorities, as those should be, in
theory, more full featured.
Mixing It All Mixing It All
============= =============

15
mitterlib/ui/__init__.py

@ -49,6 +49,7 @@ class Interfaces(object):
def __init__(self, options): def __init__(self, options):
self._interfaces = [] self._interfaces = []
self._priority_list = {}
self._options = options self._options = options
self.options() self.options()
return return
@ -61,9 +62,17 @@ class Interfaces(object):
try: try:
_log.debug('Importing module %s', import_name) _log.debug('Importing module %s', import_name)
module = __import__(import_name, fromlist=[import_name]) module = __import__(import_name, fromlist=[import_name])
interface_name = module.Interface.NAMESPACE interface_name = module.Interface.NAMESPACE
priority = module.Interface.PRIORITY
module.Interface.options(self._options) module.Interface.options(self._options)
self._interfaces.append(interface_name) self._interfaces.append(interface_name)
if priority in self._priority_list:
self._priority_list[priority].append(interface_name)
else:
self._priority_list[priority] = [interface_name]
except ImportError, exc: except ImportError, exc:
_log.debug('Cannot import module %s', import_name) _log.debug('Cannot import module %s', import_name)
_log.debug(str(exc)) _log.debug(str(exc))
@ -80,8 +89,10 @@ class Interfaces(object):
else: else:
# So we pick the one in the top of the list ('cause we know it's # So we pick the one in the top of the list ('cause we know it's
# importable and the user didn't chose anything.) # importable and the user didn't chose anything.)
# [we could be mean and use random.choice(self._interfaces)] _log.debug('Priority list: ' + str(self._priority_list))
import_name = self._interfaces[0] priority = sorted(self._priority_list.keys(), reverse=True)
top_priority = priority[0]
import_name = self._priority_list[top_priority][0]
_log.debug('Loading interface %s', import_name) _log.debug('Loading interface %s', import_name)
module_name = _import_name(import_name) module_name = _import_name(import_name)

1
mitterlib/ui/ui_cmd.py

@ -36,6 +36,7 @@ class Interface(cmd.Cmd):
"""The command line interface for Mitter.""" """The command line interface for Mitter."""
NAMESPACE = 'cmd' NAMESPACE = 'cmd'
PRIORITY = 1
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
# Methods required by cmd.Cmd (our commands) # Methods required by cmd.Cmd (our commands)

1
mitterlib/ui/ui_pygtk.py

@ -220,6 +220,7 @@ class Interface(object):
"""Linux/GTK interface for Mitter.""" """Linux/GTK interface for Mitter."""
NAMESPACE = 'pygtk' NAMESPACE = 'pygtk'
PRIORITY = 20
# ------------------------------------------------------------ # ------------------------------------------------------------
# Widget creation functions # Widget creation functions

1
mitterlib/ui/ui_tty.py

@ -31,6 +31,7 @@ class Interface(object):
"""The console/tty interface for Mitter.""" """The console/tty interface for Mitter."""
NAMESPACE = 'tty' NAMESPACE = 'tty'
PRIORITY = 0
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
# Private functions # Private functions

1
mitterlib/ui/ui_zork.py

@ -33,6 +33,7 @@ class Interface(cmd.Cmd):
"""A MH/zork-like interface to Mitter.""" """A MH/zork-like interface to Mitter."""
NAMESPACE = 'zork' NAMESPACE = 'zork'
PRIORITY = 1
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
# Commands # Commands

Loading…
Cancel
Save