Rev 9384 | Rev 9390 | 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 | |||
9384 | Boppan | 7 | from lib.network import download |
9374 | Boppan | 8 | from lib.logging import log |
9385 | Boppan | 9 | from lib.constants import tools, tools_workspace, 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__": |
9385 | Boppan | 28 | # Create _tools/cache folder if not exist |
29 | os.makedirs(tools_cache, exist_ok = True) |
||
9374 | Boppan | 30 | # Create (in current directory) scripts that execute |
31 | # the same named scripts from _tools/workspace |
||
32 | tools_workspace_run_py = os.path.join(tools_workspace, "run.py") |
||
33 | tools_workspace_build_py = os.path.join(tools_workspace, "build.py") |
||
34 | create_workspace_script("run.py", tools_workspace_run_py) |
||
35 | create_workspace_script("build.py", tools_workspace_build_py) |
||
9377 | Boppan | 36 | # Initalize tup here |
37 | # TODO: Do anything if tup doesn't exist |
||
38 | os.system("tup init") |
||
9383 | Boppan | 39 | # Download IMG to _tools/cache |
40 | img_url = "http://builds.kolibrios.org/eng/data/data/kolibri.img" |
||
9384 | Boppan | 41 | download(img_url, tools_cache_kolibri_img, skip_exist = True) |