Subversion Repositories Kolibri OS

Rev

Rev 9378 | Rev 9384 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9370 Boppan 1
#!/usr/bin/python3
9367 Boppan 2
# Copyright Magomed Kostoev
3
# Published under MIT license
4
 
5
import os
6
 
9383 Boppan 7
from lib.network import download_if_not_exist
9374 Boppan 8
from lib.logging import log
9383 Boppan 9
from lib.constants import tools_cache, tools_cache_kolibri_img
9367 Boppan 10
 
9374 Boppan 11
def generate_script_executing_script(script_to_execute):
9375 Boppan 12
    script_to_execute = script_to_execute.replace("\\", "\\\\")
9374 Boppan 13
    contents = ""
14
    contents += "from importlib.machinery import SourceFileLoader\n"
15
    contents += f"SourceFileLoader('__main__', '{script_to_execute}').load_module()\n"
16
    return contents
9367 Boppan 17
 
9374 Boppan 18
def create_workspace_script(name, script_to_execute):
19
    log(f"Installing {name}... ", end = "")
9367 Boppan 20
 
9374 Boppan 21
    script_contents = generate_script_executing_script(script_to_execute)
22
    with open(name, "w") as f:
23
        f.write(script_contents)
9367 Boppan 24
 
9374 Boppan 25
    log("Done")
26
 
9367 Boppan 27
if __name__ == "__main__":
28
    tools_get_started_py = os.path.abspath(__file__)
29
    tools = os.sep.join(tools_get_started_py.split(os.sep)[:-1])
30
    tools_workspace = os.sep.join([tools, "workspace"])
9374 Boppan 31
    # Create (in current directory) scripts that execute
32
    # the same named scripts from _tools/workspace
33
    tools_workspace_run_py = os.path.join(tools_workspace, "run.py")
34
    tools_workspace_build_py = os.path.join(tools_workspace, "build.py")
35
    create_workspace_script("run.py", tools_workspace_run_py)
36
    create_workspace_script("build.py", tools_workspace_build_py)
9377 Boppan 37
    # Initalize tup here
38
    # TODO: Do anything if tup doesn't exist
39
    os.system("tup init")
9383 Boppan 40
    # Download IMG to _tools/cache
41
    os.makedirs(tools_cache, exist_ok = True)
42
    img_url = "http://builds.kolibrios.org/eng/data/data/kolibri.img"
43
    download_if_not_exist(img_url, tools_cache_kolibri_img)