forked from MetOffice/SimSys_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerge_sources.py
More file actions
executable file
·90 lines (75 loc) · 2.44 KB
/
Copy pathmerge_sources.py
File metadata and controls
executable file
·90 lines (75 loc) · 2.44 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/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.
# -----------------------------------------------------------------------------
"""
Script to clone and merge git sources
"""
import argparse
import os
import yaml
from pathlib import Path
from get_git_sources import clone_and_merge, set_https, validate_dependencies
import logging
def parse_args():
"""
Parse arguments
"""
parser = argparse.ArgumentParser(description="Extract and merge git sources")
parser.add_argument(
"-d",
"--dependencies",
default=Path(__file__).parent,
type=Path,
help="Path to the dependencies.yaml file",
)
parser.add_argument(
"-p",
"--path",
type=Path,
default=None,
help="The path to extract the sources to. If part of a cylc suite, it will "
"default to $CYLC_WORKFLOW_SHARE_DIR/source, otherwise __file__/source",
)
parser.add_argument(
"-m",
"--mirrors",
action="store_true",
help="If true, attempts to use local git mirrors",
)
parser.add_argument(
"--mirror_loc",
default="/data/users/gitassist/git_mirrors",
help="Location of github mirrors",
)
parser.add_argument(
"--tokens",
action="store_true",
help="If true, https github sources will be used, requiring github "
"authentication via Personal Access Tokens",
)
args = parser.parse_args()
args.dependencies = args.dependencies.resolve()
if args.dependencies.is_dir():
args.dependencies = args.dependencies / "dependencies.yaml"
if not args.path:
args.path = Path(os.getenv("CYLC_WORKFLOW_SHARE_DIR", __file__)) / "source"
args.path = args.path.resolve()
return args
def main():
"""
Main Function
"""
args = parse_args()
logging.basicConfig(level=logging.INFO)
dependencies = yaml.safe_load(args.dependencies.read_text())
validate_dependencies(dependencies)
if args.tokens:
dependencies = set_https(dependencies)
for dependency, sources in dependencies.items():
dest = args.path / dependency
clone_and_merge(sources, dest, args.mirrors, args.mirror_loc)
if __name__ == "__main__":
main()