~curtin-dev/curtin/trunk

« back to all changes in this revision

Viewing changes to curtin/reporter/registry.py

  • Committer: Scott Moser
  • Date: 2017-12-20 17:33:03 UTC
  • Revision ID: smoser@ubuntu.com-20171220173303-29gha5qb8wpqrd40
README: Mention move of revision control to git.

curtin development has moved its revision control to git.
It is available at
  https://code.launchpad.net/curtin

Clone with
  git clone https://git.launchpad.net/curtin
or
  git clone git+ssh://git.launchpad.net/curtin

For more information see
  http://curtin.readthedocs.io/en/latest/topics/development.html

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2015 Canonical Ltd.
2
 
# This file is part of cloud-init.  See LICENCE file for license information.
3
 
#
4
 
# vi: ts=4 expandtab
5
 
import copy
6
 
 
7
 
 
8
 
class DictRegistry(object):
9
 
    """A simple registry for a mapping of objects."""
10
 
 
11
 
    def __init__(self):
12
 
        self.reset()
13
 
 
14
 
    def reset(self):
15
 
        self._items = {}
16
 
 
17
 
    def register_item(self, key, item):
18
 
        """Add item to the registry."""
19
 
        if key in self._items:
20
 
            raise ValueError(
21
 
                'Item already registered with key {0}'.format(key))
22
 
        self._items[key] = item
23
 
 
24
 
    def unregister_item(self, key, force=True):
25
 
        """Remove item from the registry."""
26
 
        if key in self._items:
27
 
            del self._items[key]
28
 
        elif not force:
29
 
            raise KeyError("%s: key not present to unregister" % key)
30
 
 
31
 
    @property
32
 
    def registered_items(self):
33
 
        """All the items that have been registered.
34
 
 
35
 
        This cannot be used to modify the contents of the registry.
36
 
        """
37
 
        return copy.copy(self._items)