diff --git a/HACKING b/HACKING index 8ddcb65..8231d19 100644 --- a/HACKING +++ b/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 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 ================= 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 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 ============= diff --git a/mitterlib/ui/__init__.py b/mitterlib/ui/__init__.py index ab231ec..964f89f 100644 --- a/mitterlib/ui/__init__.py +++ b/mitterlib/ui/__init__.py @@ -49,6 +49,7 @@ class Interfaces(object): def __init__(self, options): self._interfaces = [] + self._priority_list = {} self._options = options self.options() return @@ -61,9 +62,17 @@ class Interfaces(object): try: _log.debug('Importing module %s', import_name) module = __import__(import_name, fromlist=[import_name]) + interface_name = module.Interface.NAMESPACE + priority = module.Interface.PRIORITY + module.Interface.options(self._options) + 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: _log.debug('Cannot import module %s', import_name) _log.debug(str(exc)) @@ -80,8 +89,10 @@ class Interfaces(object): else: # So we pick the one in the top of the list ('cause we know it's # importable and the user didn't chose anything.) - # [we could be mean and use random.choice(self._interfaces)] - import_name = self._interfaces[0] + _log.debug('Priority list: ' + str(self._priority_list)) + 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) module_name = _import_name(import_name) diff --git a/mitterlib/ui/ui_cmd.py b/mitterlib/ui/ui_cmd.py index 1170681..5bce26c 100644 --- a/mitterlib/ui/ui_cmd.py +++ b/mitterlib/ui/ui_cmd.py @@ -36,6 +36,7 @@ class Interface(cmd.Cmd): """The command line interface for Mitter.""" NAMESPACE = 'cmd' + PRIORITY = 1 # ----------------------------------------------------------------------- # Methods required by cmd.Cmd (our commands) diff --git a/mitterlib/ui/ui_pygtk.py b/mitterlib/ui/ui_pygtk.py index 92c87f7..2b21939 100644 --- a/mitterlib/ui/ui_pygtk.py +++ b/mitterlib/ui/ui_pygtk.py @@ -220,6 +220,7 @@ class Interface(object): """Linux/GTK interface for Mitter.""" NAMESPACE = 'pygtk' + PRIORITY = 20 # ------------------------------------------------------------ # Widget creation functions diff --git a/mitterlib/ui/ui_tty.py b/mitterlib/ui/ui_tty.py index ec60626..f2bc56f 100644 --- a/mitterlib/ui/ui_tty.py +++ b/mitterlib/ui/ui_tty.py @@ -31,6 +31,7 @@ class Interface(object): """The console/tty interface for Mitter.""" NAMESPACE = 'tty' + PRIORITY = 0 # ----------------------------------------------------------------------- # Private functions diff --git a/mitterlib/ui/ui_zork.py b/mitterlib/ui/ui_zork.py index 98c5ec9..2527f49 100644 --- a/mitterlib/ui/ui_zork.py +++ b/mitterlib/ui/ui_zork.py @@ -33,6 +33,7 @@ class Interface(cmd.Cmd): """A MH/zork-like interface to Mitter.""" NAMESPACE = 'zork' + PRIORITY = 1 # ----------------------------------------------------------------------- # Commands