actev_get_system.py 2.77 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, sha=None, name=False):
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
Baptiste CHOCOT's avatar
Baptiste CHOCOT committed
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
Baptiste CHOCOT's avatar
Baptiste CHOCOT committed
29
    except KeyError:
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"
Baptiste CHOCOT's avatar
Baptiste CHOCOT committed
66
67
68
69
70

    # SHA
    if not sha:
        sha = "None"

71
72
    if not name:
        name = ""
Baptiste CHOCOT's avatar
Baptiste CHOCOT committed
73
    
Alexandre Boyer's avatar
Alexandre Boyer committed
74

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

Baptiste CHOCOT's avatar
Baptiste CHOCOT committed
87
88
89
    # status is a 16-bit long integer
    # The 8 strongest bits are exit_code
    # The 8 weakest bits are signal_number
90
    status = os.system(script)
Baptiste CHOCOT's avatar
Baptiste CHOCOT committed
91
92
    exit_code = status >> 8
    signal_number = status & (2**8 - 1)
93
    if status != 0:
Baptiste CHOCOT's avatar
Baptiste CHOCOT committed
94
95
96
97
        if signal_number == 2:  # SIGINT
            raise KeyboardInterrupt
        else:
            raise Exception("Error occured in %s (error code: %d)" % (command.entry_point, exit_code))