Subversion Repositories Kolibri OS

Rev

Rev 9390 | 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
9392 Boppan 6
import shutil
9367 Boppan 7
 
9384 Boppan 8
from lib.network import download
9374 Boppan 9
from lib.logging import log
9385 Boppan 10
from lib.constants import tools, tools_workspace, tools_cache, tools_cache_kolibri_img
9367 Boppan 11
 
9374 Boppan 12
def generate_script_executing_script(script_to_execute):
9375 Boppan 13
    script_to_execute = script_to_execute.replace("\\", "\\\\")
9374 Boppan 14
    contents = ""
15
    contents += "from importlib.machinery import SourceFileLoader\n"
16
    contents += f"SourceFileLoader('__main__', '{script_to_execute}').load_module()\n"
17
    return contents
9367 Boppan 18
 
9374 Boppan 19
def create_workspace_script(name, script_to_execute):
20
    log(f"Installing {name}... ", end = "")
9367 Boppan 21
 
9374 Boppan 22
    script_contents = generate_script_executing_script(script_to_execute)
23
    with open(name, "w") as f:
24
        f.write(script_contents)
9367 Boppan 25
 
9374 Boppan 26
    log("Done")
27
 
9367 Boppan 28
if __name__ == "__main__":
9392 Boppan 29
    # Check if we have tup installed
30
    if shutil.which("tup") == None:
31
        print("Sorry, I haven't found tup")
32
        print("Possible solutions:")
33
        print("- Install tup")
34
        print("- Add tup installation folder to PATH")
35
        exit()
36
    # Initalize tup here
37
    os.system("tup init")
9374 Boppan 38
    # Create (in current directory) scripts that execute
39
    # the same named scripts from _tools/workspace
40
    tools_workspace_run_py = os.path.join(tools_workspace, "run.py")
41
    tools_workspace_build_py = os.path.join(tools_workspace, "build.py")
42
    create_workspace_script("run.py", tools_workspace_run_py)
43
    create_workspace_script("build.py", tools_workspace_build_py)
9392 Boppan 44