Subversion Repositories Kolibri OS

Rev

Rev 9390 | 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. import shutil
  7.  
  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
  11.  
  12. def generate_script_executing_script(script_to_execute):
  13.     script_to_execute = script_to_execute.replace("\\", "\\\\")
  14.     contents = ""
  15.     contents += "from importlib.machinery import SourceFileLoader\n"
  16.     contents += f"SourceFileLoader('__main__', '{script_to_execute}').load_module()\n"
  17.     return contents
  18.  
  19. def create_workspace_script(name, script_to_execute):
  20.     log(f"Installing {name}... ", end = "")
  21.  
  22.     script_contents = generate_script_executing_script(script_to_execute)
  23.     with open(name, "w") as f:
  24.         f.write(script_contents)
  25.  
  26.     log("Done")
  27.  
  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")
  35.         exit()
  36.     # Initalize tup here
  37.     os.system("tup init")
  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)
  44.  
  45.