-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig.py
64 lines (47 loc) · 1.73 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""Module for worker and job configuration."""
import os
STORAGE_ROOT = os.environ.get(
"STORAGE_ROOT", os.path.join(os.path.dirname(__file__), "..", "storage", "data")
)
NODE_MODULES = os.environ.get(
"NODE_MODULES", os.path.join(os.path.dirname(__file__), "node_modules")
)
def get_working_dir(project: int):
"""
Get the path to a project's working directory.
Most jobs are done within the context of a project's
working directory. This method translates a project integer id
into a local filesystem path on the worker. This allows
for workers to customize where the projects are stored.
"""
return os.path.join(
os.environ.get("WORKING_ROOT", os.path.join(STORAGE_ROOT, "working")),
str(project),
)
def get_snapshots_root() -> str:
"""
Get the root of the snapshot storage.
"""
return os.environ.get("SNAPSHOT_ROOT", os.path.join(STORAGE_ROOT, "snapshots"))
def get_snapshot_dir(project: int, snapshot: str) -> str:
"""
Get the path to a project snapshot directory.
Snapshots may be on a different filesystem from the project
working directories.
"""
return os.path.join(get_snapshots_root(), str(project), snapshot,)
def get_content_root() -> str:
"""
Get the root of the content storage.
"""
return os.environ.get("CONTENT_ROOT", os.path.join(STORAGE_ROOT, "content"))
def get_node_modules_bin(name: str) -> str:
"""
Get the path to a "bin" script installed in the configured `node_modules`.
"""
return os.path.join(NODE_MODULES, ".bin", name)
def get_node_modules_path(subpath: str) -> str:
"""
Get the path to a file within the configured `node_modules`.
"""
return os.path.join(NODE_MODULES, subpath)