-
Notifications
You must be signed in to change notification settings - Fork 1
/
copy_common.py
72 lines (62 loc) · 2.59 KB
/
copy_common.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
65
66
67
68
69
70
71
72
#!/bin/python3
#
# Copyright © 2021 Uncharted Software Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import glob
import os
import shutil
primitives = [
"data_transformation.datetime_range_filter.Common",
"data_transformation.numeric_range_filter.Common",
"data_transformation.regex_filter.Common",
"data_transformation.term_filter.Common",
"data_transformation.datetime_field_compose.Common",
]
json_source = ""
run_source = ""
# find the pipeline / run for common
json_common = glob.glob("./pipelines/common__*.json")
if len(json_common) > 0:
print(f"Found {json_common[0]}")
json_source = json_common[0]
else:
print(f"Pipeline not found - exiting")
exit(1)
run_common = glob.glob("./pipelines/common__*.gz")
if len(run_common) > 0:
print(f"Found {run_common[0]}")
run_source = run_common[0]
json_symlink_source = ""
run_symlink_source = ""
for idx, primitive_path in enumerate(primitives):
print(f"Processing {primitive_path}")
json_target = os.path.join("../common-primitives/pipelines", primitive_path)
json_target_filename = os.path.basename(json_source).replace("common__", "")
json_target_path = os.path.join(json_target, json_target_filename)
os.makedirs(json_target, exist_ok=True)
if idx == 0:
shutil.copyfile(json_source, json_target_path)
json_symlink_source = os.path.join("..", primitive_path, json_target_filename)
elif not os.path.exists(json_target_path):
os.symlink(json_symlink_source, json_target_path)
if len(run_source) > 0:
run_target = os.path.join("../common-primitives/pipeline_runs", primitive_path)
run_target_filename = os.path.basename(run_source).replace("common__", "")
run_target_path = os.path.join(run_target, run_target_filename)
os.makedirs(run_target, exist_ok=True)
if idx == 0:
shutil.copyfile(run_source, run_target_path)
run_symlink_source = os.path.join("..", primitive_path, run_target_filename)
elif not os.path.exists(run_target_path):
os.symlink(run_symlink_source, run_target_path)