Subversion Repositories Kolibri OS

Rev

Rev 9368 | Rev 9374 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. import os
  2. import sys
  3. import shlex
  4. import shutil
  5. import urllib.request
  6. import subprocess
  7.  
  8. import build
  9.  
  10. path_to_tools = '..'
  11. sys.path.append(path_to_tools)
  12.  
  13. from lib.makeflop import Floppy
  14. from lib.platform import is_win32, path
  15. from lib.logging import log
  16. from lib.network import download
  17.  
  18. # TODO: Move into _tools/lib
  19. def get_file_directory(path):
  20.     path = path.replace("\\", "/")
  21.     if "/" in path:
  22.         folder = "/".join(path.split("/")[:-1])
  23.         if folder == "":
  24.             return "/" # It was a file in the root folder
  25.         return folder
  26.     else:
  27.         return "." # Just a filename, let's return current folder
  28.  
  29. # TODO: Move into _tools/lib
  30. def run_qemu(start_dir = "workspace"):
  31.     qemu_command = f"qemu-system-i386"
  32.     flags = ""
  33.     flags += "-L . " # IDK why it does not work without this
  34.     flags += "-m 128 "
  35.     flags += f"-drive format=raw,file={start_dir}/kolibri.img,index=0,if=floppy -boot a "
  36.     flags += "-vga vmware "
  37.     flags += "-net nic,model=rtl8139 -net user "
  38.     flags += "-soundhw ac97 "
  39.     if is_win32():
  40.         qemu_full_path = shutil.which(qemu_command)
  41.         qemu_directory = get_file_directory(qemu_full_path)
  42.         flags += f"-L {qemu_directory} "
  43.     s = f"{qemu_command} {flags}"
  44.     qemu_stdout = open(f"{start_dir}/qemu_stdout.log", "w")
  45.     qemu_stderr = open(f"{start_dir}/qemu_stderr.log", "w")
  46.     if is_win32():
  47.         return subprocess.Popen(s, bufsize = 0, stdout = qemu_stdout, stderr = qemu_stderr, stdin = subprocess.DEVNULL, shell = True, start_new_session = True)
  48.     else:
  49.         a = shlex.split(s)
  50.         return subprocess.Popen(a, bufsize = 0, stdout = qemu_stdout, stderr = qemu_stderr, stdin = subprocess.DEVNULL, start_new_session = True)
  51.  
  52. if __name__ == "__main__":
  53.     program_files = build.build()
  54.  
  55.     os.makedirs("workspace", exist_ok = True)
  56.  
  57.     if not os.path.exists("workspace/kolibri.img"):
  58.         img_url = "http://builds.kolibrios.org/eng/data/data/kolibri.img"
  59.         download(img_url, "workspace/kolibri.img")
  60.  
  61.     # Open the IMG
  62.     with open("workspace/kolibri.img", "rb") as img:
  63.         img_data = img.read()
  64.     img = Floppy(img_data)
  65.  
  66.     # Remove unuseful folders
  67.     img.delete_path("GAMES")
  68.     img.delete_path("DEMOS")
  69.     img.delete_path("3D")
  70.  
  71.     log("Moving program files into kolibri image... ", end = "")
  72.     for file_name in program_files:
  73.         with open(file_name, "rb") as file:
  74.             file_data = file.read()
  75.         if not img.add_file_path(file_name, file_data):
  76.             print(f"Coudn't move {file_name} into IMG")
  77.     img.save("workspace/kolibri.img")
  78.     log("Done")
  79.  
  80.     # TODO: Autorun
  81.     run_qemu()
  82.