-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
44 lines (29 loc) · 850 Bytes
/
config.py
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
from enum import Enum
import os
class Config:
MAX_USERS = os.getenv('MAX_USERS', default=20)
MIN_USERS = os.getenv('MIN_USERS', default=0)
class DevelopmentConfig(Config):
pass
class ProductionConfig(Config):
pass
class ConfigType(Enum):
DEVELOPMENT = 'development'
PRODUCTION = 'production'
@classmethod
def reverse_lookup(cls, value):
"""Reverse lookup."""
for _, member in cls.__members__.items():
if member.value == value:
return member
raise LookupError
class ConfigFactory:
_configs = {
ConfigType.DEVELOPMENT: DevelopmentConfig,
ConfigType.PRODUCTION: ProductionConfig
}
current = None
def get(self, type_: ConfigType):
cls = self._configs[type_]
self.current = cls()
return self.current