-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconfiguration.py
55 lines (40 loc) · 1.96 KB
/
configuration.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
45
46
47
48
49
50
51
52
53
54
55
# separate file so that it can be imported without initializing FastAPI
from amarillo.routers.carpool import enhance_missing_carpools
from amarillo.utils.container import container
import logging
from amarillo.services.agencyconf import AgencyConfService, agency_conf_directory
from amarillo.services.agencies import AgencyService
from amarillo.services.regions import RegionService
from amarillo.services.config import config
from amarillo.utils.utils import assert_folder_exists
logger = logging.getLogger(__name__)
def create_required_directories():
logger.info("Checking that necessary directories exist")
# Folder to serve GTFS(-RT) from
assert_folder_exists('data/gtfs')
# Temp folder for GTFS generation
assert_folder_exists('data/tmp')
for agency_id in container['agencies'].agencies:
for subdir in ['carpool', 'trash', 'enhanced', 'failed']:
foldername = f'data/{subdir}/{agency_id}'
logger.debug("Checking that necessary %s exist", foldername)
assert_folder_exists(f'data/{subdir}/{agency_id}')
# Agency configurations
assert_folder_exists(agency_conf_directory)
def configure_services():
container['agencyconf'] = AgencyConfService()
logger.info("Loaded %d agency configuration(s)", len(container['agencyconf'].agency_id_to_agency_conf))
container['agencies'] = AgencyService()
logger.info("Loaded %d agencies", len(container['agencies'].agencies))
container['regions'] = RegionService()
logger.info("Loaded %d regions", len(container['regions'].regions))
create_required_directories()
enhance_missing_carpools()
def configure_admin_token():
if config.admin_token is None:
message = "ADMIN_TOKEN environment variable not set"
logger.error(message)
raise Exception(message)
logger.info("ADMIN_TOKEN environment variable found")
# Note: the admin token is not persisted. When needed it is accessed
# via config.admin_token as above