blob: d42bb75675dfe85166cd8c51dac5ff70bdf60fd4 (
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
|
"""General utilities for apps."""
import enum
import os
class AreaError(Exception):
"""Error raised when area configuration is invalid or missing."""
class Area(enum.Enum):
"""The area we are running."""
Test = "Test"
Live = "Live"
def from_env() -> Area:
"""Load AREA from environment variable.
Raises:
AreaError: if AREA is not defined
"""
var = os.getenv("AREA", "Test")
if var == "Test":
return Area.Test
if var == "Live":
return Area.Live
msg = "AREA not defined"
raise AreaError(msg)
|