def set_benchmark_progressbar(desktop, text): message = dialogbox.DialogBox.MESSAGE(text) progressbar = dialogbox.DialogBox(message) desktop.addChild("progressbar", progressbar, ((desktop.getWidth() - progressbar.getWidth()) / 2, (desktop.getHeight() - progressbar.getHeight()) / 2), -1) gui.yieldFrame()
def show_progress(progress_bar, subprocess): s = system.getSystem() nbr = s.getNonblockingReader(subprocess.stdout) line = nbr.readline() while line != "": if line != None and re.match(r'^\d+/\d+$', line): (n, m) = map(lambda a: float(a), line.split('/')) progress_bar.setProgress(n / m if m > 0 else 0) gui.yieldFrame() line = nbr.readline()
def kexec_load_kernel(kernel, kernel_args=None, initrd=None): s = system.getSystem() cmdline = kexec_cmdline(kernel, kernel_args, initrd) with dialogbox.messagebox.open(gui.res.string_inst_start_) as pb: with s.openCancellableProcessForInput(cmdline) as kexec: nbr = s.getNonblockingReader(kexec.stdout) line = nbr.readline() while line != "": gui.yieldFrame() line = nbr.readline()
def kexec_load_kernel(kernel, kernel_args = None, initrd = None): s = system.getSystem() cmdline = kexec_cmdline(kernel, kernel_args, initrd) with dialogbox.messagebox.open(gui.res.string_inst_start_) as pb: with s.openCancellableProcessForInput(cmdline) as kexec: nbr = s.getNonblockingReader(kexec.stdout) line = nbr.readline() while line != "": gui.yieldFrame() line = nbr.readline()
def nonblockingHttpHead(url): cmdline = ["curl", "--cacert", CA_CERT_FILE, "-sLfI", url] curl = subprocess.Popen(cmdline, shell=False, close_fds=True, stdout=subprocess.PIPE) s = system.getSystem() headers = {} nbr = s.getNonblockingReader(curl.stdout) r = nbr.readline() started = False while r != "": if r != None: if started: splitted = r.split(":", 1) if len(splitted) > 1: name = splitted[0].strip().lower() value = splitted[1].strip() if name == "content-length": value = int(value) headers[name] = value else: line = r.strip() if line.startswith("HTTP/") and line.endswith(" 200 OK"): started = True if gui.yieldFrame(): # キャンセルキーでTrueが返る curl.terminate() raise Cancelled() r = nbr.readline() curl.stdout.close() rst = curl.wait() if rst != 0: raise CurlException(rst, url) return headers
def nonblockingHttpHead(url): cmdline = ["curl", "--cacert", CA_CERT_FILE, "-sLfI", url] curl = subprocess.Popen(cmdline, shell=False, close_fds=True, stdout=subprocess.PIPE) s = system.getSystem() headers = {} nbr = s.getNonblockingReader(curl.stdout) r = nbr.readline() started = False while r != "": if r != None: if started: splitted = r.split(':', 1) if len(splitted) > 1: name = splitted[0].strip().lower() value = splitted[1].strip() if name == "content-length": value = int(value) headers[name] = value else: line = r.strip() if line.startswith("HTTP/") and line.endswith(" 200 OK"): started = True if gui.yieldFrame(): # キャンセルキーでTrueが返る curl.terminate() raise Cancelled() r = nbr.readline() curl.stdout.close() rst = curl.wait() if rst != 0: raise CurlException(rst, url) return headers
def run(source_device, esp, device, arch): s = system.getSystem() try: mount_option = "loop" if os.path.isfile(source_device) else None with s.temporaryMount(source_device, mount_option, "ro") as sourceDir: with s.temporaryMount(device) as targetDir: delfiles = [] with s.temporaryFile() as tmpFileName: # excludeFile with open(tmpFileName, "w") as tmpFile: with dialogbox.messagebox.open(gui.res.string_installer_upgrade_check) as pb: tarball = "%s/wb-%s.tar.xz" % (sourceDir, arch) with s.openWbForInput("compare_files", [tarball, targetDir]) as compare_files: nbr = s.getNonblockingReader(compare_files.stdout) line = nbr.readline() while line != "": if line != None: #print line if line.startswith("X "): tmpFile.write(".%s" % line[2:]) elif line.startswith("D "): delfiles.append(line[2:].rstrip()) else: gui.yieldFrame() line = nbr.readline() with dialogbox.progressbar.open(gui.res.string_installer_upgrade_upgrade) as progress_bar: with s.openWbForInput("extract_archive", ("-x", tmpFileName, tarball, targetDir)) as extract_archive: show_progress(progress_bar, extract_archive) # delete removed files delete(targetDir, delfiles) # install wbui installer.copyWBUI(sourceDir, targetDir) with dialogbox.progressbar.open(string_copying_boot_files) as progress_bar: with s.temporaryMount(esp) as boot_dir: with s.openWbForInput("copy_boot_files", ("%s/EFI/Walbrix" % sourceDir, "%s/EFI/Walbrix" % boot_dir)) as copy_boot_files: show_progress(progress_bar, copy_boot_files) s.installGrubEFI(boot_dir) disk = s.getDiskFromPartition(esp) # get the disk which ESP belongs to if s.isBiosCompatibleDisk(disk): s.installGrub(disk, boot_dir) except Exception, e: traceback.print_exc(file=sys.stderr) dialogbox.messagebox.execute(gui.res.string_installer_upgrade_failed % (e), None, gui.res.caution_sign) return False
def run(disk, image): block_name = disk["name"] product = "%s %s" % (disk["vendor"], disk["model"]) size = disk["size_str"] if dialogbox.messagebox.execute(string_installation_description % (size, product, block_name), dialogbox.DialogBox.OKCANCEL(), gui.res.caution_sign) != "ok": return False with dialogbox.messagebox.open(string_installing): q = multiprocessing.Queue() p = multiprocessing.Process(target=exec_install, args=(disk, image, q)) p.start() while p.is_alive(): gui.yieldFrame() p.join() try: rst = q.get_nowait() except Exception, e: rst = e
def run(disk, image): block_name = disk["name"] product = "%s %s" % (disk["vendor"], disk["model"]) size = disk["size_str"] if dialogbox.messagebox.execute( string_installation_description % (size, product, block_name), dialogbox.DialogBox.OKCANCEL(), gui.res.caution_sign) != "ok": return False with dialogbox.messagebox.open(string_installing): q = multiprocessing.Queue() p = multiprocessing.Process(target=exec_install, args=(disk, image, q)) p.start() while p.is_alive(): gui.yieldFrame() p.join() try: rst = q.get_nowait() except Exception, e: rst = e
def exec_ntp_client(message): with dialogbox.messagebox.open(string_adjusting_time): init_ntpclient = subprocess.Popen("/etc/init.d/ntp-client restart", shell=True, close_fds=True) last_tick = pygame.time.get_ticks() while init_ntpclient.poll() == None: if last_tick > pygame.time.get_ticks(): reset_gui_clock() if gui.yieldFrame(): init_ntpclient.send_signal(signal.SIGINT) return None reset_gui_clock() return (init_ntpclient.wait() == 0)
def nonblockHttpGet(url): cmdline = ["curl", "--cacert", CA_CERT_FILE, "-sLf", url] curl = subprocess.Popen(cmdline, shell=False, close_fds=True, stdout=subprocess.PIPE) s = system.getSystem() nbr = s.getNonblockingReader(curl.stdout) buf = "" r = nbr.read() while r != "": if r != None: buf += r if gui.yieldFrame(): # キャンセルキーでTrueが返る curl.terminate() raise Cancelled() r = nbr.read() curl.stdout.close() rst = curl.wait() if rst != 0: raise CurlException(rst, url) return buf
def start(install_image=None): desktop = gui.DesktopWindow(gui.getScreen().get_size(), gui.res.background) gui.setDesktop(desktop) global header, marquee header = Header() marquee = Marquee() with dialogbox.messagebox.open(u"使用可能なディスクを調査中..."): q = multiprocessing.Queue() p = multiprocessing.Process(target=get_usable_disks, args=(install_image, q)) p.start() while p.is_alive(): gui.yieldFrame() p.join() rst = q.get_nowait() if isinstance(rst, Exception): raise rst disks, install_image = rst mainmenu = MainMenu() mme = MainMenuEventHandler() mainmenu.setEventHandler(mme) install.window = Install() tools.window = Tools() mainmenu_items = [] if len(disks) > 0: mainmenu_items.append( MainMenu.ListItem(gui.res.icon_install, gui.res.string_inst_inatall, install.window)) mainmenu_items.append( MainMenu.ListItem(gui.res.icon_tools, gui.res.string_inst_tool, tools.window)) mainmenu.addItems(mainmenu_items) items_height = sum(map(lambda x: x.getHeight(), mainmenu_items)) mainmenu.addItem( gui.list.Separator(332 - mainmenu.getMarginTop() - items_height)) mainmenu.addItem( MainMenu.SmallListItem(gui.res.icon_shutdown, gui.res.string_inst_end_)) for disk in disks: install.window.addItem( gui.list.TextListItem( "%s %s(%s)" % (disk["vendor"], disk["model"], disk["size_str"]), gui.res.font_select_option, None, None, ("install", disk, u"%s %s(%s, %s)に Walbrixをインストールします" % (disk["vendor"], disk["model"], disk["name"], disk["size_str"])))) tools.window.addItem( gui.list.TextListItem(gui.res.string_inst_gui_benchmark, gui.res.font_select_option, None, None, ("benchmark", gui.res.string_inst_speed_desc))) tools.window.addItem( gui.list.TextListItem(gui.res.string_inst_console, gui.res.font_select_option, None, None, ("console", gui.res.string_linux_console_exit))) desktop.addChild("header", header, (0, 0), -1) desktop.addChild("marquee", marquee, (0, gui.getScreen().get_height() - marquee.getHeight()), -1) desktop.addChild("mainmenu", mainmenu, (0, header.getHeight()), 1) while True: mme.onChange(mainmenu) while gui.eventLoop(mainmenu) == None: pass selected = mainmenu.getSelected().getWindow() if selected == None: return False mainmenu.keepShowingCursor() while True: if gui.eventLoop(selected) == None: break action = selected.getSelected().getData() if action[0] == "install": install.run(action[1], install_image) elif action[0] == "benchmark": if not tools.benchmark_gui(): continue elif action[0] == "console": if not tools.console(): continue
def create_new_domain(args): hostname = args["hostname"] vgname = args["vgname"] tarball = args["tarball"] memory = args["memory"] disk = args["disk"] vcpus = 1 lvname = hostname device_name = system.create_logical_volume_in_GB(vgname, lvname, disk, True, "@wbvm") if device_name == None: wbui.play_sound("fail") dialogbox.messagebox.execute(gui.res.string_domain_failed, None, gui.res.caution_sign) return metadata = None # /etc/wb-va.xml configuration_messages = None # マーキーに作成中の仮想マシンに関する情報を表示 footer.window.setText(gui.res.string_area_description % (hostname, vgname, memory, disk)) try: s = system.getSystem() with s.temporaryMount(device_name, None, "inode32") as tmpdir: with dialogbox.progressbar.open( gui.res.string_download_description) as pb: with s.openWbForInput("extract_archive", (tarball, tmpdir)) as extract_archive: nbr = s.getNonblockingReader(extract_archive.stdout) line = nbr.readline() while line != "": if line != None: (n, m) = map(lambda a: float(a), line.split('/')) pb.setProgress(n / m) if gui.yieldFrame(): extract_archive.send_signal(signal.SIGINT) line = nbr.readline() cli_import.set_hostname(tmpdir, hostname) # https://github.com/wbrxcorp/walbrix/issues/39 xen_conf_dir = os.path.join(tmpdir, "etc/xen") if not os.path.isdir(xen_conf_dir): if os.path.exists(xen_conf_dir): os.unlink(xen_conf_dir) os.makedirs(xen_conf_dir) with open(os.path.join(xen_conf_dir, "config"), "w") as f: f.write("memory=%d\n" % memory) f.write("vcpus=%d\n" % vcpus) # rootのパスワードをつける serialnum = status.get_serial_number() set_root_password(tmpdir, serialnum) # VAのメタデータを得る metadata = system.get_va_metadata(device_name, tmpdir) # メタデータを元に、コンフィギュレーションを行う if metadata != None: configuration_messages = configure_va(metadata, tmpdir) except Exception, e: s = system.getSystem() s.removeLogicalVolume(device_name) wbui.play_sound("fail") traceback.print_exc(file=sys.stderr) dialogbox.messagebox.execute(gui.res.string_create_failed % (e), None, gui.res.caution_sign) return False
# マーキーに作成中の仮想マシンに関する情報を表示 footer.window.setText(gui.res.string_app_apps_area % (app["id"],vgname) ) try: xfs = s.getFilesystem("xfs") xfs.mkfs(device_name) with s.temporaryMount(device_name) as tmpdir: with dialogbox.progressbar.open(gui.res.string_app_while_downloading) as pb: with s.openWbForInput("extract_archive", (tarball, tmpdir)) as extract_archive: nbr = s.getNonblockingReader(extract_archive.stdout) line = nbr.readline() while line != "": if line != None: (n, m) = map(lambda a: float(a), line.split('/')) pb.setProgress(n / m) if gui.yieldFrame(): extract_archive.send_signal(signal.SIGINT) #raise Exception(u"ユーザーによるキャンセル") line = nbr.readline() #extract_archive.wait() #extract_archive.stdout.close() except Exception, e: s.removeLogicalVolume(device_name) traceback.print_exc(file=sys.stderr) dialogbox.messagebox.execute(gui.res.string_app_download_failed % (e), None, gui.res.caution_sign) return False dialogbox.messagebox.execute(gui.res.string_app_download_copmlete) return True def main():
def set_benchmark_progressbar(desktop, text): progressbar = gui.progressbar.ProgressBar(text) desktop.addChild("progressbar", progressbar, ((desktop.getWidth() - progressbar.getWidth()) / 2, (desktop.getHeight() - progressbar.getHeight()) / 2), -1) gui.yieldFrame()
def start_domain(name): def wb_create(q): try: cli_create.run(name) q.put(True) except Exception, e: traceback.print_exc(file=sys.stderr) q.put(e) try: q = multiprocessing.Queue() p = multiprocessing.Process(target=wb_create, args=(q,)) p.start() with dialogbox.messagebox.open(string_starting): while p.is_alive(): gui.yieldFrame() p.join() rst = q.get_nowait() if isinstance(rst, Exception): raise rst except: traceback.print_exc(file=sys.stderr) dialogbox.messagebox.execute(string_not_start, None, gui.res.caution_sign) wbui.play_sound("fail") return False return True def start(domain): return start_domain(domain["name"]) def console(domain):
def start_domain(name): def wb_create(q): try: cli_create.run(name) q.put(True) except Exception, e: traceback.print_exc(file=sys.stderr) q.put(e) try: q = multiprocessing.Queue() p = multiprocessing.Process(target=wb_create, args=(q, )) p.start() with dialogbox.messagebox.open(string_starting): while p.is_alive(): gui.yieldFrame() p.join() rst = q.get_nowait() if isinstance(rst, Exception): raise rst except: traceback.print_exc(file=sys.stderr) dialogbox.messagebox.execute(string_not_start, None, gui.res.caution_sign) wbui.play_sound("fail") return False return True def start(domain): return start_domain(domain["name"])
def create_new_domain(args): hostname = args["hostname"] vgname = args["vgname"] tarball = args["tarball"] memory = args["memory"] disk = args["disk"] vcpus = 1 lvname = hostname device_name = system.create_logical_volume_in_GB(vgname, lvname, disk, True, "@wbvm") if device_name == None: wbui.play_sound("fail") dialogbox.messagebox.execute(gui.res.string_domain_failed, None, gui.res.caution_sign) return metadata = None # /etc/wb-va.xml configuration_messages = None # マーキーに作成中の仮想マシンに関する情報を表示 footer.window.setText(gui.res.string_area_description % (hostname,vgname,memory,disk) ) try: s = system.getSystem() with s.temporaryMount(device_name, None, "inode32") as tmpdir: with dialogbox.progressbar.open(gui.res.string_download_description) as pb: with s.openWbForInput("extract_archive", (tarball, tmpdir)) as extract_archive: nbr = s.getNonblockingReader(extract_archive.stdout) line = nbr.readline() while line != "": if line != None: (n, m) = map(lambda a: float(a), line.split('/')) pb.setProgress(n / m) if gui.yieldFrame(): extract_archive.send_signal(signal.SIGINT) line = nbr.readline() cli_import.set_hostname(tmpdir, hostname) # https://github.com/wbrxcorp/walbrix/issues/39 xen_conf_dir = os.path.join(tmpdir, "etc/xen") if not os.path.isdir(xen_conf_dir): if os.path.exists(xen_conf_dir): os.unlink(xen_conf_dir) os.makedirs(xen_conf_dir) with open(os.path.join(xen_conf_dir, "config"), "w") as f: f.write("memory=%d\n" % memory) f.write("vcpus=%d\n" % vcpus) # rootのパスワードをつける serialnum = status.get_serial_number() set_root_password(tmpdir, serialnum) # VAのメタデータを得る metadata = system.get_va_metadata(device_name, tmpdir) # メタデータを元に、コンフィギュレーションを行う if metadata != None: configuration_messages = configure_va(metadata, tmpdir) except Exception, e: s = system.getSystem() s.removeLogicalVolume(device_name) wbui.play_sound("fail") traceback.print_exc(file=sys.stderr) dialogbox.messagebox.execute(gui.res.string_create_failed % (e), None, gui.res.caution_sign) return False
def run(source_device, esp, device, arch): s = system.getSystem() try: mount_option = "loop" if os.path.isfile(source_device) else None with s.temporaryMount(source_device, mount_option, "ro") as sourceDir: with s.temporaryMount(device) as targetDir: delfiles = [] with s.temporaryFile() as tmpFileName: # excludeFile with open(tmpFileName, "w") as tmpFile: with dialogbox.messagebox.open( gui.res.string_installer_upgrade_check) as pb: tarball = "%s/wb-%s.tar.xz" % (sourceDir, arch) with s.openWbForInput( "compare_files", [tarball, targetDir]) as compare_files: nbr = s.getNonblockingReader( compare_files.stdout) line = nbr.readline() while line != "": if line != None: #print line if line.startswith("X "): tmpFile.write(".%s" % line[2:]) elif line.startswith("D "): delfiles.append(line[2:].rstrip()) else: gui.yieldFrame() line = nbr.readline() with dialogbox.progressbar.open( gui.res.string_installer_upgrade_upgrade ) as progress_bar: with s.openWbForInput("extract_archive", ("-x", tmpFileName, tarball, targetDir)) as extract_archive: show_progress(progress_bar, extract_archive) # delete removed files delete(targetDir, delfiles) # install wbui installer.copyWBUI(sourceDir, targetDir) with dialogbox.progressbar.open( string_copying_boot_files) as progress_bar: with s.temporaryMount(esp) as boot_dir: with s.openWbForInput( "copy_boot_files", ("%s/EFI/Walbrix" % sourceDir, "%s/EFI/Walbrix" % boot_dir)) as copy_boot_files: show_progress(progress_bar, copy_boot_files) s.installGrubEFI(boot_dir) disk = s.getDiskFromPartition( esp) # get the disk which ESP belongs to if s.isBiosCompatibleDisk(disk): s.installGrub(disk, boot_dir) except Exception, e: traceback.print_exc(file=sys.stderr) dialogbox.messagebox.execute( gui.res.string_installer_upgrade_failed % (e), None, gui.res.caution_sign) return False