Subversion Repositories Kolibri OS

Rev

Rev 9391 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9391 Rev 9411
1
import os
1
import os
2
import sys
2
import sys
3
import shlex
3
import shlex
4
import shutil
4
import shutil
5
import urllib.request
5
import urllib.request
6
import subprocess
6
import subprocess
7
 
7
 
8
path_to_tools_workspace = os.path.dirname(os.path.abspath(__file__))
8
path_to_tools_workspace = os.path.dirname(os.path.abspath(__file__))
9
path_to_tools = os.path.dirname(path_to_tools_workspace)
9
path_to_tools = os.path.dirname(path_to_tools_workspace)
10
sys.path.append(path_to_tools)
10
sys.path.append(path_to_tools)
11
 
11
 
12
from workspace.build import build
12
from workspace.build import build
13
 
13
 
14
from lib.builds import builds_get, builds_get_contents
14
from lib.builds import builds_get, builds_get_contents
15
from lib.makeflop import Floppy
15
from lib.makeflop import Floppy
16
from lib.platform import is_win32, path
16
from lib.platform import is_win32, path
17
from lib.logging import log
17
from lib.logging import log, require_tools
18
from lib.constants import tools_cache_kolibri_img
18
from lib.constants import tools_cache_kolibri_img
19
 
19
 
20
# TODO: Move into _tools/lib
20
# TODO: Move into _tools/lib
21
def run_qemu(start_dir = "workspace"):
21
def run_qemu(start_dir = "workspace"):
-
 
22
    require_tools(("qemu-system-i386",))
-
 
23
 
22
    qemu_command = f"qemu-system-i386"
24
    qemu_command = f"qemu-system-i386"
23
    flags = ""
25
    flags = ""
24
    flags += "-L . " # IDK why it does not work without this
26
    flags += "-L . " # IDK why it does not work without this
25
    flags += "-m 128 "
27
    flags += "-m 128 "
26
    flags += f"-drive format=raw,file={start_dir}/kolibri.img,index=0,if=floppy -boot a "
28
    flags += f"-drive format=raw,file={start_dir}/kolibri.img,index=0,if=floppy -boot a "
27
    flags += "-vga vmware "
29
    flags += "-vga vmware "
28
    flags += "-net nic,model=rtl8139 -net user "
30
    flags += "-net nic,model=rtl8139 -net user "
29
    flags += "-soundhw ac97 "
31
    flags += "-soundhw ac97 "
30
    if is_win32():
32
    if is_win32():
31
        qemu_full_path = shutil.which(qemu_command)
33
        qemu_full_path = shutil.which(qemu_command)
32
        qemu_directory = os.path.dirname(qemu_full_path)
34
        qemu_directory = os.path.dirname(qemu_full_path)
33
        flags += f"-L {qemu_directory} "
35
        flags += f"-L {qemu_directory} "
34
    s = f"{qemu_command} {flags}"
36
    s = f"{qemu_command} {flags}"
35
    qemu_stdout = open(f"{start_dir}/qemu_stdout.log", "w")
37
    qemu_stdout = open(f"{start_dir}/qemu_stdout.log", "w")
36
    qemu_stderr = open(f"{start_dir}/qemu_stderr.log", "w")
38
    qemu_stderr = open(f"{start_dir}/qemu_stderr.log", "w")
37
    if is_win32():
39
    if is_win32():
38
        return subprocess.Popen(s, bufsize = 0, stdout = qemu_stdout, stderr = qemu_stderr, stdin = subprocess.DEVNULL, shell = True, start_new_session = True)
40
        return subprocess.Popen(s, bufsize = 0, stdout = qemu_stdout, stderr = qemu_stderr, stdin = subprocess.DEVNULL, shell = True, start_new_session = True)
39
    else:
41
    else:
40
        a = shlex.split(s)
42
        a = shlex.split(s)
41
        return subprocess.Popen(a, bufsize = 0, stdout = qemu_stdout, stderr = qemu_stderr, stdin = subprocess.DEVNULL, start_new_session = True)
43
        return subprocess.Popen(a, bufsize = 0, stdout = qemu_stdout, stderr = qemu_stderr, stdin = subprocess.DEVNULL, start_new_session = True)
42
 
44
 
43
if __name__ == "__main__":
45
if __name__ == "__main__":
44
    program_name = build()
46
    program_name = build()
45
 
47
 
46
    os.makedirs("workspace", exist_ok = True)
48
    os.makedirs("workspace", exist_ok = True)
47
 
49
 
48
    # Create a copy of IMG
50
    # Create a copy of IMG
49
    kolibri_img = builds_get("eng/data/data/kolibri.img", "workspace/kolibri.img")
51
    kolibri_img = builds_get("eng/data/data/kolibri.img", "workspace/kolibri.img")
50
 
52
 
51
    # Open the IMG
53
    # Open the IMG
52
    with open(kolibri_img, "rb") as img:
54
    with open(kolibri_img, "rb") as img:
53
        img_data = img.read()
55
        img_data = img.read()
54
    img = Floppy(img_data)
56
    img = Floppy(img_data)
55
 
57
 
56
    # Remove unuseful folders
58
    # Remove unuseful folders
57
    img.delete_path("GAMES")
59
    img.delete_path("GAMES")
58
    img.delete_path("DEMOS")
60
    img.delete_path("DEMOS")
59
    img.delete_path("3D")
61
    img.delete_path("3D")
60
 
62
 
61
    # Insert faster kernel if no --compressed-kernel flag passed
63
    # Insert faster kernel if no --compressed-kernel flag passed
62
    if "--compressed-kernel" not in sys.argv:
64
    if "--compressed-kernel" not in sys.argv:
63
        new_kernel = builds_get_contents("eng/data/kernel/trunk/kernel.mnt.pretest")
65
        new_kernel = builds_get_contents("eng/data/kernel/trunk/kernel.mnt.pretest")
64
        img.add_file_path("KERNEL.MNT", new_kernel)
66
        img.add_file_path("KERNEL.MNT", new_kernel)
65
 
67
 
66
    log("Moving program into kolibri image... ", end = "")
68
    log("Moving program into kolibri image... ", end = "")
67
    with open(program_name, "rb") as file:
69
    with open(program_name, "rb") as file:
68
        file_data = file.read()
70
        file_data = file.read()
69
    if not img.add_file_path(program_name.upper(), file_data):
71
    if not img.add_file_path(program_name.upper(), file_data):
70
        print(f"Coudn't move {program_name} into IMG")
72
        print(f"Coudn't move {program_name} into IMG")
71
    log("Done")
73
    log("Done")
72
 
74
 
73
    log("Adding program to autorun.dat... ", end = "")
75
    log("Adding program to autorun.dat... ", end = "")
74
    lines_to_add = bytes(f"\r\n/SYS/{program_name.upper()}\t\t""\t0\t# Your program", "ascii")
76
    lines_to_add = bytes(f"\r\n/SYS/{program_name.upper()}\t\t""\t0\t# Your program", "ascii")
75
    autorun_dat = img.extract_file_path("SETTINGS\AUTORUN.DAT")
77
    autorun_dat = img.extract_file_path("SETTINGS\AUTORUN.DAT")
76
    place_for_new_lines = autorun_dat.index(b"\r\n/SYS/@TASKBAR")# b"\r\n### Hello, ASM World! ###")
78
    place_for_new_lines = autorun_dat.index(b"\r\n/SYS/@TASKBAR")# b"\r\n### Hello, ASM World! ###")
77
    autorun_dat = autorun_dat[:place_for_new_lines] + lines_to_add + autorun_dat[place_for_new_lines:]
79
    autorun_dat = autorun_dat[:place_for_new_lines] + lines_to_add + autorun_dat[place_for_new_lines:]
78
    img.delete_path("SETTINGS\AUTORUN.DAT")
80
    img.delete_path("SETTINGS\AUTORUN.DAT")
79
    img.add_file_path("SETTINGS\AUTORUN.DAT", autorun_dat)
81
    img.add_file_path("SETTINGS\AUTORUN.DAT", autorun_dat)
80
    log("Done")
82
    log("Done")
81
 
83
 
82
    img.save(kolibri_img)
84
    img.save(kolibri_img)
83
 
85
 
84
    run_qemu()
86
    run_qemu()