Subversion Repositories Kolibri OS

Rev

Rev 9370 | Rev 9375 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9370 Rev 9374
Line 2... Line 2...
2
# Copyright Magomed Kostoev
2
# Copyright Magomed Kostoev
3
# Published under MIT license
3
# Published under MIT license
Line 4... Line 4...
4
 
4
 
Line 5... Line 5...
5
import os
5
import os
6
 
-
 
Line 7... Line 6...
7
def log(s, end = "\n"):
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"
8
    print(s, end = end, flush = True)
13
    return contents
-
 
14
 
-
 
15
def create_workspace_script(name, script_to_execute):
-
 
16
    log(f"Installing {name}... ", end = "")
-
 
17
 
Line 9... Line -...
9
 
-
 
10
def install_python_script(src, dst, tools):
-
 
11
    log(f"Copying {src}... ", end = "")
-
 
12
 
-
 
13
    with open(src) as src_file:
-
 
14
        script = src_file.read()
-
 
15
    tools = tools.replace("\\", "\\\\")
-
 
16
    repl_from = "path_to_tools = '..'"
-
 
17
    repl_to = f"path_to_tools ='{tools}'"
-
 
18
    script = script.replace(repl_from, repl_to, 1)
18
    script_contents = generate_script_executing_script(script_to_execute)
Line 19... Line 19...
19
    with open(dst, "w") as dst_file:
19
    with open(name, "w") as f:
20
        dst_file.write(script)
20
        f.write(script_contents)
21
 
21
 
22
    log(f"Done")
22
    log("Done")
23
 
23
 
24
if __name__ == "__main__":
24
if __name__ == "__main__":
25
    tools_get_started_py = os.path.abspath(__file__)
25
    tools_get_started_py = os.path.abspath(__file__)
26
    tools = os.sep.join(tools_get_started_py.split(os.sep)[:-1])
26
    tools = os.sep.join(tools_get_started_py.split(os.sep)[:-1])
27
    tools_workspace = os.sep.join([tools, "workspace"])
27
    tools_workspace = os.sep.join([tools, "workspace"])
28
    # Copy scripts from _tools/workspace to current folder, but let them know
28
    # Create (in current directory) scripts that execute