actev_get_system.py 2.54 KB
Newer Older
1
"""Entry point module: get-system
2
3
4
5

This file should not be modified.
"""
import os
6
7
8

from diva_evaluation_cli.bin.private_src.implementation.utils.actev_cli_environment import init_environment, export_variable

9
from diva_evaluation_cli.bin.private_src.implementation.get_system.system_types_definition import system_types
10

Baptiste CHOCOT's avatar
Baptiste CHOCOT committed
11
def entry_point(url, system_type, location=None, user=None, password=None, token=None, install_cli=False, name=False, sha=None):
12
13
14
15
16
17
18
19
20
21
22
    """Private entry point.

    Downloads a credentialed, web-accessible content into src

    Args:
        url (str): Url to get the system
        location (str, optional): Path to store the system
        user (str, optional): Username to access the url
        password (str, optional): Password to access the url
        token (str, optional): Token to access the url
        install_cli (bool, optional): Information to know wether CLI has to be installed
23
        sha (str, optional): commit SHA or tag to checkout after cloning
24

25
26
    """
    try:
Alexandre Boyer's avatar
Alexandre Boyer committed
27
28
        command = system_types[system_type]()
        script = command.entry_point
29
    except:
30
        raise Exception("Unknown system type")
Alexandre Boyer's avatar
Alexandre Boyer committed
31

32
33
34
35
36
37
38
    # Init the actev_cli_environemnt variables
    init_environment()

    # Add variables into the actev_cli_environemnt
    export_variable('ACTEV_GET_SYSTEM_URL', url)

    # Destination of the software
Alexandre Boyer's avatar
Alexandre Boyer committed
39
40
    if not location:
        location = "None"
41
42
43
44
45

    # Username
    if user:
        export_variable('ACTEV_GET_SYSTEM_USER', user)
    else:
Alexandre Boyer's avatar
Alexandre Boyer committed
46
        user = "None"
47
48
49
50
51

    # Password
    if password:
        export_variable('ACTEV_GET_SYSTEM_PASSWORD', password)
    else:
Alexandre Boyer's avatar
Alexandre Boyer committed
52
        password = "None"
53
54
55
56
57

    # Token
    if token:
        export_variable('ACTEV_GET_SYSTEM_TOKEN', token)
    else:
Alexandre Boyer's avatar
Alexandre Boyer committed
58
        token = "None"
59
60
61


    # Whether installing the CLI
62
63
64
65
    if install_cli:
        install_cli = "True"
    else:
        install_cli = "False"
66
    if not name:
Baptiste CHOCOT's avatar
Baptiste CHOCOT committed
67
68
69
70
71
        name = "None"
    
    # SHA
    if not sha:
        sha = "None"
Alexandre Boyer's avatar
Alexandre Boyer committed
72

73
74
    # go into the right directory to execute the script
    path = os.path.dirname(__file__)
75
    script = os.path.join(path, '../implementation/get_system/get/' + script)
76
77
78
79
    script += " " + url + \
              " " + location + \
              " " + user + \
              " " + password + \
80
              " " + token + \
81
              " " + install_cli + \
82
83
              " " + name + \
              " " + sha
Alexandre Boyer's avatar
Alexandre Boyer committed
84

85
86
87
88
    # execute the script
    # status is the exit status code returned by the program
    status = os.system(script)
    if status != 0:
89
        raise Exception("Error occured in %s" % command.entry_point)