本文整理汇总了Python中window.Window.addstr方法的典型用法代码示例。如果您正苦于以下问题:Python Window.addstr方法的具体用法?Python Window.addstr怎么用?Python Window.addstr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类window.Window
的用法示例。
在下文中一共展示了Window.addstr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from window import Window [as 别名]
# 或者: from window.Window import addstr [as 别名]
def main(screen):
# setup the basic syntax for text files
text_syntax = SyntaxClass("basic")
text_syntax.add("character", r".")
text_syntax.add("word", r" ")
text_syntax.add("sentance", r"\.")
# make the main window
mainwin = Window(screen, FileBuffer(open("README.markdown")))
mainwin.render()
# the event loop
while True:
event = screen.getch()
if event == ord("q"): break
if event == ord("e"): mainwin.clear()
if event == ord("r"): mainwin.render()
if event == ord("f"): mainwin.addstr("X")
if event == ord("w"): mainwin.rmove(0, -1)
if event == ord("a"): mainwin.rmove(-1, 0)
if event == ord("s"): mainwin.rmove(0, +1)
if event == ord("d"): mainwin.rmove(+1, 0)
if event == ord("x"): mainwin.here()
def find(syntaxname):
return lambda t, x, y: text_syntax.find(syntaxname, t, x, y)
if event == ord("c"): mainwin.movef(find("character"))
if event == ord("v"): mainwin.movef(find("word"))
示例2: DiskPartitioner
# 需要导入模块: from window import Window [as 别名]
# 或者: from window.Window import addstr [as 别名]
class DiskPartitioner(object):
def __init__(self, maxy, maxx):
self.menu_items = []
self.maxx = maxx
self.maxy = maxy
self.win_width = 70
self.win_height = 17
self.win_starty = (self.maxy - self.win_height) / 2
self.win_startx = (self.maxx - self.win_width) / 2
self.menu_starty = self.win_starty + 10
# initialize the devices
self.devices = Device.refresh_devices()
self.items = [
('Auto-partitioning - use entire disk', self.guided_partitions, None),
('Manual - not implemented!', self.manual_partitions, None),
]
self.menu = Menu(self.menu_starty, self.maxx, self.items)
self.window = Window(self.win_height, self.win_width, self.maxy, self.maxx, 'Welcome to the Photon installer', True, self.menu)
self.window.addstr(0, 0, 'First, we will setup your disks. \n\nYou can: \n\na) use auto-partitioning or\nb) you can do it manually.')
def guided_partitions(self, params):
return ActionResult(True, {'guided': True, 'devices': self.devices})
def manual_partitions(self, params):
raise NameError('Manual partitioning not implemented')
def display(self, params):
return self.window.do_action()
示例3: WindowStringReader
# 需要导入模块: from window import Window [as 别名]
# 或者: from window.Window import addstr [as 别名]
class WindowStringReader(object):
def __init__(self, maxy, maxx, height, width, field, confirmation_err_msg,
echo_char, accepted_chars, validation_fn, conversion_fn, title,
display_string, inputy, install_config, default_string=None,
tab_enabled=False):
self.title = title
self.display_string = display_string
self.install_config = install_config
self.inputy = inputy
self.width = width
self.height = height
self.maxx = maxx
self.maxy = maxy
self.startx = (self.maxx - self.width) // 2
self.starty = (self.maxy - self.height) // 2
self.tab_enabled = False
self.can_go_next = True
self.window = Window(self.height, self.width, self.maxy, self.maxx, self.title,
True, tab_enabled=self.tab_enabled,
position=1, can_go_next=self.can_go_next, read_text=self.can_go_next)
self.read_text = ReadText(maxy, maxx, self.window.content_window(), self.inputy,
install_config,
field, confirmation_err_msg, echo_char, accepted_chars,
validation_fn,
conversion_fn, default_string, tab_enabled=self.tab_enabled)
self.window.set_action_panel(self.read_text)
self.window.addstr(0, 0, self.display_string)
def get_user_string(self, params):
return self.window.do_action()
示例4: WindowStringReader
# 需要导入模块: from window import Window [as 别名]
# 或者: from window.Window import addstr [as 别名]
class WindowStringReader(object):
def __init__(self, maxy, maxx, height, width, ispassword, confirm_password, title, display_string, inputy, install_config):
self.title = title
self.display_string = display_string
self.inputy = inputy
self.width = width
self.height = height
self.maxx = maxx
self.maxy = maxy
self.startx = (self.maxx - self.width) / 2
self.starty = (self.maxy - self.height) / 2
self.window = Window(self.height, self.width, self.maxy, self.maxx, self.title, True)
self.read_text = ReadText(maxy, maxx, self.window.content_window(), self.inputy, install_config, ispassword, confirm_password)
self.window.set_action_panel(self.read_text)
self.window.addstr(0, 0, self.display_string)
def get_user_string(self, params):
return self.window.do_action()
示例5: LinuxSelector
# 需要导入模块: from window import Window [as 别名]
# 或者: from window.Window import addstr [as 别名]
class LinuxSelector(object):
def __init__(self, maxy, maxx, install_config):
self.install_config = install_config
self.maxx = maxx
self.maxy = maxy
self.win_width = 60
self.win_height = 13
self.win_starty = (self.maxy - self.win_height) / 2
self.win_startx = (self.maxx - self.win_width) / 2
self.menu_starty = self.win_starty + 6
self.menu_items = []
self.menu_items.append(("1. Hypervisor optimized", self.set_linux_esx_installation, True))
self.menu_items.append(("2. Generic", self.set_linux_esx_installation, False))
self.host_menu = Menu(self.menu_starty, self.maxx, self.menu_items,
default_selected=0, tab_enable=False)
self.window = Window(self.win_height, self.win_width, self.maxy, self.maxx,
'Select Linux kernel to install', True, items=[], tab_enabled=False,
position=1, can_go_next=True)
self.window.set_action_panel(self.host_menu)
def set_linux_esx_installation(self, is_linux_esx):
self.install_config['install_linux_esx'] = is_linux_esx
return ActionResult(True, None)
def display(self, params):
self.window.addstr(0, 0, 'The installer has detected that you are installing')
self.window.addstr(1, 0, 'Photon OS on a VMware hypervisor.')
self.window.addstr(2, 0, 'Which type of Linux kernel would you like to install?')
return self.window.do_action()
示例6: License
# 需要导入模块: from window import Window [as 别名]
# 或者: from window.Window import addstr [as 别名]
class License(object):
def __init__(self, maxy, maxx):
self.maxx = maxx
self.maxy = maxy
self.win_width = maxx - 4
self.win_height = maxy - 4
self.win_starty = (self.maxy - self.win_height) // 2
self.win_startx = (self.maxx - self.win_width) // 2
self.text_starty = self.win_starty + 4
self.text_height = self.win_height - 6
self.text_width = self.win_width - 6
self.window = Window(self.win_height, self.win_width, self.maxy, self.maxx,
'Welcome to the Photon installer', False)
def display(self, params):
accept_decline_items = [('<Accept>', self.accept_function),
('<Cancel>', self.exit_function)]
title = 'VMWARE 2.0 LICENSE AGREEMENT'
self.window.addstr(0, (self.win_width - len(title)) // 2, title)
self.text_pane = TextPane(self.text_starty, self.maxx, self.text_width,
"EULA.txt", self.text_height, accept_decline_items)
self.window.set_action_panel(self.text_pane)
return self.window.do_action()
def accept_function(self):
return ActionResult(True, None)
def exit_function(self):
exit(0)
示例7: Installer
# 需要导入模块: from window import Window [as 别名]
# 或者: from window.Window import addstr [as 别名]
class Installer(object):
def __init__(self, install_config, maxy = 0, maxx = 0, iso_installer = False, tools_path = "../stage", rpm_path = "../stage/RPMS", log_path = "../stage/LOGS", ks_config = None):
self.install_config = install_config
self.ks_config = ks_config
self.iso_installer = iso_installer
self.tools_path = tools_path
self.rpm_path = rpm_path
self.log_path = log_path
self.mount_command = "./mk-mount-disk.sh"
self.prepare_command = "./mk-prepare-system.sh"
self.finalize_command = "./mk-finalize-system.sh"
self.install_package_command = "./mk-install-package.sh"
self.chroot_command = "./mk-run-chroot.sh"
self.setup_grub_command = "./mk-setup-grub.sh"
self.unmount_disk_command = "./mk-unmount-disk.sh"
if self.iso_installer:
self.working_directory = "/mnt/photon-root"
elif 'working_directory' in self.install_config:
self.working_directory = self.install_config['working_directory']
else:
self.working_directory = "/mnt/photon-root"
self.photon_root = self.working_directory + "/photon-chroot";
self.restart_command = "shutdown"
if self.iso_installer:
self.output = open(os.devnull, 'w')
else:
self.output = None
self.install_factor = 3
if self.iso_installer:
#initializing windows
self.maxy = maxy
self.maxx = maxx
self.height = 10
self.width = 75
self.progress_padding = 5
self.progress_width = self.width - self.progress_padding
self.starty = (self.maxy - self.height) / 2
self.startx = (self.maxx - self.width) / 2
self.window = Window(self.height, self.width, self.maxy, self.maxx, 'Installing Photon', False)
self.progress_bar = ProgressBar(self.starty + 3, self.startx + self.progress_padding / 2, self.progress_width)
signal.signal(signal.SIGINT, self.exit_gracefully)
# This will be called if the installer interrupted by Ctrl+C or exception
def exit_gracefully(self, signal, frame):
if self.iso_installer:
self.progress_bar.hide()
self.window.addstr(0, 0, 'Opps, Installer got inturrupted.\n\nPress any key to get to the bash...')
self.window.content_window().getch()
sys.exit(1)
def install(self, params):
try:
return self.unsafe_install(params)
except:
if self.iso_installer:
self.exit_gracefully(None, None)
else:
raise
def unsafe_install(self, params):
if self.iso_installer:
self.window.show_window()
self.progress_bar.initialize('Initializing installation...')
self.progress_bar.show()
self.execute_modules(modules.commons.PRE_INSTALL)
self.initialize_system()
#install packages
for rpm in self.rpms_tobeinstalled:
# We already installed the filesystem in the preparation
if rpm['package'] == 'filesystem':
continue
if self.iso_installer:
self.progress_bar.update_message('Installing {0}...'.format(rpm['package']))
return_value = self.install_package(rpm['package'])
if return_value != 0:
self.exit_gracefully(None, None)
if self.iso_installer:
self.progress_bar.increment(rpm['size'] * self.install_factor)
if self.iso_installer:
self.progress_bar.show_loading('Finalizing installation')
self.finalize_system()
if not self.install_config['iso_system']:
# Execute post installation modules
self.execute_modules(modules.commons.POST_INSTALL)
# install grub
#.........这里部分代码省略.........
示例8: Installer
# 需要导入模块: from window import Window [as 别名]
# 或者: from window.Window import addstr [as 别名]
class Installer(object):
def __init__(self, install_config, maxy = 0, maxx = 0, iso_installer = False, rpm_path = "../stage/RPMS", log_path = "../stage/LOGS", ks_config = None):
self.install_config = install_config
self.ks_config = ks_config
self.iso_installer = iso_installer
self.rpm_path = rpm_path
self.log_path = log_path
self.mount_command = "./mk-mount-disk.sh"
self.prepare_command = "./mk-prepare-system.sh"
self.finalize_command = "./mk-finalize-system.sh"
self.install_package_command = "./mk-install-package.sh"
self.chroot_command = "./mk-run-chroot.sh"
self.setup_grub_command = "./mk-setup-grub.sh"
self.unmount_disk_command = "./mk-unmount-disk.sh"
if self.iso_installer:
self.working_directory = "/mnt/photon-root"
elif 'working_directory' in self.install_config:
self.working_directory = self.install_config['working_directory']
else:
self.working_directory = "/mnt/photon-root"
self.photon_root = self.working_directory + "/photon-chroot";
self.restart_command = "shutdown"
if self.iso_installer:
self.output = open(os.devnull, 'w')
else:
self.output = None
if self.iso_installer:
#initializing windows
self.maxy = maxy
self.maxx = maxx
self.height = 10
self.width = 75
self.progress_padding = 5
self.progress_width = self.width - self.progress_padding
self.starty = (self.maxy - self.height) / 2
self.startx = (self.maxx - self.width) / 2
self.window = Window(self.height, self.width, self.maxy, self.maxx, 'Installing Photon', False)
self.progress_bar = ProgressBar(self.starty + 3, self.startx + self.progress_padding / 2, self.progress_width)
signal.signal(signal.SIGINT, self.exit_gracefully)
# This will be called if the installer interrupted by Ctrl+C or exception
def exit_gracefully(self, signal, frame):
if self.iso_installer:
self.progress_bar.hide()
self.window.addstr(0, 0, 'Opps, Installer got interrupted.\n\nPress any key to get to the bash...')
self.window.content_window().getch()
modules.commons.dump(modules.commons.LOG_FILE_NAME)
sys.exit(1)
def install(self, params):
try:
return self.unsafe_install(params)
except Exception as inst:
if self.iso_installer:
modules.commons.log(modules.commons.LOG_ERROR, repr(inst))
self.exit_gracefully(None, None)
else:
raise
def unsafe_install(self, params):
if self.iso_installer:
self.window.show_window()
self.progress_bar.initialize('Initializing installation...')
self.progress_bar.show()
#self.rpm_path = "https://dl.bintray.com/vmware/photon_release_1.0_TP2_x86_64"
if self.rpm_path.startswith("https://") or self.rpm_path.startswith("http://"):
cmdoption = 's/baseurl.*/baseurl={}/g'.format(self.rpm_path.replace('/','\/'))
process = subprocess.Popen(['sed', '-i', cmdoption,'/etc/yum.repos.d/photon-iso.repo'])
retval = process.wait()
if retval != 0:
modules.commons.log(modules.commons.LOG_INFO, "Failed to reset repo")
self.exit_gracefully(None, None)
cmdoption = 's/cachedir=\/var/cachedir={}/g'.format(self.photon_root.replace('/','\/'))
process = subprocess.Popen(['sed', '-i', cmdoption,'/etc/tdnf/tdnf.conf'])
retval = process.wait()
if retval != 0:
modules.commons.log(modules.commons.LOG_INFO, "Failed to reset tdnf cachedir")
self.exit_gracefully(None, None)
self.execute_modules(modules.commons.PRE_INSTALL)
self.initialize_system()
if self.iso_installer:
self.get_size_of_packages()
selected_packages = self.install_config['packages']
for package in selected_packages:
self.progress_bar.update_message('Installing {0}...'.format(package))
process = subprocess.Popen(['tdnf', 'install', package, '--installroot', self.photon_root, '--nogpgcheck', '--assumeyes'], stdout=self.output, stderr=subprocess.STDOUT)
retval = process.wait()
# 0 : succeed; 137 : package already installed; 65 : package not found in repo.
if retval != 0 and retval != 137:
#.........这里部分代码省略.........
示例9: SelectDisk
# 需要导入模块: from window import Window [as 别名]
# 或者: from window.Window import addstr [as 别名]
class SelectDisk(object):
def __init__(self, maxy, maxx, install_config):
self.install_config = install_config
self.menu_items = []
self.maxx = maxx
self.maxy = maxy
self.win_width = 70
self.win_height = 16
self.win_starty = (self.maxy - self.win_height) / 2
self.win_startx = (self.maxx - self.win_width) / 2
self.menu_starty = self.win_starty + 6
self.menu_height = 5
self.window = Window(self.win_height, self.win_width, self.maxy, self.maxx, 'Setup your disk', True)
self.devices = Device.refresh_devices()
def guided_partitions(self, device_index):
menu_height = 9
menu_width = 40
menu_starty = (self.maxy - menu_height) / 2 + 5
confrim_window = ConfirmWindow(menu_height, menu_width, self.maxy, self.maxx, menu_starty, 'This will erase the disk.\nAre you sure?')
confirmed = confrim_window.do_action().result['yes']
if not confirmed:
return ActionResult(confirmed, None)
#self.install_config['disk'] = self.devices[device_index].path
#return ActionResult(True, None)
# Do the partitioning
self.window.clearerror()
json_ret = subprocess.check_output(['gpartedbin', 'defaultpartitions', self.devices[device_index].path], stderr=open(os.devnull, 'w'))
json_dct = json.loads(json_ret)
if json_dct['success']:
self.install_config['disk'] = json_dct['data']
else:
self.window.adderror('Partitioning failed, you may try again')
return ActionResult(json_dct['success'], None)
def display(self, params):
self.window.addstr(0, 0, 'First, we will setup your disks.\n\nWe have detected {0} disks, choose disk to be auto-partitioned:'.format(len(self.devices)))
self.disk_menu_items = []
# Fill in the menu items
for index, device in enumerate(self.devices):
#if index > 0:
self.disk_menu_items.append(
(
'{2} - {1} MB @ {0}'.format(device.path, device.size, device.model),
self.guided_partitions,
index
)
)
self.disk_menu = Menu(self.menu_starty, self.maxx, self.disk_menu_items, self.menu_height)
self.window.set_action_panel(self.disk_menu)
return self.window.do_action()
示例10: PartitionISO
# 需要导入模块: from window import Window [as 别名]
# 或者: from window.Window import addstr [as 别名]
class PartitionISO(object):
def __init__(self, maxy, maxx, install_config):
self.maxx = maxx
self.maxy = maxy
self.win_width = maxx - 4
self.win_height = maxy - 4
self.install_config = install_config
self.path_checker = []
self.win_starty = (self.maxy - self.win_height) // 2
self.win_startx = (self.maxx - self.win_width) // 2
self.text_starty = self.win_starty + 4
self.text_height = self.win_height - 6
self.text_width = self.win_width - 6
self.install_config['partitionsnumber'] = 0
self.devices = Device.refresh_devices_bytes()
self.has_slash = False
self.has_remain = False
self.has_empty = False
self.disk_size = []
for index, device in enumerate(self.devices):
self.disk_size.append((device.path, int(device.size) / 1048576))
self.window = Window(self.win_height, self.win_width, self.maxy, self.maxx,
'Welcome to the Photon installer', False, can_go_next=False)
Device.refresh_devices()
def display(self, params):
if 'skipPrevs' in self.install_config and self.install_config['skipPrevs'] == True:
self.delete()
return ActionResult(False, {'goBack':True})
if 'autopartition' in self.install_config and self.install_config['autopartition'] == True:
return ActionResult(True, None)
if ('delete_partition' in self.install_config and
self.install_config['delete_partition'] == True):
self.delete()
self.install_config['delete_partition'] = False
self.device_index = self.install_config['diskindex']
self.disk_buttom_items = []
self.disk_buttom_items.append(('<Next>', self.next))
self.disk_buttom_items.append(('<Create New>', self.create_function))
self.disk_buttom_items.append(('<Delete All>', self.delete_function))
self.disk_buttom_items.append(('<Go Back>', self.go_back))
self.text_items = []
self.text_items.append(('Disk', 20))
self.text_items.append(('Size', 5))
self.text_items.append(('Type', 5))
self.text_items.append(('Mountpoint', 20))
self.table_space = 5
title = 'Current partitions:\n'
self.window.addstr(0, (self.win_width - len(title)) // 2, title)
info = ("Unpartitioned space: " +
str(self.disk_size[self.device_index][1])+
" MB, Total size: "+
str(int(self.devices[self.device_index].size)/ 1048576) + " MB")
self.text_pane = TextPane(self.text_starty, self.maxx, self.text_width,
"EULA.txt", self.text_height, self.disk_buttom_items,
partition=True, popupWindow=True,
install_config=self.install_config,
text_items=self.text_items, table_space=self.table_space,
default_start=1, info=info,
size_left=str(self.disk_size[self.device_index][1]))
self.window.set_action_panel(self.text_pane)
return self.window.do_action()
def validate_partition(self, pstr):
if not pstr:
return ActionResult(False, None)
sizedata = pstr[0]
mtdata = pstr[2]
typedata = pstr[1]
devicedata = self.devices[self.device_index].path
#no empty fields unless swap
if (typedata == 'swap' and
(len(mtdata) != 0 or len(typedata) == 0 or len(devicedata) == 0)):
return False, "invalid swap data "
if (typedata != 'swap' and
(len(sizedata) == 0 or
len(mtdata) == 0 or
len(typedata) == 0 or
len(devicedata) == 0)):
if not self.has_empty and mtdata and typedata and devicedata:
self.has_empty = True
else:
return False, "Input cannot be empty"
if typedata != 'swap' and typedata != 'ext3' and typedata != 'ext4':
return False, "Invalid type"
#.........这里部分代码省略.........
示例11: Installer
# 需要导入模块: from window import Window [as 别名]
# 或者: from window.Window import addstr [as 别名]
class Installer(object):
def __init__(self, install_config, maxy = 0, maxx = 0, iso_installer = False, tools_path = "../stage", rpm_path = "../stage/RPMS", log_path = "../stage/LOGS"):
self.install_config = install_config
self.iso_installer = iso_installer
self.tools_path = tools_path
self.rpm_path = rpm_path
self.log_path = log_path
self.mount_command = "./mk-mount-disk.sh"
self.prepare_command = "./mk-prepare-system.sh"
self.finalize_command = "./mk-finalize-system.sh"
self.install_package_command = "./mk-install-package.sh"
self.chroot_command = "./mk-run-chroot.sh"
self.setup_grub_command = "./mk-setup-grub.sh"
self.unmount_disk_command = "./mk-unmount-disk.sh"
if self.iso_installer:
self.working_directory = "/mnt/photon-root"
elif 'working_directory' in self.install_config:
self.working_directory = self.install_config['working_directory']
else:
self.working_directory = "/mnt/photon-root"
self.photon_root = self.working_directory + "/photon-chroot";
self.restart_command = "shutdown"
self.hostname_file = self.photon_root + "/etc/hostname"
self.hosts_file = self.photon_root + "/etc/hosts"
self.passwd_filename = self.photon_root + "/etc/passwd"
self.shadow_filename = self.photon_root + "/etc/shadow"
self.authorized_keys_dir = self.photon_root + "/root/.ssh"
self.authorized_keys_filename = self.authorized_keys_dir + "/authorized_keys"
self.sshd_config_filename = self.photon_root + "/etc/ssh/sshd_config"
if self.iso_installer:
self.output = open(os.devnull, 'w')
else:
self.output = None
self.install_factor = 3
if self.iso_installer:
#initializing windows
self.maxy = maxy
self.maxx = maxx
self.height = 10
self.width = 75
self.progress_padding = 5
self.progress_width = self.width - self.progress_padding
self.starty = (self.maxy - self.height) / 2
self.startx = (self.maxx - self.width) / 2
self.window = Window(self.height, self.width, self.maxy, self.maxx, 'Installing Photon', False)
self.progress_bar = ProgressBar(self.starty + 3, self.startx + self.progress_padding / 2, self.progress_width)
signal.signal(signal.SIGINT, self.exit_gracefully)
# This will be called if the installer interrupted by Ctrl+C or exception
def exit_gracefully(self, signal, frame):
if self.iso_installer:
self.progress_bar.hide()
self.window.addstr(0, 0, 'Opps, Installer got inturrupted.\n\nPress any key to get to the bash...')
self.window.content_window().getch()
sys.exit(1)
def install(self, params):
try:
return self.unsafe_install(params)
except:
if self.iso_installer:
self.exit_gracefully(None, None)
else:
raise
def unsafe_install(self, params):
if self.iso_installer:
self.window.show_window()
self.progress_bar.initialize('Initializing installation...')
self.progress_bar.show()
self.initialize_system()
#install packages
for rpm in self.rpms_tobeinstalled:
# We already installed the filesystem in the preparation
if rpm['package'] == 'filesystem':
continue
if self.iso_installer:
self.progress_bar.update_message('Installing {0}...'.format(rpm['package']))
return_value = self.install_package(rpm['package'])
if return_value != 0:
self.exit_gracefully(None, None)
if self.iso_installer:
self.progress_bar.increment(rpm['size'] * self.install_factor)
if self.iso_installer:
self.progress_bar.show_loading('Finalizing installation')
self.finalize_system()
if not self.install_config['iso_system']:
#.........这里部分代码省略.........
示例12: Installer
# 需要导入模块: from window import Window [as 别名]
# 或者: from window.Window import addstr [as 别名]
class Installer(object):
"""
Photon installer
"""
mount_command = "./mk-mount-disk.sh"
prepare_command = "./mk-prepare-system.sh"
finalize_command = "./mk-finalize-system.sh"
chroot_command = "./mk-run-chroot.sh"
setup_grub_command = "./mk-setup-grub.sh"
unmount_disk_command = "./mk-unmount-disk.sh"
def __init__(self, install_config, maxy=0, maxx=0, iso_installer=False,
rpm_path="../stage/RPMS", log_path="../stage/LOGS"):
self.install_config = install_config
self.install_config['iso_installer'] = iso_installer
self.rpm_path = rpm_path
self.log_path = log_path
if 'working_directory' in self.install_config:
self.working_directory = self.install_config['working_directory']
else:
self.working_directory = "/mnt/photon-root"
self.photon_root = self.working_directory + "/photon-chroot"
self.rpms_tobeinstalled = None
if self.install_config['iso_installer']:
self.output = open(os.devnull, 'w')
#initializing windows
height = 10
width = 75
progress_padding = 5
progress_width = width - progress_padding
starty = (maxy - height) // 2
startx = (maxx - width) // 2
self.window = Window(height, width, maxy, maxx,
'Installing Photon', False)
self.progress_bar = ProgressBar(starty + 3,
startx + progress_padding // 2,
progress_width)
else:
self.output = None
signal.signal(signal.SIGINT, self.exit_gracefully)
def install(self, params):
"""
Install photon system and handle exception
"""
del params
try:
return self._unsafe_install()
except Exception as inst:
if self.install_config['iso_installer']:
modules.commons.log(modules.commons.LOG_ERROR, repr(inst))
self.exit_gracefully(None, None)
else:
raise
def _unsafe_install(self):
"""
Install photon system
"""
self._setup_install_repo()
self._initialize_system()
self._install_packages()
self._enable_network_in_chroot()
self._finalize_system()
self._disable_network_in_chroot()
self._cleanup_and_exit()
return ActionResult(True, None)
def exit_gracefully(self, signal1, frame1):
"""
This will be called if the installer interrupted by Ctrl+C, exception
or other failures
"""
del signal1
del frame1
if self.install_config['iso_installer']:
self.progress_bar.hide()
self.window.addstr(0, 0, 'Oops, Installer got interrupted.\n\n' +
'Press any key to get to the bash...')
self.window.content_window().getch()
modules.commons.dump(modules.commons.LOG_FILE_NAME)
sys.exit(1)
def _cleanup_and_exit(self):
"""
Unmount the disk, eject cd and exit
"""
command = [Installer.unmount_disk_command, '-w', self.photon_root]
if not self.install_config['iso_system']:
command.extend(self._generate_partitions_param(reverse=True))
process = subprocess.Popen(command, stdout=self.output)
retval = process.wait()
if retval != 0:
modules.commons.log(modules.commons.LOG_ERROR, "Failed to unmount disks")
#.........这里部分代码省略.........
示例13: SelectDisk
# 需要导入模块: from window import Window [as 别名]
# 或者: from window.Window import addstr [as 别名]
class SelectDisk(object):
def __init__(self, maxy, maxx, install_config):
self.install_config = install_config
self.menu_items = []
self.maxx = maxx
self.maxy = maxy
self.win_width = 70
self.win_height = 16
self.win_starty = (self.maxy - self.win_height) / 2
self.win_startx = (self.maxx - self.win_width) / 2
self.menu_starty = self.win_starty + 6
self.menu_height = 5
self.progress_padding = 5
self.progress_width = self.win_width - self.progress_padding
self.progress_bar = ProgressBar(self.win_starty + 6, self.win_startx + self.progress_padding / 2, self.progress_width)
self.window = Window(self.win_height, self.win_width, self.maxy, self.maxx, 'Setup your disk', True)
self.devices = Device.refresh_devices()
def guided_partitions(self, device_index):
menu_height = 9
menu_width = 40
menu_starty = (self.maxy - menu_height) / 2 + 5
confrim_window = ConfirmWindow(menu_height, menu_width, self.maxy, self.maxx, menu_starty, 'This will erase the disk.\nAre you sure?')
confirmed = confrim_window.do_action().result['yes']
if not confirmed:
return ActionResult(confirmed, None)
self.progress_bar.initialize('Partitioning...')
self.progress_bar.show()
self.progress_bar.show_loading('Partitioning')
# Do the partitioning
self.window.clearerror()
partitions_data = modules.commons.partition_disk(self.devices[device_index].path, modules.commons.default_partitions)
if partitions_data == None:
self.window.adderror('Partitioning failed, you may try again')
else:
self.install_config['disk'] = partitions_data
self.progress_bar.hide()
return ActionResult(partitions_data != None, None)
def display(self, params):
self.window.addstr(0, 0, 'First, we will setup your disks.\n\nWe have detected {0} disks, choose disk to be auto-partitioned:'.format(len(self.devices)))
self.disk_menu_items = []
# Fill in the menu items
for index, device in enumerate(self.devices):
#if index > 0:
self.disk_menu_items.append(
(
'{2} - {1} @ {0}'.format(device.path, device.size, device.model),
self.guided_partitions,
index
)
)
self.disk_menu = Menu(self.menu_starty, self.maxx, self.disk_menu_items, self.menu_height)
self.window.set_action_panel(self.disk_menu)
return self.window.do_action()
示例14: Installer
# 需要导入模块: from window import Window [as 别名]
# 或者: from window.Window import addstr [as 别名]
class Installer(object):
def __init__(self, install_config, maxy = 0, maxx = 0, iso_installer = False, rpm_path = "../stage/RPMS", log_path = "../stage/LOGS", ks_config = None):
self.install_config = install_config
self.ks_config = ks_config
self.iso_installer = iso_installer
self.rpm_path = rpm_path
self.log_path = log_path
self.mount_command = "./mk-mount-disk.sh"
self.prepare_command = "./mk-prepare-system.sh"
self.finalize_command = "./mk-finalize-system.sh"
self.install_package_command = "./mk-install-package.sh"
self.chroot_command = "./mk-run-chroot.sh"
self.setup_grub_command = "./mk-setup-grub.sh"
self.unmount_disk_command = "./mk-unmount-disk.sh"
if self.iso_installer:
self.working_directory = "/mnt/photon-root"
elif 'working_directory' in self.install_config:
self.working_directory = self.install_config['working_directory']
else:
self.working_directory = "/mnt/photon-root"
self.photon_root = self.working_directory + "/photon-chroot";
self.restart_command = "shutdown"
if self.iso_installer:
self.output = open(os.devnull, 'w')
else:
self.output = None
if self.iso_installer:
#initializing windows
self.maxy = maxy
self.maxx = maxx
self.height = 10
self.width = 75
self.progress_padding = 5
self.progress_width = self.width - self.progress_padding
self.starty = (self.maxy - self.height) / 2
self.startx = (self.maxx - self.width) / 2
self.window = Window(self.height, self.width, self.maxy, self.maxx, 'Installing Photon', False)
self.progress_bar = ProgressBar(self.starty + 3, self.startx + self.progress_padding / 2, self.progress_width)
signal.signal(signal.SIGINT, self.exit_gracefully)
# This will be called if the installer interrupted by Ctrl+C or exception
def exit_gracefully(self, signal, frame):
if self.iso_installer:
self.progress_bar.hide()
self.window.addstr(0, 0, 'Opps, Installer got interrupted.\n\nPress any key to get to the bash...')
self.window.content_window().getch()
modules.commons.dump(modules.commons.LOG_ERROR, modules.commons.LOG_FILE_NAME)
sys.exit(1)
def install(self, params):
try:
return self.unsafe_install(params)
except:
if self.iso_installer:
self.exit_gracefully(None, None)
else:
raise
def unsafe_install(self, params):
if self.iso_installer:
self.window.show_window()
self.progress_bar.initialize('Initializing installation...')
self.progress_bar.show()
self.execute_modules(modules.commons.PRE_INSTALL)
self.initialize_system()
#install packages
for rpm in self.rpms_tobeinstalled:
# We already installed the filesystem in the preparation
if rpm['package'] == 'filesystem':
continue
if self.iso_installer:
self.progress_bar.update_message('Installing {0}...'.format(rpm['package']))
return_value = self.install_package(rpm['filename'])
if return_value != 0:
self.exit_gracefully(None, None)
if self.iso_installer:
self.progress_bar.increment(rpm['size'] * self.install_factor)
if self.iso_installer:
self.progress_bar.show_loading('Finalizing installation')
self.finalize_system()
if not self.install_config['iso_system']:
# Execute post installation modules
self.execute_modules(modules.commons.POST_INSTALL)
# install grub
try:
#.........这里部分代码省略.........
示例15: SelectDisk
# 需要导入模块: from window import Window [as 别名]
# 或者: from window.Window import addstr [as 别名]
class SelectDisk(object):
def __init__(self, maxy, maxx, install_config):
self.install_config = install_config
self.menu_items = []
self.maxx = maxx
self.maxy = maxy
self.win_width = 70
self.win_height = 16
self.win_starty = (self.maxy - self.win_height) / 2
self.win_startx = (self.maxx - self.win_width) / 2
self.menu_starty = self.win_starty + 6
self.menu_height = 5
self.progress_padding = 5
self.progress_width = self.win_width - self.progress_padding
self.progress_bar = ProgressBar(self.win_starty + 6, self.win_startx + self.progress_padding / 2, self.progress_width, new_win=True)
self.disk_buttom_items = []
self.disk_buttom_items.append(('<Custom>', self.custom_function, False))
self.disk_buttom_items.append(('<Auto>', self.auto_function, False))
self.window = Window(self.win_height, self.win_width, self.maxy, self.maxx, 'Select a disk', True, items = self.disk_buttom_items, menu_helper = self.save_index, position = 2, tab_enabled=False)
self.partition_window = Window(self.win_height, self.win_width, self.maxy, self.maxx, 'Partition', True)
self.devices = Device.refresh_devices()
def guided_partitions(self, params):
if not 'diskindex' in self.install_config:
return ActionResult(False, None);
device_index = self.install_config['diskindex']
menu_height = 9
menu_width = 40
menu_starty = (self.maxy - menu_height) / 2 + 5
self.install_config['delete_partition'] = True
confrim_window = ConfirmWindow(menu_height, menu_width, self.maxy, self.maxx, menu_starty, 'This will erase the disk.\nAre you sure?')
confirmed = confrim_window.do_action().result['yes']
if confirmed == False:
self.install_config['skipPrevs'] = True
return ActionResult(False, {'goBack':True})
self.install_config['skipPrevs'] = False
self.progress_bar.initialize('Partitioning...')
self.progress_bar.show()
self.progress_bar.show_loading('Partitioning')
# Do the partitioning
if 'partitionsnumber' in self.install_config:
if (int(self.install_config['partitionsnumber']) == 0):
partitions_data = modules.commons.partition_disk(self.devices[device_index].path, modules.commons.default_partitions)
else:
partitions = []
for i in range (int (self.install_config['partitionsnumber'])):
if len(self.install_config[str(i)+'partition_info'+str(0)])==0:
sizedata=0
else:
sizedata = int(self.install_config[str(i)+'partition_info'+str(0)])
mtdata = self.install_config[str(i)+'partition_info'+str(2)]
typedata = self.install_config[str(i)+'partition_info'+str(1)]
partitions = partitions + [
{"mountpoint": mtdata, "size": sizedata, "filesystem": typedata},
]
partitions_data = modules.commons.partition_disk(self.devices[device_index].path, partitions)
else:
partitions_data = modules.commons.partition_disk(self.devices[device_index].path, modules.commons.default_partitions)
if partitions_data == None:
self.partition_window.adderror('Partitioning failed, you may try again')
else:
self.install_config['disk'] = partitions_data
self.progress_bar.hide()
return ActionResult(partitions_data != None, None)
def display(self, params):
if 'skipPrevs' in self.install_config:
self.install_config['skipPrevs'] = False
self.window.addstr(0, 0, 'Please select a disk and a method how to partition it:\nAuto - single partition for /, no swap partition.\nCustom - for customized partitioning')
self.disk_menu_items = []
# Fill in the menu items
for index, device in enumerate(self.devices):
#if index > 0:
self.disk_menu_items.append(
(
'{2} - {1} @ {0}'.format(device.path, device.size, device.model),
self.save_index,
index
)
)
self.disk_menu = Menu(self.menu_starty, self.maxx, self.disk_menu_items, self.menu_height, tab_enable=False)
self.disk_menu.can_save_sel(True)
self.window.set_action_panel(self.disk_menu)
#.........这里部分代码省略.........