-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathrose_stem_extract_source.py
More file actions
executable file
·52 lines (41 loc) · 1.85 KB
/
rose_stem_extract_source.py
File metadata and controls
executable file
·52 lines (41 loc) · 1.85 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
#!/usr/bin/env python3
# -----------------------------------------------------------------------------
# (C) Crown copyright Met Office. All rights reserved.
# The file LICENCE, distributed with this code, contains details of the terms
# under which the code may be used.
# -----------------------------------------------------------------------------
"""
Clone sources for a rose-stem run for use with git bdiff module in scripts
Only intended for use with rose-stem suites that have provided appropriate
environment variables
"""
import os
from pathlib import Path
from ast import literal_eval
from get_git_sources import clone_and_merge, set_https, validate_dependencies
import logging
def main() -> None:
"""
1. Read environment variables for:
SOURCE_DIRECTORY - location to clone sources,
DEPENDENCIES - dictionary of dependencies,
USE_TOKENS - whether to use tokens for https URLs,
USE_MIRRORS - whether to use local git mirrors,
GIT_MIRROR_LOC - location of local git mirrors
2. For each dependency in DEPENDENCIES, clone or sync the source
3. If USE_TOKENS is True, modify the source URLs to use https
4. If USE_MIRRORS is True, clone from local mirrors at GIT_MIRROR_LOC
"""
logging.basicConfig(level=logging.INFO)
clone_loc = Path(os.environ["SOURCE_DIRECTORY"])
dependencies: dict = literal_eval(os.environ["DEPENDENCIES"])
validate_dependencies(dependencies)
if os.environ.get("USE_TOKENS", "false").lower() == "true":
dependencies = set_https(dependencies)
use_mirrors = os.environ.get("USE_MIRRORS", "false").lower() == "true"
mirror_loc = Path(os.getenv("GIT_MIRROR_LOC", ""))
for dependency, sources in dependencies.items():
loc = clone_loc / dependency
clone_and_merge(sources, loc, use_mirrors, mirror_loc)
if __name__ == "__main__":
main()