Subversion Repositories Kolibri OS

Rev

Rev 9385 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #!/usr/bin/python3
  2. # Copyright Magomed Kostoev
  3. # Published under MIT license
  4.  
  5. import os
  6.  
  7. from lib.network import download
  8. from lib.logging import log
  9. from lib.constants import tools, tools_workspace, tools_cache, tools_cache_kolibri_img
  10.  
  11. def generate_script_executing_script(script_to_execute):
  12.     script_to_execute = script_to_execute.replace("\\", "\\\\")
  13.     contents = ""
  14.     contents += "from importlib.machinery import SourceFileLoader\n"
  15.     contents += f"SourceFileLoader('__main__', '{script_to_execute}').load_module()\n"
  16.     return contents
  17.  
  18. def create_workspace_script(name, script_to_execute):
  19.     log(f"Installing {name}... ", end = "")
  20.  
  21.     script_contents = generate_script_executing_script(script_to_execute)
  22.     with open(name, "w") as f:
  23.         f.write(script_contents)
  24.  
  25.     log("Done")
  26.  
  27. if __name__ == "__main__":
  28.     # Create (in current directory) scripts that execute
  29.     # the same named scripts from _tools/workspace
  30.     tools_workspace_run_py = os.path.join(tools_workspace, "run.py")
  31.     tools_workspace_build_py = os.path.join(tools_workspace, "build.py")
  32.     create_workspace_script("run.py", tools_workspace_run_py)
  33.     create_workspace_script("build.py", tools_workspace_build_py)
  34.     # Initalize tup here
  35.     # TODO: Do anything if tup doesn't exist
  36.     os.system("tup init")
  37.