Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/creactistore/_templates/lib/olpcfr/tools/registry.py
blob: 7e575c3ee441fd586d8379531ae2c2db73a1c2ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

# python import
import logging


class Registry(object):

    class __Singleton:
        """Our singleton object.
        """

        def __init__(self):
            """Create the new singleton for a simple use.
            """
            # ensure config
            self.__dict = dict()

        def get_info(self, path):
            # ..
            if path in self.__dict:
                return self.__dict[path]
            else:
                return None

        def set_info(self, path, info):
            # clear previous
            if path in self.__dict:
                del self.__dict[path]
            else:
                pass
            # ...
            self.__dict[path] = info

    # singleton instance
    instance = None

    def __new__(c, force=False):
        """Singleton new init.
        """
        # if doesn't already initialized
        if not Registry.instance \
        or force is True:
            # create a new instance
            Registry.instance = Registry.__Singleton()
        else:
            pass
        # return the manager object
        return Registry.instance