Subversion Repositories Kolibri OS

Rev

Rev 9370 | Rev 9375 | 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.logging import log
  8.  
  9. def generate_script_executing_script(script_to_execute):
  10.     contents = ""
  11.     contents += "from importlib.machinery import SourceFileLoader\n"
  12.     contents += f"SourceFileLoader('__main__', '{script_to_execute}').load_module()\n"
  13.     return contents
  14.  
  15. def create_workspace_script(name, script_to_execute):
  16.     log(f"Installing {name}... ", end = "")
  17.  
  18.     script_contents = generate_script_executing_script(script_to_execute)
  19.     with open(name, "w") as f:
  20.         f.write(script_contents)
  21.  
  22.     log("Done")
  23.  
  24. if __name__ == "__main__":
  25.     tools_get_started_py = os.path.abspath(__file__)
  26.     tools = os.sep.join(tools_get_started_py.split(os.sep)[:-1])
  27.     tools_workspace = os.sep.join([tools, "workspace"])
  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.