author B2G Bumper Bot <>
Wed, 08 Oct 2014 18:10:48 -0700
changeset 209598 cc64cf81f704073b0352a5935bd7ee0bdcc8cef6
parent 146271 8dc5604a4a880179fb4bf4f2e5e98a036561d936
child 262141 b66d80b9f5566eef25db2cf35e47e87d5194599a
permissions -rw-r--r--
Bumping gaia.json for 2 gaia revision(s) a=gaia-bump ======== Author: Douglas Sherk <> Desc: Merge pull request #24909 from DouglasSherk/1077331-system-call-vibrate Bug 1077331 - Only seek ringtone back to start on ringtone if the file is loaded fully enough to seek. r=etienne ======== Author: Doug Sherk <> Desc: Bug 1077331 - Only seek ringtone back to start on ringtone if the file is loaded fully enough to seek. r=etienne

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at

from __future__ import unicode_literals

from .base import MachError

class MachRegistrar(object):
    """Container for mach command and config providers."""

    def __init__(self):
        self.command_handlers = {}
        self.commands_by_category = {}
        self.settings_providers = set()
        self.categories = {}
        self.require_conditions = False

    def register_command_handler(self, handler):
        name =

        if not handler.category:
            raise MachError('Cannot register a mach command without a '
                'category: %s' % name)

        if handler.category not in self.categories:
            raise MachError('Cannot register a command to an undefined '
                'category: %s -> %s' % (name, handler.category))

        self.command_handlers[name] = handler

    def register_settings_provider(self, cls):

    def register_category(self, name, title, description, priority=50):
        self.categories[name] = (title, description, priority)
        self.commands_by_category[name] = set()

    def dispatch(self, name, context=None, **args):
        """Dispatch/run a command.

        Commands can use this to call other commands.

        # TODO The logic in this function overlaps with code in
        # mach.main.Main._run() and should be consolidated.
        handler = self.command_handlers[name]
        cls = handler.cls

        if handler.pass_context and not context:
            raise Exception('mach command class requires context.')

        if handler.pass_context:
            instance = cls(context)
            instance = cls()

        fn = getattr(instance, handler.method)

        return fn(**args) or 0

Registrar = MachRegistrar()