-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathcache.py
More file actions
62 lines (48 loc) · 1.72 KB
/
cache.py
File metadata and controls
62 lines (48 loc) · 1.72 KB
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
import os
import pathlib
from ruamel.yaml import YAML
from . import schema
yaml = YAML()
def configuration_from_file(file, mount):
with file.open() as fid:
# load the raw yaml input
raw = yaml.load(fid)
# validate the yaml
schema.CacheValidator.validate(raw)
# verify that the root path exists
path = pathlib.Path(os.path.expandvars(raw["root"]))
if not path.is_absolute():
raise FileNotFoundError(f"The build cache path '{path}' is not absolute")
if not path.is_dir():
raise FileNotFoundError(f"The build cache path '{path}' does not exist")
raw["root"] = path
# Put the build cache in a sub-directory named after the mount point.
# This avoids relocation issues.
raw["path"] = pathlib.Path(path.as_posix() + mount.as_posix())
# verify that the key file exists if it was specified
key = raw["key"]
if key is not None:
key = pathlib.Path(os.path.expandvars(key))
if not key.is_absolute():
raise FileNotFoundError(f"The build cache key '{key}' is not absolute")
if not key.is_file():
raise FileNotFoundError(f"The build cache key '{key}' does not exist")
raw["key"] = key
return raw
def generate_mirrors_yaml(config, out):
path = config["path"].as_posix()
mirrors = {
"mirrors": {
"alpscache": {
"fetch": {
"url": f"file://{path}",
},
"push": {
"url": f"file://{path}",
},
}
}
}
yaml = YAML()
yaml.default_flow_style = True
yaml.dump(mirrors, out)