Skip to content

Install

astra.install

install_astra(dest_dir=None, name='Astra', verbose=False)

Installs Astra from Klaus Floettmann's DESY website for the detected platform.

Sets environmental variable ASTRA_BIN

Source code in astra/install.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def install_astra(dest_dir=None, name='Astra', verbose=False):
    """
    Installs Astra from Klaus Floettmann's DESY website for the detected platform.

    Sets environmental variable ASTRA_BIN
    """
    system = platform.system()
    url=ASTRA_URL[system]
    dest = os.path.abspath(os.path.join(dest_dir, name))

    install_executable(url,  dest, verbose=verbose)

    os.environ['ASTRA_BIN'] = dest

    if verbose:
        print(f'Installed Astra in {dest}, and set $ASTRA_BIN equal to this.')

    return dest

install_examples(location)

Install lume-astra examples on the informed location.

Parameters:

Name Type Description Default
location str

The folder in which to install the examples

required
Source code in astra/install.py
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
def install_examples(location):
    """
    Install lume-astra examples on the informed location.

    Parameters
    ----------
    location : str
        The folder in which to install the examples
    """
    import requests
    import zipfile
    import io
    import os

    loc = os.path.expanduser(os.path.expandvars(location))
    os.makedirs(loc, exist_ok=True)

    response = requests.get(EXAMPLES_URL, stream=True)
    if response.status_code == 200:
        zip_file = zipfile.ZipFile(io.BytesIO(response.content))
        zip_file.extractall(loc)
    else:
        raise RuntimeError(f"Could not download examples archive. Status code was: {response.status_code}")

install_executable(url, dest, verbose=False)

Downloads a url into a destination and makes it executable. Will not overwrite.

Source code in astra/install.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def install_executable(url, dest, verbose=False):
    """
    Downloads a url into a destination and makes it executable. Will not overwrite.
    """

    if os.path.exists(dest):
        print(os.path.abspath(dest), 'exists, will not overwrite')
    else:
        if verbose:
            print(f'Downloading {url} to {dest}')
        urllib.request.urlretrieve(url, dest)   
        make_executable(dest)

    return dest

install_generator(dest_dir=None, name='generator', verbose=False)

Installs Astra's generator from Klaus Floettmann's DESY website for the detected platform.

Sets environmental variable GENERATOR_BIN

Source code in astra/install.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def install_generator(dest_dir=None, name='generator', verbose=False):
    """
    Installs Astra's generator from Klaus Floettmann's DESY website for the detected platform.

    Sets environmental variable GENERATOR_BIN
    """
    system = platform.system()
    url=GENERATOR_URL[system]
    dest = os.path.abspath(os.path.join(dest_dir, name))
    install_executable(url,  dest, verbose=verbose)

    os.environ['GENERATOR_BIN'] = dest

    if verbose:
        print(f'Installed Astra\'s generator in {dest}, and set $GENERATOR_BIN equal to this.')    

    return dest