Differences between revisions 14 and 15
Revision 14 as of 2009-08-21 12:57:47
Size: 9255
Editor: 65-78-0-53
Revision 15 as of 2009-08-21 13:00:18
Size: 9260
Editor: 65-78-0-53
Deletions are marked like this. Additions are marked like this.
Line 133: Line 133:
import gtk
Line 143: Line 142:
        import gtk
Line 145: Line 145:
        self.builder.add_from_file('/usr/share/ubiquity-foo/')         self.builder.add_from_file('/usr/share/ubiquity-foo/foo.ui')

Here, I describe a possible system for enabling drop-in plugins for Ubiquity and OEM-config.


  • Insert a page: The ability to add a page anywhere in the page sequence
  • Hide a page: The ability to stop a standard page from showing up (the combination of inserting/hiding lets you replace a page)
  • The ability to prevent going forward (say, a EULA page that requires an approval checkbox). Might as well also allow preventing going back.
  • Let plugins be translatable
  • Let plugins execute code after user is done entering any info, to actually do what user asks
  • Let plugins offer gtk or kde UI (or debconf or noninteractive, etc if desired)


  • Reduce plugin's exposure to Ubiquity internals, to make them more change-proof.
  • Allow plugins to be pure Python (no required shell)


What a plugin looks like

Bits of a standard gtk page:

  • A glade file
  • A debconf filter
  • Ask and apply scripts

With the above, by providing the above files, we can do everything a normal page can in a plugin. Assuming Ubiquity knows how to find the files.

The asking can be provided by Ubiquity, as long as the plugin gives us a list of debconf questions to ask. And the apply script could just be done by the filter by a special 'apply' method. Then all a plugin needs is a filter and a UI file.

We could additionally dumb down the python a plugin needs to provide by having them be 'filter lites' custom classes that didn't do everything a filter does. But the filter parent classes already provide good default methods. We should probably have a plugin parent class that sits between the debconf filter and the plugin, just to provide further default methods and any special configuration we need.

How the plugin will talk to its own UI

The plugin will have UI classes like 'PageGtk' or 'PageKde' or 'PageNoninteractive' which will be instantiated by Ubiquity and passed to the filter class. If the right class for the current frontend isn't find, the plugin is ignored. For GUI frontends, a method get_ui() can be called to get frontend-specific objects and info. This will return a dictionary object with keys that the frontend knows. (For GTK, 'widgets' containing a list of pages and 'optional_widgets').

The plugin can install the UI files (.glade, .ui) anywhere it wants, because it is responsible for loading it. The GTK and KDE frontends only want to see actual widgets.

How the plugin is translated

Plugins can use their own debconf template. Ubiquity will do the translation for it, from its template.

How to find the plugin

Plugins drop python page files in /usr/lib/ubiquity/plugins.d/

How to order/add/remove pages

Plugins has a module-wide NAME field that specifies a name to use. The recommended NAME for pages would be similar to the module name that defines the page. For third-party plugins, using a namespace (e.g. 'foo-page' and 'foo-page2') is recommended.

To insert your page into the sequence of pages, use AFTER or BEFORE fields.

BEFORE=['language', None]

Pages can be hidden from a HIDDEN field (a list would also work):

  • If neither AFTER or BEFORE are specified, the page will not be used, but may still specify other plugin options, like HIDDEN. (i.e. a page that only hides, and does not insert itself)
  • If AFTER or BEFORE is a list of names, the first component that Ubiquity recognizes is used.
  • If both AFTER and BEFORE are specified, Ubiquity will use AFTER if it recognizes it, else use BEFORE.
  • If Ubiquity still can't find a value that it recognizes, the page is ignored (and other plugin options like HIDDEN are not used -- it's likely this page is optional, pending installation of some package we don't have or was written for an older Ubiquity).

  • If AFTER's value is None or otherwise 'Python-false', it is inserted at the beginning of the page sequence.
  • If BEFORE's value is None or otherwise 'Python-false', it is inserted at the end of the page sequence.

Ties (where two pages specify 'after language' for example) are broken by file system ordering in plugins.d. Ubiquity reads the plugins.d files in order, and resolves names as they come in. The number before the filename can thus be considered a priority then for ties. i.e. if both 10-mypage and 22-otherpage specify AFTER=language, 22 would be first in the resulting sequence, then 10.

PageGtk Design

The PageGtk class must provide an init that takes at least one argument. Additional keyword arguments are allowed, but not currently used.

This first argument is a 'controller' class, specified below. This is how PageGtk can provide feedback to the 'real' frontend.

It must provide a method called get_ui(self) that returns a dictionary with 'widgets' and optionally, 'optional_widgets' fields. 'widgets' is a list or singleton of GTK pages (usually just a single page).

PageKde Design

The PageKde class must provide an init that takes at least one argument. Additional keyword arguments are allowed, but not currently used.

This first argument is a 'controller' class, specified below. This is how PageKde can provide feedback to the 'real' frontend.

It must provide a method called get_ui(self) that returns a dictionary with 'widgets' and 'breadcrumb' fields. 'widgets' is a list or singleton of Qt pages (usually just a single page). 'breadcrumb' is a debconf template key for the list of stages. Setting 'breadcrumb' to None indicates that you don't want the breadcrumb list visible for your page.

Controller Design

The controller object passed to Page UI classes is a simple mechanism for talking to the main frontend. Right now the only methods allowed are:

  • dbfilter (lets you have access to your Page class)
  • oem_config, oem_user_config (flags for which mode we're in)
  • is_language_page (set this to True if you intend to change languages)
  • translate(self, lang=None, just_me=True, reget=False) (retranslate the UI)
  • allow_go_forward(self, bool) (page starts with forward allowed)
  • allow_go_backward(self, bool) (page starts with backward allowed)
  • go_forward(self) (clicks forward)
  • go_backward(self) (clicks back)
  • go_to_page(self, page) (jumps to the given page)

Applying the Page

If your plugin wants to perform install-time work, it can define a Install class that derives from the InstallPlugin class.

InstallPlugin is a Plugin and follows the same conventions -- it is a debconf filter that has prepare and cleanup methods. But additionally and more relevantly for us, it adds an install method.

install is passed a target directory (usually '/target' or '/'), a progress class (more on that below), and possibly some future arguments. It's recommended that plugins use *args and **kwargs to gracefully handle future extensions.

If install returns a Python-true value, it is considered an error (ala command line programs). The error value (a string or a number) will be printed to syslog.

Progress API

install is passed a progress class that can provide updates on what your plugin is doing. Currently, it only supports passing a text description. Each plugin takes up 1% on the install progress bar.

   1 def info(self, title):
   2     pass

Install Example

   1 def install(self, target, progress, *args, **kwargs):
   3     return InstallPlugin.install(target, progress, *args, **kwargs)


In /usr/lib/ubiquity/plugins.d/

   1 import os
   2 from ubiquity.plugin import *
   4 # Plugin settings
   5 NAME='foo'
   6 BEFORE='usersetup'
   8 class PageGtk:
   9     def __init__(self, controller):
  10         import gtk
  11         self.controller = controller
  12         self.builder = gtk.Builder()
  13         self.builder.add_from_file('/usr/share/ubiquity-foo/foo.ui')
  14         self.builder.connect_signals(self)
  15     def get_ui(self):
  16         return self.builder.get_object('foo')
  18     # Custom foo controls
  19     def get_bar(self):
  20         button = self.builder.get_object('bar')
  21         return button.get_active()
  22     def set_bar(self, on):
  23         button = self.builder.get_object('bar')
  24         button.set_active(on)
  26 class Page(Plugin):
  27     def prepare(self, unfiltered=False):
  28         # self.frontend is PageGtk above
  29         bar = self.db.get('foo/bar')
  30         self.ui.set_bar(bar)
  31         return ([], ['foo/bar'])
  33     def ok_handler(self):
  34         bar = self.ui.get_bar()
  35         self.preseed_bool('foo/bar', bar)
  36         Plugin.ok_handler(self)
  38 class Install(InstallPlugin):
  39     def install(self, target, progress, *args, **kwargs):
  41         cmd = 'touch' if self.db.get('foo/bar') else 'rm'
  42         rv = os.system([cmd, os.path.join(target, '/etc/bar')])
  43         if rv:
  44             return rv
  45         return InstallPlugin.install(target, progress, *args, **kwargs)

Ubiquity/Plugins (last edited 2013-01-16 10:57:22 by fourdollars)