-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployments.py
66 lines (53 loc) · 1.73 KB
/
deployments.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
import os
import logging
import argparse
from dataflows.deployments._constants import (
FLOW_DEPLOYMENT_DICT,
DEPLOYMENT_FILE_FUNC_DICT,
)
def get_file_name_file_extension(file_path: str) -> tuple:
"""Function to extract the file name and extension from a file URI
Args:
file_uri (str): URL pointing to the file
Returns:
tuple: file name and extension
"""
file_name_with_ext = os.path.basename(file_path)
file_name, file_ext = os.path.splitext(file_name_with_ext)
return (file_name, file_ext)
def get_deploy_function(file_name: str) -> callable:
"""Function to get the deployment function for a flow
Args:
flow (str): flow file name without extension
Returns:
callable: deployment function
"""
deploy_function = FLOW_DEPLOYMENT_DICT.get(file_name)
if not deploy_function:
deploy_function = DEPLOYMENT_FILE_FUNC_DICT.get(file_name)
return deploy_function
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter
)
parser.add_argument(
"-f",
"--file_path",
help="File path",
required=True,
)
args = parser.parse_args()
logger = logging.getLogger()
logger.setLevel(logging.INFO)
file_name, _ = get_file_name_file_extension(args.file_path)
deploy_function = get_deploy_function(file_name)
if deploy_function:
logger.info(f"Deploying {file_name} using {deploy_function.__name__}")
deploy_function()
logger.info(f"{file_name} has been deployed!")
else:
logger.info(
f"No deployment function found for {file_name},"
"skipping..."
)