Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/atoideweb/tools/registry.py
blob: a57285ecabdad4a5ca57ec2a7de1a51317baaa82 (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
49
50
51
52
53
54

# python import
import logging

# get application logger
logger = logging.getLogger('atoideweb')


class InfoRegistry(object):

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

        def __init__(self):
            """Create the new singleton with the application config.

            :param config: SafeConfigParser object for all the application
            :see: `ConfigParser.SafeConfigParser`
            """
            # 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 InfoRegistry.instance \
        or force is True:
            # create a new instance
            InfoRegistry.instance = InfoRegistry.__Singleton()
        else:
            pass
        # return the manager object
        return InfoRegistry.instance