get_default_config_file_path()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nop 0
1
import configparser
2
import getpass
3
import os
4
import sys
5
from tabpy.tabpy_tools.client import Client
6
7
8
def get_default_config_file_path():
9
    import tabpy
10
11
    pkg_path = os.path.dirname(tabpy.__file__)
12
    config_file_path = os.path.join(pkg_path, "tabpy_server", "common", "default.conf")
13
    return config_file_path
14
15
16
def parse_config(config_file_path):
17
    config = configparser.ConfigParser()
18
    config.read(config_file_path)
19
    tabpy_config = config["TabPy"]
20
21
    port = 9004
22
    if "TABPY_PORT" in tabpy_config:
23
        port = tabpy_config["TABPY_PORT"]
24
25
    auth_on = "TABPY_PWD_FILE" in tabpy_config
26
    ssl_on = (
27
        "TABPY_TRANSFER_PROTOCOL" in tabpy_config
28
        and "TABPY_CERTIFICATE_FILE" in tabpy_config
29
        and "TABPY_KEY_FILE" in tabpy_config
30
    )
31
    prefix = "https" if ssl_on else "http"
32
    return port, auth_on, prefix
33
34
35
def get_creds():
36
    if sys.stdin.isatty():
37
        user = input("Username: ")
38
        passwd = getpass.getpass("Password: ")
39
    else:
40
        user = sys.stdin.readline().rstrip()
41
        passwd = sys.stdin.readline().rstrip()
42
    return [user, passwd]
43
44
45
def deploy_model(funcName, func, funcDescription):
46
    # running from deploy_models.py
47
    config_file_path = sys.argv[1] if len(sys.argv) > 1 else get_default_config_file_path()
48
    port, auth_on, prefix = parse_config(config_file_path)
49
50
    connection = Client(f"{prefix}://localhost:{port}/")
51
52
    if auth_on:
53
        # credentials are passed in from setup.py
54
        user, passwd = sys.argv[2], sys.argv[3] if len(sys.argv) == 4 else get_creds()
55
        connection.set_credentials(user, passwd)
56
57
    connection.deploy(funcName, func, funcDescription, override=True)
58
    print(f"Successfully deployed {funcName}")
59