class DownloadMonitor(): def __init__(self, screen, title, item_count=0): self.screen = screen self.title = title self.current_item = 0 self.item_count = item_count g = Grid(1, 2) self.fnm_label = Textbox(40, 2, 'Downloading...', 0, 0) self.scale = Scale(40, 100) self.scale.set(0) g.setField(self.fnm_label, 0, 1) g.setField(self.scale, 0, 0) self.screen.gridWrappedWindow(g, title) self.f = Form() self.f.add(self.scale) self.f.add(self.fnm_label) def update_url(self, fnm): self.current_item = self.current_item + 1 self.fnm_label.setText("(%s/%s): %s" % (self.current_item, self.item_count, fnm)) def download_hook(self, count, blockSize, totalSize): donep = int(min(100, float(blockSize * count) / totalSize * 100)) self.scale.set(donep) self.f.draw() self.screen.refresh()
def __init__(self, screen, title, text): self.screen = screen self.g = GridForm(self.screen, title, 1, 2) self.s = Scale(70, 100) self.t = Textbox(70, 12, text) self.g.add(self.s, 0, 0) self.g.add(self.t, 0, 1, padding=(0, 1, 0, 0))
def display_create_template(screen, title, vm_type, templates, help=None): """Helper function for displaying a form for creating a new VM template""" label_base = Textbox( 40, 2, 'Select %s VM to be used as a basis\n(only stopped VMs are allowed)' % vm_type, 0, 0) base_tmpl = Listbox(7, 1, 0, 30, 1) for vm in templates.keys(): base_tmpl.append(templates[vm], vm) label_newname = Textbox(40, 2, 'Name of the template to be created', 0, 0) spacer1 = Textbox(1, 1, "", 0, 0) spacer2 = Textbox(1, 1, "", 0, 0) entry_newname = Entry(30, 'template_name') bb = ButtonBar(screen, ('Create new template', ('Back to menu', 'back'))) form = GridFormHelp(screen, title, help, 1, 7) form.add(label_base, 0, 0) form.add(base_tmpl, 0, 1) form.add(spacer1, 0, 2) form.add(label_newname, 0, 3) form.add(entry_newname, 0, 4) form.add(spacer2, 0, 5) form.add(bb, 0, 6) form_result = form.runOnce() tmpl_name = entry_newname.value() # remove whitespaces from the template name tmpl_name = re.sub(r'\s', '', tmpl_name) return (bb.buttonPressed(form_result), str(base_tmpl.current()), tmpl_name)
def _define_view(self, button_save, button_exit): rows = [(Textbox(20, 1, "Template name:", 0, 0), self.template_name), self.separator, (Textbox(20, 1, "Memory size (GB):", 0, 0), self.memory), (Textbox(20, 1, "Min memory size (GB):", 0, 0), self.memory_min), self.separator, (Textbox(20, 1, "Number of CPUs:", 0, 0), self.vcpu), (Textbox(20, 1, "Min number of CPUs:", 0, 0), self.vcpu_min), self.separator, (button_exit, button_save)] return rows
def _define_view(self, button_save, button_exit): rows = super(KvmTemplateEditForm, self)._define_view(button_save, button_exit) rows.insert(-2, self.separator) rows.insert(-2, (Textbox(20, 1, 'Default admin:', 0, 0), self.username)) rows.insert(-2, self.separator) rows.insert(-2, (Textbox(20, 1, 'Password:'******'Password x2:', 0, 0), self.password2)) return rows
def display(self): button_save, button_exit = Button("Migrate"), Button("Back") separator = (Textbox(20, 1, "", 0, 0), Textbox(20, 1, "", 0, 0)) rows = [(Textbox(20, 1, "Hostname/IP:", 0, 0), self.target), separator, (Textbox(20, 1, "Live migration:", 0, 0), self.live), separator, (button_save, button_exit)] form = GridForm(self.screen, self.title, 2, len(rows)) for i, row in enumerate(rows): for j, cell in enumerate(row): form.add(cell, j, i) return form.runOnce() != button_exit
def __init__(self, margin, title, message=None, vendor_text=None, args=None): self.debug_mode = args is not None and args.debug self.screen = SnackScreen() # set usual colors for i in colorsets["ROOT"], colorsets["ROOTTEXT"], colorsets[ "HELPLINE"], colorsets["EMPTYSCALE"]: self.screen.setColor(i, "white", "blue") if not self.debug_mode else \ self.screen.setColor(i, "brightgreen", "black") # remove silly default help text self.screen.popHelpLine() # write static messages self.screen.drawRootText((self.screen.width - len(message)) // 2, 4, message) self.screen.drawRootText(-len(vendor_text) - 2, -2, vendor_text) if self.debug_mode: # write some static debug information self.screen.drawRootText(1, 1, _("DEBUG MODE")) self.screen.drawRootText( 2, 2, "screen {}×{}".format(self.screen.width, self.screen.height)) self.screen.drawRootText(2, 3, "file {}".format(args.input)) self.window_width = self.screen.width - margin * 2 # assemble our progress bar self.scale = Scale(self.window_width, 100) self.spacer = Label("") self.taskbox = Textbox(self.window_width - 2, 1, "") self.messagebox = Textbox(self.window_width - 8, 1, " . . . ") self.grid = Grid(1, 4) self.grid.setField(self.scale, 0, 0) self.grid.setField(self.spacer, 0, 1) self.grid.setField(self.taskbox, 0, 2) self.grid.setField(self.messagebox, 0, 3) self.grid.place(1, 1) self.screen.gridWrappedWindow(self.grid, title) self.form = Form() self.form.add(self.scale) self.form.add(self.taskbox) self.form.add(self.messagebox) self.form.draw() self.screen.refresh()
class GenericTemplateEditForm(Form): separator = (Textbox(20, 1, "", 0, 0), Textbox(20, 1, "", 0, 0)) def _define_fields(self, settings): self.memory = FloatField("memory", settings["memory"]) self.memory_min = FloatField("memory_min", settings.get("memory_min", ""), display_name="min memory", required=False) self.vcpu = FloatField("vcpu", settings["vcpu"]) self.vcpu_min = FloatField("vcpu_min", settings.get("vcpu_min", ""), display_name="min vcpu", required=False) self.template_name = StringField('template_name', settings.get('template_name'), display_name='template name', required=False) return [ self.memory, self.memory_min, self.vcpu, self.vcpu_min, self.template_name ] def _define_view(self, button_save, button_exit): rows = [(Textbox(20, 1, "Template name:", 0, 0), self.template_name), self.separator, (Textbox(20, 1, "Memory size (GB):", 0, 0), self.memory), (Textbox(20, 1, "Min memory size (GB):", 0, 0), self.memory_min), self.separator, (Textbox(20, 1, "Number of CPUs:", 0, 0), self.vcpu), (Textbox(20, 1, "Min number of CPUs:", 0, 0), self.vcpu_min), self.separator, (button_exit, button_save)] return rows def __init__(self, screen, title, settings): self.settings = settings super(GenericTemplateEditForm, self).__init__(screen, title, self._define_fields(settings)) def display(self): button_save, button_exit = Button("Edit"), Button("Cancel") rows = self._define_view(button_save, button_exit) form = GridForm(self.screen, self.title, 2, len(rows)) for i, row in enumerate(rows): for j, cell in enumerate(row): form.add(cell, j, i) return form.runOnce() != button_exit
def __init__(self, screen, title, item_count=0): self.screen = screen self.title = title self.current_item = 0 self.item_count = item_count g = Grid(1, 2) self.fnm_label = Textbox(40, 2, 'Downloading...', 0, 0) self.scale = Scale(40, 100) self.scale.set(0) g.setField(self.fnm_label, 0, 1) g.setField(self.scale, 0, 0) self.screen.gridWrappedWindow(g, title) self.f = Form() self.f.add(self.scale) self.f.add(self.fnm_label)
def form(self): elements = Grid(2, 8) is_network_up = network_up() if is_network_up: header_message = "oVirt Engine Configuration" else: header_message = "Network Down, oVirt Engine Configuration Disabled" heading = Label(header_message) self.ncs.screen.setColor(customColorset(1), "black", "magenta") heading.setColors(customColorset(1)) elements.setField(heading, 0, 0, anchorLeft = 1) rhevm_grid = Grid(2,2) rhevm_grid.setField(Label("Management Server:"), 0, 0, anchorLeft = 1) self.rhevm_server = Entry(25, "") self.rhevm_server.setCallback(self.valid_rhevm_server_callback) rhevm_grid.setField(Label("Management Server Port:"), 0, 1, anchorLeft = 1) self.rhevm_server_port = Entry(6, "", scroll = 0) self.rhevm_server_port.setCallback(self.valid_rhevm_server_port_callback) rhevm_grid.setField(self.rhevm_server, 1, 0, anchorLeft = 1, padding=(2, 0, 0, 1)) rhevm_grid.setField(self.rhevm_server_port, 1, 1, anchorLeft = 1, padding=(2, 0, 0, 1)) elements.setField(rhevm_grid, 0, 1, anchorLeft = 1, padding = (0,0,0,0)) elements.setField(Label(""), 0, 2, anchorLeft = 1) self.verify_rhevm_cert = Checkbox("Connect to oVirt Engine and Validate Certificate", isOn=True) elements.setField(self.verify_rhevm_cert, 0, 3, anchorLeft = 1, padding = (0,0,0,0)) elements.setField(Label(""), 0, 4, anchorLeft = 1) elements.setField(Label("Set oVirt Engine Admin Password"), 0, 5, anchorLeft = 1) pw_elements = Grid(3,3) pw_elements.setField(Label("Password: "******"Confirm Password: "******"", wrap=1) elements.setField(pw_elements, 0, 6, anchorLeft=1) elements.setField(self.pw_msg, 0, 7, padding = (0,0,0,0)) inputFields = [self.rhevm_server, self.rhevm_server_port, self.verify_rhevm_cert, self.root_password_1, self.root_password_2] if not is_network_up: for field in inputFields: field.setFlags(FLAG_DISABLED, FLAGS_SET) try: rhevm_server = get_rhevm_config() rhevm_server,rhevm_port = rhevm_server.split(":") if rhevm_server.startswith("None"): self.rhevm_server.set("") else: self.rhevm_server.set(rhevm_server) self.rhevm_server_port.set(rhevm_port) except: pass return [Label(""), elements]
def create_ui(self): """ Creates/Draws the UI """ self.button_bar = ButtonBar(self.screen, ((_("Cancel"), "cancel"), (_("Install"), "ok")), compact=True) self.textview_changes = Textbox(72, 8, "Changelog", True, True) self.checkbox_tree_updates = CheckboxTree(height=8, width=72, scroll=1) self.checkbox_tree_updates.setCallback(self.checkbox_changed) self.layout = GridForm(self.screen, "Updates", 1, 5) self.layout.add(self.checkbox_tree_updates, 0, 0) # empty line to make it look less crowded self.layout.add(Textbox(60, 1, " ", False, False), 0, 1) self.layout.add(self.textview_changes, 0, 2) # empty line to make it look less crowded self.layout.add(Textbox(60, 1, " ", False, False), 0, 3) self.layout.add(self.button_bar, 0, 4) # FIXME: better progress than the current suspend/resume screen thing self.screen.suspend()
def display_info(screen, title, info_text="Close me, please.", width=50, height=2): """Display information message on information screen""" g = GridFormHelp(screen, title, help, 1, 2) g.add(Textbox(width, height, info_text, 0, 0), 0, 0, padding=(0, 1, 0, 1)) g.add(Button("OK"), 0, 1) g.runOnce()
def display_yesno(screen, title, question_text="Yes / No", width=50, height=2): """Display yes/no dialog. Return True on yes and False on no.""" g = GridFormHelp(screen, title, help, 1, 2) bb = ButtonBar(screen, (('No', 'no', 'F12'), 'Yes')) g.add(Textbox(width, height, question_text, 0, 0), 0, 0, padding=(0, 1, 0, 1)) g.add(bb, 0, 1) rc = g.runOnce() return bb.buttonPressed(rc) == 'yes'
def display(self): button_save, button_exit = Button("Create"), Button("Back") separator = (Textbox(20, 1, "", 0, 0), Textbox(20, 1, "", 0, 0)) rows = [(Textbox(20, 1, "Memory size (GB):", 0, 0), self.memory), (Textbox(20, 1, "Min memory size (GB):", 0, 0), self.memory_min), (Textbox(20, 1, "Max memory size (GB):", 0, 0), self.memory_max), separator, (Textbox(20, 1, "Number of CPUs:", 0, 0), self.vcpu), (Textbox(20, 1, "Min number of CPUs:", 0, 0), self.vcpu_min), (Textbox(20, 1, "Max number of CPUs:", 0, 0), self.vcpu_max), separator, (Textbox(20, 1, "Disk size (GB):", 0, 0), self.disk), separator, (Textbox(20, 1, "OS template:", 0, 0), self.ostemplate), separator, (button_exit, button_save)] form = GridForm(self.screen, self.title, 2, len(rows)) for i, row in enumerate(rows): for j, cell in enumerate(row): form.add(cell, j, i) return form.runOnce() != button_exit
def __init__(self, datadir): self.screen = SnackScreen() # FIXME: self.screen.finish() clears the screen (and all messages) # there too #atexit.register(self.restoreScreen) self.button_bar = ButtonBar(self.screen, ((_("Cancel"), "cancel"), (_("Install"), "ok")), compact=True) self.textview_changes = Textbox(72, 8, _("Changelog"), True, True) self.checkbox_tree_updates = CheckboxTree(height=8, width=72, scroll=1) self.checkbox_tree_updates.setCallback(self.checkbox_changed) self.layout = GridForm(self.screen, _("Updates"), 1, 5) self.layout.add(self.checkbox_tree_updates, 0, 0) # empty line to make it look less crowded self.layout.add(Textbox(60, 1, " ", False, False), 0, 1) self.layout.add(self.textview_changes, 0, 2) # empty line to make it look less crowded self.layout.add(Textbox(60, 1, " ", False, False), 0, 3) self.layout.add(self.button_bar, 0, 4) # FIXME: better progress than the current suspend/resume screen thing self.screen.suspend() if not self.DEBUG: apt_pkg.pkgsystem_lock() self.openCache() print(_("Building Updates List")) self.fillstore() if self.list.distUpgradeWouldDelete > 0: print( _(""" A normal upgrade can not be calculated, please run: sudo apt-get dist-upgrade This can be caused by: * A previous upgrade which didn't complete * Problems with some of the installed software * Unofficial software packages not provided by Ubuntu * Normal changes of a pre-release version of Ubuntu""")) sys.exit(1) self.screen.resume()
class ExtTopProgressWindow: def __init__(self, screen, title, text): self.screen = screen self.g = GridForm(self.screen, title, 1, 2) self.s = Scale(70, 100) self.t = Textbox(70, 12, text) self.g.add(self.s, 0, 0) self.g.add(self.t, 0, 1, padding=(0, 1, 0, 0)) def show(self): self.g.draw() self.screen.refresh() def update(self, progress, text=''): self.s.set(progress) self.t.setText(text) self.g.draw() self.screen.refresh() def close(self): time.sleep(1) self.screen.popWindow()
def dup(): screen = SnackScreen() bb = ButtonBar(screen, (("Yes", "yes"), ("No", "no"))) tb = Textbox( 70, 4, "It's recomended to run the Distribution Update after Initiliazation. \nDo you want to run Distribution Update after Initiliazation ?", ) g = GridForm(screen, "Distribution Update", 1, 4) g.add(tb, 0, 2) g.add(bb, 0, 3, growx=1) result = g.runOnce() screen.finish() return bb.buttonPressed(result)
def welcome(): screen = SnackScreen() bb = ButtonBar(screen, (("Continue", "continue"), ("Cancel", "cancel"))) tb = Textbox( 65, 4, "Python Script to Initialize New openSUSE Tumbleweed Installation,\nlike Installing Applications, Enabling & Starting Services, \nand Performing Distrubution Update.", ) g = GridForm(screen, "TW-Init - by Trodskovich", 1, 4) g.add(tb, 0, 2) g.add(bb, 0, 3, growx=1) result = g.runOnce() screen.finish() return bb.buttonPressed(result)
def add_repo(): screen = SnackScreen() bb = ButtonBar(screen, (("Add", "add"), ("Cancel", "cancel"))) tb = Textbox( 50, 5, "Multimedia Applications and Codecs require Packman Repositary to be added in order to work correctly. \nDo you want add Packman repo now ?", 0, 1, ) g = GridForm(screen, "Packman Repo", 1, 4) g.add(tb, 0, 2) g.add(bb, 0, 3, growx=1) result = g.runOnce() screen.finish() return bb.buttonPressed(result)
def display(self): button_save, button_exit = Button("Create VM"), Button("Main menu") separator = (Textbox(20, 1, "", 0, 0), Textbox(20, 1, "", 0, 0)) rows = [ (Textbox(20, 1, "Memory size (GB):", 0, 0), self.memory), (Textbox(20, 1, "Memory min/max:", 0, 0), Textbox( 20, 1, "%s / %s" % (self.memory.min_value, self.memory.max_value), 0, 0)), separator, (Textbox(20, 1, "Number of CPUs:", 0, 0), self.vcpu), (Textbox(20, 1, "CPU number min/max:", 0, 0), Textbox(20, 1, "%s / %s" % (self.vcpu.min_value, self.vcpu.max_value), 0, 0)), separator, (Textbox(20, 1, "Hostname:", 0, 0), self.hostname), separator, (button_save, button_exit) ] form = GridForm(self.screen, self.title, 2, len(rows)) for i, row in enumerate(rows): for j, cell in enumerate(row): form.add(cell, j, i) return form.runOnce() != button_exit
def ExtCheckboxWindow(screen, title, text, items, buttons=('Ok', 'Cancel'), width=50, height=8): g = GridForm(screen, title, 1, 3) g.add(Textbox(width, 2, text), 0, 0) scroll = 0 if len(items) > height: scroll = 1 ct = CheckboxTree(height, scroll, width) if len(items) > 0: for i in items: ct.append(i, i, items[i]) g.add(ct, 0, 1) bb = ButtonBar(screen, buttons, compact=1) g.add(bb, 0, 2, (0, 2, 0, 0), growx=1, growy=1) result = g.runOnce() return bb.buttonPressed(result), ct.getSelection()
def __init__(self, datadir): self.screen = SnackScreen() # FIXME: self.screen.finish() clears the screen (and all messages) # there too #atexit.register(self.restoreScreen) self.button_bar = ButtonBar(self.screen, ( (_("Cancel"), "cancel"), (_("Install"), "ok")), compact = True) self.textview_changes = Textbox(72, 8, "Changelog", True, True) self.checkbox_tree_updates = CheckboxTree(height=8, width=72, scroll=1) self.checkbox_tree_updates.setCallback(self.checkbox_changed) self.layout = GridForm(self.screen, "Updates", 1, 5) self.layout.add(self.checkbox_tree_updates, 0, 0) # empty line to make it look less crowded self.layout.add(Textbox(60, 1," ",False, False), 0, 1) self.layout.add(self.textview_changes, 0, 2) # empty line to make it look less crowded self.layout.add(Textbox(60, 1," ",False, False), 0, 3) self.layout.add(self.button_bar, 0, 4) # FIXME: better progress than the current suspend/resume screen thing self.screen.suspend() if not self.DEBUG: apt_pkg.PkgSystemLock() self.openCache() print _("Building Updates List") self.fillstore() if self.list.distUpgradeWouldDelete > 0: print _(""" A normal upgrade can not be calculated, please run: sudo apt-get dist-upgrade This can be caused by: * A previous upgrade which didn't complete * Problems with some of the installed software * Unofficial software packages not provided by Ubuntu * Normal changes of a pre-release version of Ubuntu""") sys.exit(1) self.screen.resume()
def select_packages(): global sellist screen = SnackScreen() ct = CheckboxTree(height=20, scroll=1) for idx, key in enumerate(packages): ct.append(key) for val in packages[key]: ct.addItem(val, (idx, snackArgs["append"])) ct.setEntryValue(val) bb = ButtonBar(screen, (("Next", "next"), ("Cancel", "cancel"))) g = GridForm(screen, "Packages", 1, 4) g.add(ct, 0, 2) g.add(bb, 0, 3, growx=1) result = g.runOnce() screen.finish() # format selected packages list for zypper and print(result) sellist = (str(ct.getSelection()).replace("[", "").replace("]", "").replace( "'", "").replace(",", "")) # to confirm Selected Packages screen = SnackScreen() bb = ButtonBar(screen, (("Next", "next"), ("Cancel", "cancel"))) tb = Textbox( 80, 10, "the packages selected to install are \n \n" + str(sellist.split(" ")), 1, 1) g = GridForm(screen, "Selected Packages", 1, 4) g.add(tb, 0, 2) g.add(bb, 0, 3, growx=1) result = g.runOnce() screen.finish() return bb.buttonPressed(result)
def ConfirmationWindow(screen, title, infolist, width=40, buttons=['Start', 'Modify', 'Save', 'Exit'], help=None): from snack import ButtonBar, Label, GridFormHelp, Textbox bb = ButtonBar(screen, buttons) ig = Grid(2, len(infolist)) i = 0 for _info in infolist: ig.setField(Label("%s: " % _info.getName()), 0, i, padding=(0, 0, 1, 0), anchorLeft=1) ig.setField(Label("%s" % _info.getValue()), 1, i, padding=(0, 0, 1, 0), anchorLeft=1) i = i + 1 g = GridFormHelp(screen, title, help, 1, 3) g.add(Textbox(20, 1, "Current settings:"), 0, 0, padding=(0, 0, 0, 1), anchorLeft=1) g.add(ig, 0, 1, padding=(0, 0, 0, 1)) g.add(bb, 0, 2, growx=1) result = g.runOnce() return (bb.buttonPressed(result))
class Plugin(PluginBase): """Plugin for oVirt Engine configuration. """ def __init__(self, ncs): PluginBase.__init__(self, "oVirt Engine", ncs) def form(self): elements = Grid(2, 8) is_network_up = network_up() if is_network_up: header_message = "oVirt Engine Configuration" else: header_message = "Network Down, oVirt Engine Configuration Disabled" heading = Label(header_message) self.ncs.screen.setColor(customColorset(1), "black", "magenta") heading.setColors(customColorset(1)) elements.setField(heading, 0, 0, anchorLeft = 1) rhevm_grid = Grid(2,2) rhevm_grid.setField(Label("Management Server:"), 0, 0, anchorLeft = 1) self.rhevm_server = Entry(25, "") self.rhevm_server.setCallback(self.valid_rhevm_server_callback) rhevm_grid.setField(Label("Management Server Port:"), 0, 1, anchorLeft = 1) self.rhevm_server_port = Entry(6, "", scroll = 0) self.rhevm_server_port.setCallback(self.valid_rhevm_server_port_callback) rhevm_grid.setField(self.rhevm_server, 1, 0, anchorLeft = 1, padding=(2, 0, 0, 1)) rhevm_grid.setField(self.rhevm_server_port, 1, 1, anchorLeft = 1, padding=(2, 0, 0, 1)) elements.setField(rhevm_grid, 0, 1, anchorLeft = 1, padding = (0,0,0,0)) elements.setField(Label(""), 0, 2, anchorLeft = 1) self.verify_rhevm_cert = Checkbox("Connect to oVirt Engine and Validate Certificate", isOn=True) elements.setField(self.verify_rhevm_cert, 0, 3, anchorLeft = 1, padding = (0,0,0,0)) elements.setField(Label(""), 0, 4, anchorLeft = 1) elements.setField(Label("Set oVirt Engine Admin Password"), 0, 5, anchorLeft = 1) pw_elements = Grid(3,3) pw_elements.setField(Label("Password: "******"Confirm Password: "******"", wrap=1) elements.setField(pw_elements, 0, 6, anchorLeft=1) elements.setField(self.pw_msg, 0, 7, padding = (0,0,0,0)) inputFields = [self.rhevm_server, self.rhevm_server_port, self.verify_rhevm_cert, self.root_password_1, self.root_password_2] if not is_network_up: for field in inputFields: field.setFlags(FLAG_DISABLED, FLAGS_SET) try: rhevm_server = get_rhevm_config() rhevm_server,rhevm_port = rhevm_server.split(":") if rhevm_server.startswith("None"): self.rhevm_server.set("") else: self.rhevm_server.set(rhevm_server) self.rhevm_server_port.set(rhevm_port) except: pass return [Label(""), elements] def password_check_callback(self): resp, msg = password_check(self.root_password_1.value(), self.root_password_2.value()) self.pw_msg.setText(msg) return def action(self): self.ncs.screen.setColor("BUTTON", "black", "red") self.ncs.screen.setColor("ACTBUTTON", "blue", "white") if self.root_password_1.value() != "" and self.root_password_2.value() != "" and self.root_password_1.value() == self.root_password_2.value(): set_password(self.root_password_1.value(), "root") augtool("set", "/files/etc/ssh/sshd_config/PasswordAuthentication", "yes") dn = file('/dev/null', 'w+') subprocess.Popen(['/sbin/service', 'sshd', 'restart'], stdout=dn, stderr=dn) if len(self.rhevm_server.value()) > 0: deployUtil.nodeCleanup() if self.verify_rhevm_cert.selected(): if deployUtil.getRhevmCert(self.rhevm_server.value(), self.rhevm_server_port.value()): path, dontCare = deployUtil.certPaths('') fp = deployUtil.generateFingerPrint(path) approval = ButtonChoiceWindow(self.ncs.screen, "Certificate Fingerprint:", fp, buttons = ['Approve', 'Reject']) if 'reject' == approval: ButtonChoiceWindow(self.ncs.screen, "Fingerprint rejected", "oVirt Engine Configuration Failed", buttons = ['Ok']) return False else: ovirt_store_config(path) self.ncs.reset_screen_colors() else: ButtonChoiceWindow(self.ncs.screen, "oVirt Engine Configuration", "Failed downloading oVirt Engine certificate", buttons = ['Ok']) self.ncs.reset_screen_colors() # Stopping vdsm-reg may fail but its ok - its in the case when the menus are run after installation deployUtil._logExec([constants.EXT_SERVICE, 'vdsm-reg', 'stop']) if write_vdsm_config(self.rhevm_server.value(), self.rhevm_server_port.value()): deployUtil._logExec([constants.EXT_SERVICE, 'vdsm-reg', 'start']) ButtonChoiceWindow(self.ncs.screen, "oVirt Engine Configuration", "oVirt Engine Configuration Successfully Updated", buttons = ['Ok']) self.ncs.reset_screen_colors() return True else: ButtonChoiceWindow(self.ncs.screen, "oVirt Engine Configuration", "oVirt Engine Configuration Failed", buttons = ['Ok']) self.ncs.reset_screen_colors() return False def valid_rhevm_server_callback(self): if not is_valid_host_or_ip(self.rhevm_server.value()): self.ncs.screen.setColor("BUTTON", "black", "red") self.ncs.screen.setColor("ACTBUTTON", "blue", "white") ButtonChoiceWindow(self.ncs.screen, "Configuration Check", "Invalid oVirt Engine Hostname or Address", buttons = ['Ok']) self.ncs.reset_screen_colors() def valid_rhevm_server_port_callback(self): if not is_valid_port(self.rhevm_server_port.value()): self.ncs.screen.setColor("BUTTON", "black", "red") self.ncs.screen.setColor("ACTBUTTON", "blue", "white") ButtonChoiceWindow(self.ncs.screen, "Configuration Check", "Invalid oVirt Engine Server Port", buttons = ['Ok']) self.ncs.reset_screen_colors()
def process(): global NvLtDrvURL, LatestFile, LatestHeader, DownloadFlag, SymlinkFlag screen = SnackScreen() bb = ButtonBar(screen, (("End", "end"), )) tbTittle = Textbox(65, 3, "Processing Input... ", 0, 1) tbDownload = Textbox(65, 3, " ", 0, 1) tbSymlink = Textbox(65, 3, " ", 0, 1) g = GridForm(screen, "chkltdr (NvDrIn) - by Trodskovich", 1, 6) g.add(tbTittle, 0, 2) g.add(tbDownload, 0, 3, growx=1) g.add(tbSymlink, 0, 4, growx=1) g.add(bb, 0, 5, growx=1) if DownloadFlag: tbDownload.setText("Downloading Please Wait...") result = g.runOnce() screen.finish() urllib.request.urlretrieve(NvLtDrvURL, "./" + LatestFile) else: tbDownload.setText("Download Skipped") if SymlinkFlag: subprocess.call( ["ln -nfs ./" + LatestFile + " NVIDIA-Linux-x86_64-Latest.run"], shell=True) tbSymlink.setText("Symlink Created") else: tbSymlink.setText("Symlink Skipped") result = g.runOnce() screen.finish() return bb.buttonPressed(result)
class UpdateManagerText(object): DEBUG = False def __init__(self, datadir): self.screen = SnackScreen() # FIXME: self.screen.finish() clears the screen (and all messages) # there too #atexit.register(self.restoreScreen) self.button_bar = ButtonBar(self.screen, ( (_("Cancel"), "cancel"), (_("Install"), "ok")), compact = True) self.textview_changes = Textbox(72, 8, "Changelog", True, True) self.checkbox_tree_updates = CheckboxTree(height=8, width=72, scroll=1) self.checkbox_tree_updates.setCallback(self.checkbox_changed) self.layout = GridForm(self.screen, "Updates", 1, 5) self.layout.add(self.checkbox_tree_updates, 0, 0) # empty line to make it look less crowded self.layout.add(Textbox(60, 1," ",False, False), 0, 1) self.layout.add(self.textview_changes, 0, 2) # empty line to make it look less crowded self.layout.add(Textbox(60, 1," ",False, False), 0, 3) self.layout.add(self.button_bar, 0, 4) # FIXME: better progress than the current suspend/resume screen thing self.screen.suspend() if not self.DEBUG: apt_pkg.PkgSystemLock() self.openCache() print _("Building Updates List") self.fillstore() if self.list.distUpgradeWouldDelete > 0: print _(""" A normal upgrade can not be calculated, please run: sudo apt-get dist-upgrade This can be caused by: * A previous upgrade which didn't complete * Problems with some of the installed software * Unofficial software packages not provided by Ubuntu * Normal changes of a pre-release version of Ubuntu""") sys.exit(1) self.screen.resume() # def restoreScreen(self): # self.screen.finish() def openCache(self): # open cache progress = apt.progress.OpTextProgress() if hasattr(self, "cache"): self.cache.open(progress) self.cache._initDepCache() else: self.cache = MyCache(progress) self.actiongroup = apt_pkg.GetPkgActionGroup(self.cache._depcache) # lock the cache self.cache.lock = True def fillstore(self): # populate the list self.list = UpdateList(self) self.list.update(self.cache) origin_list = self.list.pkgs.keys() origin_list.sort(lambda x,y: cmp(x.importance, y.importance)) origin_list.reverse() for (i, origin) in enumerate(origin_list): self.checkbox_tree_updates.append(origin.description, selected=True) for pkg in self.list.pkgs[origin]: self.checkbox_tree_updates.addItem(pkg.name, (i, snackArgs['append']), pkg, selected = True) def updateSelectionStates(self): """ helper that goes over the cache and updates the selection states in the UI based on the cache """ for pkg in self.cache: if not self.checkbox_tree_updates.item2key.has_key(pkg): continue # update based on the status if pkg.markedUpgrade or pkg.markedInstall: self.checkbox_tree_updates.setEntryValue(pkg, True) else: self.checkbox_tree_updates.setEntryValue(pkg, False) self.updateUI() def updateUI(self): self.layout.draw() self.screen.refresh() def get_news_and_changelog(self, pkg): changes = "" name = pkg.name # if we don't have it, get it if (not self.cache.all_changes.has_key(name) and not self.cache.all_news.has_key(name)): self.textview_changes.setText(_("Downloading changelog")) lock = thread.allocate_lock() lock.acquire() thread.start_new_thread(self.cache.get_news_and_changelog,(name,lock)) # this lock should never take more than 2s even with network down while lock.locked(): time.sleep(0.03) # build changes from NEWS and changelog if self.cache.all_news.has_key(name): changes += self.cache.all_news[name] if self.cache.all_changes.has_key(name): changes += self.cache.all_changes[name] return changes def checkbox_changed(self): # item is either a apt.package.Package or a str (for the headers) pkg = self.checkbox_tree_updates.getCurrent() descr = "" if hasattr(pkg, "name"): need_refresh = False name = pkg.name if self.options.show_description: descr = pkg.description else: descr = self.get_news_and_changelog(pkg) # check if it is a wanted package selected = self.checkbox_tree_updates.getEntryValue(pkg)[1] marked_install_upgrade = pkg.markedInstall or pkg.markedUpgrade if not selected and marked_install_upgrade: need_refresh = True pkg.markKeep() if selected and not marked_install_upgrade: if not (name in self.list.held_back): # FIXME: properly deal with "fromUser" here need_refresh = True pkg.markInstall() # fixup any problems if self.cache._depcache.BrokenCount: need_refresh = True Fix = apt_pkg.GetPkgProblemResolver(self.cache._depcache) Fix.ResolveByKeep() # update the list UI to reflect the cache state if need_refresh: self.updateSelectionStates() self.textview_changes.setText(descr) self.updateUI() def main(self, options): self.options = options res = self.layout.runOnce() self.screen.finish() button = self.button_bar.buttonPressed(res) if button == "ok": self.screen.suspend() res = self.cache.commit(apt.progress.text.AcquireProgress(), apt.progress.base.InstallProgress())
class NewtUI(object): """ Newt UI implementation """ def __init__(self, frontend): self._frontend = frontend self.screen = SnackScreen() self.textview_changes = None self.button_bar = None self.checkbox_tree_updates = None self.layout = None self._app = None self._updates_received = False def create_ui(self): """ Creates/Draws the UI """ self.button_bar = ButtonBar(self.screen, ((_("Cancel"), "cancel"), (_("Install"), "ok")), compact=True) self.textview_changes = Textbox(72, 8, "Changelog", True, True) self.checkbox_tree_updates = CheckboxTree(height=8, width=72, scroll=1) self.checkbox_tree_updates.setCallback(self.checkbox_changed) self.layout = GridForm(self.screen, "Updates", 1, 5) self.layout.add(self.checkbox_tree_updates, 0, 0) # empty line to make it look less crowded self.layout.add(Textbox(60, 1, " ", False, False), 0, 1) self.layout.add(self.textview_changes, 0, 2) # empty line to make it look less crowded self.layout.add(Textbox(60, 1, " ", False, False), 0, 3) self.layout.add(self.button_bar, 0, 4) # FIXME: better progress than the current suspend/resume screen thing self.screen.suspend() def cache_reload_callback(self, percent, operation): """ Cache reloading callback :param percent: Percentage done :param operation: Current operation """ if percent == RELOAD_CACHE_STATUS.DONE: sys.stdout.write(_('Finished loading package cache.') + '\n') elif percent == RELOAD_CACHE_STATUS.BEGIN: sys.stdout.write(_('Loading package cache.') + '\n') else: sys.stdout.write('[%2d] %s\r' % (percent, operation)) def main(self, application): """ UI main loop :param application: class:`UpdateManager.Application.Application` object """ self._app = application while not self._updates_received: time.sleep(0.3) self.screen.resume() res = self.layout.runOnce() self.screen.finish() button = self.button_bar.buttonPressed(res) if button == "ok": self.screen.suspend() def get_updates(self): sys.stdout.write(_("Building Updates List") + "\n") sys.stdout.flush() packages = self._app.get_available_updates() # download_size = 0 categories = {} for pkg in packages: catid = pkg.get_update_category() if not catid in categories.keys(): categories[catid] = [ pkg, ] else: categories[catid].append(pkg) for (i, cat_id) in enumerate(categories.keys()): cat_name = self._app.get_update_category_name(cat_id) self.checkbox_tree_updates.append(cat_name, selected=True) for pkg in categories[cat_id]: self.checkbox_tree_updates.addItem(pkg.get_package_name(), (i, snackArgs['append']), pkg, selected=True) self._updates_received = True def update_ui(self): """ Redraws the UI """ self.layout.draw() self.screen.refresh() def checkbox_changed(self): """ Handler for checkbox state-changes """ pkg = self.checkbox_tree_updates.getCurrent() descr = "" if hasattr(pkg, "get_description"): descr = pkg.get_description() # TODO: changelog handling/selection of changelog instead of # description self.textview_changes.setText(descr) self.update_ui()
def welcome(): global NvLtDrvURL, LatestFile, LatestHeader, DownloadFlag, SymlinkFlag screen = SnackScreen() bb = ButtonBar(screen, (("Continue", "continue"), ("Cancel", "cancel"))) tbTittle = Textbox( 65, 3, "To check for latest Nvidia Driver form NVIDIA Website, download and optionaly create a symlink to the latest File", 0, 1) for File in os.listdir(path): if File.find('.run') > 0 and os.path.isfile(path + "/" + File): FList.append(File) FList.sort() FileText = urllib.request.urlopen(NvLtTxtURL).read().decode('utf-8') for i in range(0, len(FileText)): if FileText[i] == ' ': LatestHeader = FileText[0:i] for i in range(0, len(FileText)): if FileText[i] == '/': LatestFile = FileText[i + 1:len(FileText) - 1] NvLtDrvURL = NvLtDrvURL + LatestHeader + "/" + LatestFile tbLatestL = Textbox(110, 2, "Latest Local Version: " + FList[-1], 0, 1) tbLatestR = Textbox( 110, 4, "Latest Remote Version: " + LatestFile + "\nLatest Driver URL: " + NvLtDrvURL, 0, 1) if LatestFile > FList[-1]: cbDowload = Checkbox( "Download the Latest Driver", 1, ) cbSymlink = Checkbox( "Create / Update Symlink", 1, ) else: cbDowload = Checkbox( "Download the Latest Driver", 0, ) cbSymlink = Checkbox( "Create / Update Symlink", 0, ) g = GridForm(screen, "chkltdr (NvDrIn) - by Trodskovich", 1, 8) g.add(tbTittle, 0, 2) g.add(tbLatestL, 0, 3, growx=1) g.add(tbLatestR, 0, 4, growx=1) g.add(cbDowload, 0, 5, growx=1) g.add(cbSymlink, 0, 6, growx=1) g.add(bb, 0, 7, growx=1) result = g.runOnce() screen.finish() DownloadFlag = cbDowload.value() SymlinkFlag = cbSymlink.value() return bb.buttonPressed(result)
def display(self): button_save, button_exit = Button("Update"), Button("Back") separator = (Textbox(20, 1, "", 0, 0), Textbox(20, 1, "", 0, 0)) rows = [(Textbox(20, 1, "Memory size (GB):", 0, 0), self.memory), separator, (Textbox(20, 1, "Swap size (GB):", 0, 0), self.swap), separator, (Textbox(20, 1, "Nr. of CPUs:", 0, 0), self.vcpu), separator, (Textbox(20, 1, "CPU usage limit (%):", 0, 0), self.vcpulimit), separator, (Textbox(20, 1, "Disk size (GB):", 0, 0), self.disk), separator, (Textbox(20, 1, "IO Priority:", 0, 0), self.ioprio), separator, (Textbox(20, 1, "Bind mounts:", 0, 0), self.bind_mounts), (Textbox(20, 1, "", 0, 0), Textbox(20, 1, "/src1,/dst1;/srcN,..", 0, 0)), separator, (Textbox(20, 1, "Hostname:", 0, 0), self.hostname), separator, (Textbox(20, 1, "", 0, 0), self.onboot), separator, (Textbox(20, 1, "Boot order:", 0, 0), self.bootorder), separator, (Textbox(20, 1, "VEID:", 0, 0), self.ctid), separator, (button_exit, button_save)] form = GridForm(self.screen, self.title, 2, len(rows)) for i, row in enumerate(rows): for j, cell in enumerate(row): form.add(cell, j, i) return form.runOnce() != button_exit
class Plugin(PluginBase): """Plugin for RHEV-M configuration. """ def __init__(self, ncs): PluginBase.__init__(self, "RHEV-M", ncs) def form(self): elements = Grid(2, 8) is_network_up = network_up() if is_network_up: header_message = "RHEV-M Configuration" else: header_message = "Network Down, RHEV-M Configuration Disabled" heading = Label(header_message) self.ncs.screen.setColor(customColorset(1), "black", "magenta") heading.setColors(customColorset(1)) elements.setField(heading, 0, 0, anchorLeft=1) rhevm_grid = Grid(2, 2) rhevm_grid.setField(Label("Management Server:"), 0, 0, anchorLeft=1) self.rhevm_server = Entry(25, "") self.rhevm_server.setCallback(self.valid_rhevm_server_callback) rhevm_grid.setField(Label("Management Server Port:"), 0, 1, anchorLeft=1) self.rhevm_server_port = Entry(6, "", scroll=0) self.rhevm_server_port.setCallback( self.valid_rhevm_server_port_callback) rhevm_grid.setField(self.rhevm_server, 1, 0, anchorLeft=1, padding=(2, 0, 0, 1)) rhevm_grid.setField(self.rhevm_server_port, 1, 1, anchorLeft=1, padding=(2, 0, 0, 1)) elements.setField(rhevm_grid, 0, 1, anchorLeft=1, padding=(0, 0, 0, 0)) elements.setField(Label(""), 0, 2, anchorLeft=1) self.verify_rhevm_cert = Checkbox( "Connect to RHEV Manager and Validate Certificate", isOn=True) elements.setField(self.verify_rhevm_cert, 0, 3, anchorLeft=1, padding=(0, 0, 0, 0)) elements.setField(Label(""), 0, 4, anchorLeft=1) elements.setField(Label("Set RHEV-M Admin Password"), 0, 5, anchorLeft=1) pw_elements = Grid(3, 3) pw_elements.setField(Label("Password: "******"Confirm Password: "******"", wrap=1) elements.setField(pw_elements, 0, 6, anchorLeft=1) elements.setField(self.pw_msg, 0, 7, padding=(0, 0, 0, 0)) inputFields = [ self.rhevm_server, self.rhevm_server_port, self.verify_rhevm_cert, self.root_password_1, self.root_password_2 ] if not is_network_up: for field in inputFields: field.setFlags(FLAG_DISABLED, FLAGS_SET) try: rhevm_server = get_rhevm_config() rhevm_server, rhevm_port = rhevm_server.split(":") if rhevm_server.startswith("None"): self.rhevm_server.set("") else: self.rhevm_server.set(rhevm_server) self.rhevm_server_port.set(rhevm_port) except: pass return [Label(""), elements] def password_check_callback(self): resp, msg = password_check(self.root_password_1.value(), self.root_password_2.value()) self.pw_msg.setText(msg) return def action(self): self.ncs.screen.setColor("BUTTON", "black", "red") self.ncs.screen.setColor("ACTBUTTON", "blue", "white") if self.root_password_1.value() != "" and self.root_password_2.value( ) != "" and self.root_password_1.value() == self.root_password_2.value( ): set_password(self.root_password_1.value(), "root") augtool("set", "/files/etc/ssh/sshd_config/PasswordAuthentication", "yes") dn = file('/dev/null', 'w+') subprocess.Popen(['/sbin/service', 'sshd', 'restart'], stdout=dn, stderr=dn) if len(self.rhevm_server.value()) > 0: deployUtil.nodeCleanup() if self.verify_rhevm_cert.selected(): if deployUtil.getRhevmCert(self.rhevm_server.value(), self.rhevm_server_port.value()): path, dontCare = deployUtil.certPaths('') fp = deployUtil.generateFingerPrint(path) approval = ButtonChoiceWindow( self.ncs.screen, "Certificate Fingerprint:", fp, buttons=['Approve', 'Reject']) if 'reject' == approval: ButtonChoiceWindow(self.ncs.screen, "Fingerprint rejected", "RHEV-M Configuration Failed", buttons=['Ok']) return False else: ovirt_store_config(path) self.ncs.reset_screen_colors() else: ButtonChoiceWindow(self.ncs.screen, "RHEV-M Configuration", "Failed downloading RHEV-M certificate", buttons=['Ok']) self.ncs.reset_screen_colors() # Stopping vdsm-reg may fail but its ok - its in the case when the menus are run after installation deployUtil._logExec([constants.EXT_SERVICE, 'vdsm-reg', 'stop']) if write_vdsm_config(self.rhevm_server.value(), self.rhevm_server_port.value()): deployUtil._logExec( [constants.EXT_SERVICE, 'vdsm-reg', 'start']) ButtonChoiceWindow(self.ncs.screen, "RHEV-M Configuration", "RHEV-M Configuration Successfully Updated", buttons=['Ok']) self.ncs.reset_screen_colors() return True else: ButtonChoiceWindow(self.ncs.screen, "RHEV-M Configuration", "RHEV-M Configuration Failed", buttons=['Ok']) self.ncs.reset_screen_colors() return False def valid_rhevm_server_callback(self): if not is_valid_host_or_ip(self.rhevm_server.value()): self.ncs.screen.setColor("BUTTON", "black", "red") self.ncs.screen.setColor("ACTBUTTON", "blue", "white") ButtonChoiceWindow(self.ncs.screen, "Configuration Check", "Invalid RHEV-M Hostname or Address", buttons=['Ok']) self.ncs.reset_screen_colors() def valid_rhevm_server_port_callback(self): if not is_valid_port(self.rhevm_server_port.value()): self.ncs.screen.setColor("BUTTON", "black", "red") self.ncs.screen.setColor("ACTBUTTON", "blue", "white") ButtonChoiceWindow(self.ncs.screen, "Configuration Check", "Invalid RHEV-M Server Port", buttons=['Ok']) self.ncs.reset_screen_colors()
def display(self): button_exit, button_save = Button("Back"), Button("Create VM") separator = (Textbox(20, 1, "", 0, 0), Textbox(20, 1, "", 0, 0)) rows = [ (Textbox(20, 1, "Memory size (GB):", 0, 0), self.memory), (Textbox(20, 1, "Memory min/max:", 0, 0), Textbox( 20, 1, "%s / %s" % (self.memory.min_value, self.memory.max_value), 0, 0)), (Textbox(20, 1, "VSwap size (GB):", 0, 0), self.swap), (Textbox(20, 1, "VSwap min/max:", 0, 0), Textbox(20, 1, "%s / %s" % (self.swap.min_value, self.swap.max_value), 0, 0)), (Textbox(20, 1, "Number of CPUs:", 0, 0), self.vcpu), (Textbox(20, 1, "CPU number min/max:", 0, 0), Textbox(20, 1, "%s / %s" % (self.vcpu.min_value, self.vcpu.max_value), 0, 0)), (Textbox(20, 1, "CPU usage limit (%):", 0, 0), self.vcpulimit), (Textbox(20, 1, "CPU usage min/max:", 0, 0), Textbox( 20, 1, "%s / %s" % (self.vcpulimit.min_value, self.vcpulimit.max_value), 0, 0)), (Textbox(20, 1, "Disk size (GB):", 0, 0), self.disk), (Textbox(20, 1, "Disk size min/max:", 0, 0), Textbox(20, 1, "%s / %s" % (self.disk.min_value, self.disk.max_value), 0, 0)), (Textbox(20, 1, "IO Priority:", 0, 0), self.ioprio), (Textbox(20, 1, "Bind mounts:", 0, 0), self.bind_mounts), (Textbox(20, 1, "", 0, 0), Textbox(20, 1, "/src1,/dst1;/srcN,..", 0, 0)), (Textbox(20, 1, "Hostname:", 0, 0), self.hostname), (Textbox(20, 1, "IP-address:", 0, 0), self.ip_address), (Textbox(20, 2, "Nameserver:", 0, 0), self.nameserver), (Textbox(20, 1, "Root password:"******"Root password x2:", 0, 0), self.password2), (Textbox(20, 2, "OS Template:", 0, 0), self.ostemplate), (self.startvm, self.onboot), separator, (button_save, button_exit) ] form = GridForm(self.screen, self.title, 2, len(rows)) for i, row in enumerate(rows): for j, cell in enumerate(row): form.add(cell, j, i) return form.runOnce() != button_exit
def form(self): elements = Grid(2, 8) is_network_up = network_up() if is_network_up: header_message = "RHEV-M Configuration" else: header_message = "Network Down, RHEV-M Configuration Disabled" heading = Label(header_message) self.ncs.screen.setColor(customColorset(1), "black", "magenta") heading.setColors(customColorset(1)) elements.setField(heading, 0, 0, anchorLeft=1) rhevm_grid = Grid(2, 2) rhevm_grid.setField(Label("Management Server:"), 0, 0, anchorLeft=1) self.rhevm_server = Entry(25, "") self.rhevm_server.setCallback(self.valid_rhevm_server_callback) rhevm_grid.setField(Label("Management Server Port:"), 0, 1, anchorLeft=1) self.rhevm_server_port = Entry(6, "", scroll=0) self.rhevm_server_port.setCallback( self.valid_rhevm_server_port_callback) rhevm_grid.setField(self.rhevm_server, 1, 0, anchorLeft=1, padding=(2, 0, 0, 1)) rhevm_grid.setField(self.rhevm_server_port, 1, 1, anchorLeft=1, padding=(2, 0, 0, 1)) elements.setField(rhevm_grid, 0, 1, anchorLeft=1, padding=(0, 0, 0, 0)) elements.setField(Label(""), 0, 2, anchorLeft=1) self.verify_rhevm_cert = Checkbox( "Connect to RHEV Manager and Validate Certificate", isOn=True) elements.setField(self.verify_rhevm_cert, 0, 3, anchorLeft=1, padding=(0, 0, 0, 0)) elements.setField(Label(""), 0, 4, anchorLeft=1) elements.setField(Label("Set RHEV-M Admin Password"), 0, 5, anchorLeft=1) pw_elements = Grid(3, 3) pw_elements.setField(Label("Password: "******"Confirm Password: "******"", wrap=1) elements.setField(pw_elements, 0, 6, anchorLeft=1) elements.setField(self.pw_msg, 0, 7, padding=(0, 0, 0, 0)) inputFields = [ self.rhevm_server, self.rhevm_server_port, self.verify_rhevm_cert, self.root_password_1, self.root_password_2 ] if not is_network_up: for field in inputFields: field.setFlags(FLAG_DISABLED, FLAGS_SET) try: rhevm_server = get_rhevm_config() rhevm_server, rhevm_port = rhevm_server.split(":") if rhevm_server.startswith("None"): self.rhevm_server.set("") else: self.rhevm_server.set(rhevm_server) self.rhevm_server_port.set(rhevm_port) except: pass return [Label(""), elements]
class UpdateManagerText(object): DEBUG = False def __init__(self, datadir): self.screen = SnackScreen() # FIXME: self.screen.finish() clears the screen (and all messages) # there too #atexit.register(self.restoreScreen) self.button_bar = ButtonBar(self.screen, ((_("Cancel"), "cancel"), (_("Install"), "ok")), compact=True) self.textview_changes = Textbox(72, 8, _("Changelog"), True, True) self.checkbox_tree_updates = CheckboxTree(height=8, width=72, scroll=1) self.checkbox_tree_updates.setCallback(self.checkbox_changed) self.layout = GridForm(self.screen, _("Updates"), 1, 5) self.layout.add(self.checkbox_tree_updates, 0, 0) # empty line to make it look less crowded self.layout.add(Textbox(60, 1, " ", False, False), 0, 1) self.layout.add(self.textview_changes, 0, 2) # empty line to make it look less crowded self.layout.add(Textbox(60, 1, " ", False, False), 0, 3) self.layout.add(self.button_bar, 0, 4) # FIXME: better progress than the current suspend/resume screen thing self.screen.suspend() if not self.DEBUG: apt_pkg.pkgsystem_lock() self.openCache() print(_("Building Updates List")) self.fillstore() if self.list.distUpgradeWouldDelete > 0: print( _(""" A normal upgrade can not be calculated, please run: sudo apt-get dist-upgrade This can be caused by: * A previous upgrade which didn't complete * Problems with some of the installed software * Unofficial software packages not provided by Ubuntu * Normal changes of a pre-release version of Ubuntu""")) sys.exit(1) self.screen.resume() # def restoreScreen(self): # self.screen.finish() def openCache(self): # open cache progress = apt.progress.text.OpProgress() if hasattr(self, "cache"): self.cache.open(progress) self.cache._initDepCache() else: self.cache = MyCache(progress) self.actiongroup = apt_pkg.ActionGroup(self.cache._depcache) # lock the cache self.cache.lock = True def fillstore(self): # populate the list self.list = UpdateList(self) self.list.update(self.cache) origin_list = sorted(self.list.pkgs, key=operator.attrgetter("importance"), reverse=True) for (i, origin) in enumerate(origin_list): self.checkbox_tree_updates.append(origin.description, selected=True) for pkg in self.list.pkgs[origin]: self.checkbox_tree_updates.addItem(pkg.name, (i, snackArgs['append']), pkg, selected=True) def updateSelectionStates(self): """ helper that goes over the cache and updates the selection states in the UI based on the cache """ for pkg in self.cache: if pkg not in self.checkbox_tree_updates.item2key: continue # update based on the status if pkg.marked_upgrade or pkg.marked_install: self.checkbox_tree_updates.setEntryValue(pkg, True) else: self.checkbox_tree_updates.setEntryValue(pkg, False) self.updateUI() def updateUI(self): self.layout.draw() self.screen.refresh() def get_news_and_changelog(self, pkg): changes = "" name = pkg.name # if we don't have it, get it if (name not in self.cache.all_changes and name not in self.cache.all_news): self.textview_changes.setText(_("Downloading changelog")) lock = threading.Lock() lock.acquire() changelog_thread = threading.Thread( target=self.cache.get_news_and_changelog, args=(name, lock)) changelog_thread.start() # this lock should never take more than 2s even with network down while lock.locked(): time.sleep(0.03) # build changes from NEWS and changelog if name in self.cache.all_news: changes += self.cache.all_news[name] if name in self.cache.all_changes: changes += self.cache.all_changes[name] return changes def checkbox_changed(self): # item is either a apt.package.Package or a str (for the headers) pkg = self.checkbox_tree_updates.getCurrent() descr = "" if hasattr(pkg, "name"): need_refresh = False name = pkg.name if self.options.show_description: descr = getattr(pkg.candidate, "description", None) else: descr = self.get_news_and_changelog(pkg) # check if it is a wanted package selected = self.checkbox_tree_updates.getEntryValue(pkg)[1] marked_install_upgrade = pkg.marked_install or pkg.marked_upgrade if not selected and marked_install_upgrade: need_refresh = True pkg.mark_keep() if selected and not marked_install_upgrade: if not (name in self.list.held_back): # FIXME: properly deal with "fromUser" here need_refresh = True pkg.mark_install() # fixup any problems if self.cache._depcache.broken_count: need_refresh = True Fix = apt_pkg.ProblemResolver(self.cache._depcache) Fix.resolve_by_keep() # update the list UI to reflect the cache state if need_refresh: self.updateSelectionStates() self.textview_changes.setText(descr) self.updateUI() def main(self, options): self.options = options res = self.layout.runOnce() self.screen.finish() button = self.button_bar.buttonPressed(res) if button == "ok": self.screen.suspend() res = self.cache.commit(apt.progress.text.AcquireProgress(), apt.progress.base.InstallProgress())