Subversion Repositories Kolibri OS

Rev

Rev 9375 | Rev 9378 | 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.     script_to_execute = script_to_execute.replace("\\", "\\\\")
  11.     contents = ""
  12.     contents += "from importlib.machinery import SourceFileLoader\n"
  13.     contents += f"SourceFileLoader('__main__', '{script_to_execute}').load_module()\n"
  14.     return contents
  15.  
  16. def create_workspace_script(name, script_to_execute):
  17.     log(f"Installing {name}... ", end = "")
  18.  
  19.     script_contents = generate_script_executing_script(script_to_execute)
  20.     with open(name, "w") as f:
  21.         f.write(script_contents)
  22.  
  23.     log("Done")
  24.  
  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"])
  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)
  35.     # Initalize tup here
  36.     # TODO: Do anything if tup doesn't exist
  37.     os.system("tup init")
  38.