Skip to content
Permalink
0f1adda2c0
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
39 lines (30 sloc) 986 Bytes
# pylint: disable=C0413,C0103
""" Service base clase and global_services. """
import sys
import os
sys.path.insert(0, os.path.abspath(".."))
from config import ConfigDict, global_config
global_services = {}
def register_service(name):
""" Registers a service globally. """
def wrap(c):
if name in global_config.services:
# create service using global_config
s = c(global_config.services[name])
else:
# create service without config
try:
s = c()
except TypeError:
return c
global_services[name] = s
return c
return wrap
class Service(object):
""" Service base class. """
def __init__(self, config=ConfigDict()):
if isinstance(config, dict):
config = ConfigDict(**config)
elif not isinstance(config, ConfigDict):
raise TypeError("config must be dict or ConfigDict")
self.config = config