[WS] Create new calling scripts instead of copying

git-svn-id: svn://kolibrios.org@9374 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Magomed Kostoev (mkostoevr) 2021-12-03 20:07:10 +00:00
parent 199799846d
commit 282c7690c8
3 changed files with 26 additions and 24 deletions

View File

@ -4,30 +4,30 @@
import os import os
def log(s, end = "\n"): from lib.logging import log
print(s, end = end, flush = True)
def install_python_script(src, dst, tools): def generate_script_executing_script(script_to_execute):
log(f"Copying {src}... ", end = "") contents = ""
contents += "from importlib.machinery import SourceFileLoader\n"
contents += f"SourceFileLoader('__main__', '{script_to_execute}').load_module()\n"
return contents
with open(src) as src_file: def create_workspace_script(name, script_to_execute):
script = src_file.read() log(f"Installing {name}... ", end = "")
tools = tools.replace("\\", "\\\\")
repl_from = "path_to_tools = '..'"
repl_to = f"path_to_tools ='{tools}'"
script = script.replace(repl_from, repl_to, 1)
with open(dst, "w") as dst_file:
dst_file.write(script)
log(f"Done") script_contents = generate_script_executing_script(script_to_execute)
with open(name, "w") as f:
f.write(script_contents)
log("Done")
if __name__ == "__main__": if __name__ == "__main__":
tools_get_started_py = os.path.abspath(__file__) tools_get_started_py = os.path.abspath(__file__)
tools = os.sep.join(tools_get_started_py.split(os.sep)[:-1]) tools = os.sep.join(tools_get_started_py.split(os.sep)[:-1])
tools_workspace = os.sep.join([tools, "workspace"]) tools_workspace = os.sep.join([tools, "workspace"])
# Copy scripts from _tools/workspace to current folder, but let them know # Create (in current directory) scripts that execute
# where the _tools/lib is (change their value of tools variable) # the same named scripts from _tools/workspace
tools_workspace_run_py = os.sep.join([tools_workspace, "run.py"]) tools_workspace_run_py = os.path.join(tools_workspace, "run.py")
tools_workspace_build_py = os.sep.join([tools_workspace, "build.py"]) tools_workspace_build_py = os.path.join(tools_workspace, "build.py")
install_python_script(tools_workspace_run_py, "run.py", tools) create_workspace_script("run.py", tools_workspace_run_py)
install_python_script(tools_workspace_build_py, "build.py", tools) create_workspace_script("build.py", tools_workspace_build_py)

View File

@ -1,7 +1,8 @@
import sys import sys
import os import os
path_to_tools = '..' path_to_tools_workspace = os.path.dirname(os.path.abspath(__file__))
path_to_tools = os.path.dirname(path_to_tools_workspace)
sys.path.append(path_to_tools) sys.path.append(path_to_tools)
from lib.tupfile_parser import parse as parse_tupfile from lib.tupfile_parser import parse as parse_tupfile

View File

@ -5,11 +5,12 @@ import shutil
import urllib.request import urllib.request
import subprocess import subprocess
import build path_to_tools_workspace = os.path.dirname(os.path.abspath(__file__))
path_to_tools = os.path.dirname(path_to_tools_workspace)
path_to_tools = '..'
sys.path.append(path_to_tools) sys.path.append(path_to_tools)
from workspace.build import build
from lib.makeflop import Floppy from lib.makeflop import Floppy
from lib.platform import is_win32, path from lib.platform import is_win32, path
from lib.logging import log from lib.logging import log
@ -50,7 +51,7 @@ def run_qemu(start_dir = "workspace"):
return subprocess.Popen(a, bufsize = 0, stdout = qemu_stdout, stderr = qemu_stderr, stdin = subprocess.DEVNULL, start_new_session = True) return subprocess.Popen(a, bufsize = 0, stdout = qemu_stdout, stderr = qemu_stderr, stdin = subprocess.DEVNULL, start_new_session = True)
if __name__ == "__main__": if __name__ == "__main__":
program_files = build.build() program_files = build()
os.makedirs("workspace", exist_ok = True) os.makedirs("workspace", exist_ok = True)