2 # Copyright Magomed Kostoev
3 # Published under MIT license
8 from lib
.network
import download
9 from lib
.logging
import log
10 from lib
.constants
import tools
, tools_workspace
, tools_cache
, tools_cache_kolibri_img
12 def generate_script_executing_script(script_to_execute
):
13 script_to_execute
= script_to_execute
.replace("\\", "\\\\")
15 contents
+= "from importlib.machinery import SourceFileLoader\n"
16 contents
+= f
"SourceFileLoader('__main__', '{script_to_execute}').load_module()\n"
19 def create_workspace_script(name
, script_to_execute
):
20 log(f
"Installing {name}... ", end
= "")
22 script_contents
= generate_script_executing_script(script_to_execute
)
23 with
open(name
, "w") as f
:
24 f
.write(script_contents
)
28 if __name__
== "__main__":
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")
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
)