Rev 9377 | Rev 9383 | 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 | |||
9374 | Boppan | 7 | from lib.logging import log |
9367 | Boppan | 8 | |
9374 | Boppan | 9 | def generate_script_executing_script(script_to_execute): |
9375 | Boppan | 10 | script_to_execute = script_to_execute.replace("\\", "\\\\") |
9374 | Boppan | 11 | contents = "" |
12 | contents += "from importlib.machinery import SourceFileLoader\n" |
||
13 | contents += f"SourceFileLoader('__main__', '{script_to_execute}').load_module()\n" |
||
14 | return contents |
||
9367 | Boppan | 15 | |
9374 | Boppan | 16 | def create_workspace_script(name, script_to_execute): |
17 | log(f"Installing {name}... ", end = "") |
||
9367 | Boppan | 18 | |
9374 | Boppan | 19 | script_contents = generate_script_executing_script(script_to_execute) |
20 | with open(name, "w") as f: |
||
21 | f.write(script_contents) |
||
9367 | Boppan | 22 | |
9374 | Boppan | 23 | log("Done") |
24 | |||
9367 | Boppan | 25 | if __name__ == "__main__": |
26 | tools_get_started_py = os.path.abspath(__file__) |
||
27 | tools = os.sep.join(tools_get_started_py.split(os.sep)[:-1]) |
||
28 | tools_workspace = os.sep.join([tools, "workspace"]) |
||
9374 | Boppan | 29 | # Create (in current directory) scripts that execute |
30 | # the same named scripts from _tools/workspace |
||
31 | tools_workspace_run_py = os.path.join(tools_workspace, "run.py") |
||
32 | tools_workspace_build_py = os.path.join(tools_workspace, "build.py") |
||
33 | create_workspace_script("run.py", tools_workspace_run_py) |
||
34 | create_workspace_script("build.py", tools_workspace_build_py) |
||
9377 | Boppan | 35 | # Initalize tup here |
36 | # TODO: Do anything if tup doesn't exist |
||
37 | os.system("tup init") |