def validateFields(self): if self.userNameEntry.value() == "": snack.ButtonChoiceWindow(self.screen, sstr(ERROR), sstr(USER_REQUIRED), buttons = [sstr(OK)]) self.g.setCurrent(self.userNameEntry) return 0 if self.passwordEntry.value() == "": snack.ButtonChoiceWindow(self.screen, sstr(ERROR), sstr(PASSWORD_REQUIRED), buttons = [sstr(OK)]) self.g.setCurrent(self.passwordEntry) return 0 try: self.tui.alreadyRegistered = rhnreg.reserveUser(self.userNameEntry.value(), self.passwordEntry.value()) except up2dateErrors.ValidationError: e = sys.exc_info()[1] snack.ButtonChoiceWindow(self.screen, sstr(_("Error")), sstr(_("The server indicated an error:\n")) + sstr(e.errmsg), buttons = [sstr(_("OK"))]) self.g.setCurrent(self.userNameEntry) return 0 except up2dateErrors.CommunicationError: e = sys.exc_info()[1] FatalErrorWindow(self.screen, _("There was an error communicating with the registration server:\n") + e.errmsg) return 1
def validateFields(self): if self.userNameEntry.value() == "": snack.ButtonChoiceWindow(self.screen, ERROR.encode('utf-8'), USER_REQUIRED.encode('utf-8'), buttons=[OK.encode('utf-8')]) self.g.setCurrent(self.userNameEntry) return 0 if self.passwordEntry.value() == "": snack.ButtonChoiceWindow(self.screen, ERROR.encode('utf-8'), PASSWORD_REQUIRED.encode('utf-8'), buttons=[OK.encode('utf-8')]) self.g.setCurrent(self.passwordEntry) return 0 try: self.tui.alreadyRegistered = rhnreg.reserveUser( self.userNameEntry.value(), self.passwordEntry.value()) except up2dateErrors.ValidationError, e: snack.ButtonChoiceWindow( self.screen, _("Error").encode('utf-8'), _("The server indicated an error:\n").encode('utf-8') + e.errmsg.encode('utf-8'), buttons=[_("OK").encode('utf-8')]) self.g.setCurrent(self.userNameEntry) return 0
def validateFields(self): msgbox = "ok" later_release = False if self.limited_updates_button.selected(): later_release = self.channelList.current() != \ self.available_channels['default_channel'] title = sstr(CONFIRM_OS_RELEASE_SELECTION) if later_release: msgbox = snack.ButtonChoiceWindow(self.screen, title, sstr(CONFIRM_OS_WARNING) % self.channelList.current(), buttons=[sstr(OK), sstr(CANCEL)]) return msgbox if self.all_updates_button.selected() or later_release: msgbox = snack.ButtonChoiceWindow(self.screen, title, sstr(CONFIRM_OS_ALL), buttons=[sstr(OK), sstr(CANCEL)]) return msgbox return msgbox
def validateFields(self): msgbox = "ok" later_release = False if self.limited_updates_button.selected(): later_release = self.channelList.current() != \ self.available_channels['default_channel'] title = CONFIRM_OS_RELEASE_SELECTION.encode('utf-8') if later_release: msgbox = snack.ButtonChoiceWindow( self.screen, title, CONFIRM_OS_WARNING.encode('utf-8') % self.channelList.current(), buttons=[OK.encode('utf-8'), CANCEL.encode('utf-8')]) return msgbox if self.all_updates_button.selected() or later_release: msgbox = snack.ButtonChoiceWindow( self.screen, title, CONFIRM_OS_ALL.encode('utf-8'), buttons=[OK.encode('utf-8'), CANCEL.encode('utf-8')]) return msgbox return msgbox if self.limited_updates_button.selected(): #TODO: warn return msgbox
def report_complete(report_saved): if report_saved: snack.ButtonChoiceWindow(tui.screen, "Report Saved", "Report saved successfully.", ['Ok']) else: snack.ButtonChoiceWindow(tui.screen, "Error", "Unable to save report.", ['Ok']) return uicontroller.RIGHT_FORWARDS
def validateFields(self): if self.urlEntry.value() == "": snack.ButtonChoiceWindow(self.screen, ERROR.encode('utf-8'), SATELLITE_REQUIRED.encode('utf-8'), buttons = [OK.encode('utf-8')]) self.g.setCurrent(self.urlEntry) return 0 if (self.urlEntry.value()[:5] == 'https' and self.sslEntry.value() == ""): snack.ButtonChoiceWindow(self.screen, ERROR.encode('utf-8'), SSL_REQUIRED.encode('utf-8'), buttons = [OK.encode('utf-8')]) self.g.setCurrent(self.sslEntry) return 0 return 1
def askuserIP(self, nodename): # # ask the user for an IP address # done = 0 while not done: entry = snack.Entry(15) rc, values = snack.EntryWindow( self.screen, _("IP Address Selection"), _("Enter the IP address for host %s") % (nodename), [(_("IP Address"), entry)], buttons=['Ok']) ipaddr = entry.value() try: nodeid = self.sql.getNodeId(ipaddr) if nodeid: msg = "Duplicate IP '%s' Specified" % ipaddr raise rocks.util.CommandError, msg self.setIPaddr(ipaddr) done = 1 except rocks.util.CommandError: snack.ButtonChoiceWindow(self.screen, _("Duplicate IP"), _("The IP address (%s) already exists.\n\n" \ % (ipaddr) + "Please select another."), buttons = [ _("OK") ]) return ipaddr
def validateFields(self): if self.urlEntry.value() == "": snack.ButtonChoiceWindow(self.screen, sstr(ERROR), sstr(SATELLITE_REQUIRED), buttons = [sstr(OK)]) self.g.setCurrent(self.urlEntry) return 0 if (self.urlEntry.value()[:5] == 'https' and self.sslEntry.value() == ""): snack.ButtonChoiceWindow(self.screen, sstr(ERROR), sstr(SSL_REQUIRED), buttons = [sstr(OK)]) self.g.setCurrent(self.sslEntry) return 0 return 1
def action_create(self): i = snack.EntryWindow(self.screen, self.task_type[0], "Please enter action Information", ["action_name ", "group_name"], buttons=['Ok', 'Back'], width=65, entryWidth=40) if i[0] != 'back': self.action = i action_name=self.action[1][0] group_name=self.action[1][1] zabbix=zabbix_api(False,False,output=False) info = zabbix.action_autoreg_create(action_name,group_name) info_dirt=eval(info) snack.ButtonChoiceWindow(self.screen, "%s" % self.task_type[0], "Info:\n\n" "%s: %s" % (info_dirt["status"],info_dirt["output"]), buttons=['Ok'], width=65) self.get_task() else: self.get_task()
def ConfirmQuitWindow(screen): button = snack.ButtonChoiceWindow(screen, sstr(CONFIRM_QUIT), sstr(CONFIRM_QUIT_SURE) + "\n" + \ sstr(WHY_REGISTER_SEC) + "\n" + \ sstr(WHY_REGISTER_SEC_TXT) + "\n\n" + \ sstr(WHY_REGISTER_DLD) + "\n" + \ sstr(WHY_REGISTER_DLD_TXT) + "\n\n" + \ sstr(WHY_REGISTER_SUPP) + "\n" + \ sstr(WHY_REGISTER_SUPP_TXT) + "\n\n" + \ sstr(WHY_REGISTER_COMP) + "\n" + \ sstr(WHY_REGISTER_COMP_TXT) + "\n\n" + \ sstr(CONFIRM_QUIT_WILLNOT) + "\n" + \ sstr(WHY_REGISTER_TIP), [sstr(CONTINUE_REGISTERING), sstr(REGISTER_LATER2)], width = 70) if button == sstr(REGISTER_LATER2).lower(): screen.finish() return 1 else: return 0
def ConfirmQuitWindow(screen): button = snack.ButtonChoiceWindow(screen, CONFIRM_QUIT.encode('utf-8'), CONFIRM_QUIT_SURE.encode('utf-8') + "\n" + \ WHY_REGISTER_SEC.encode('utf-8') + "\n" + \ WHY_REGISTER_SEC_TXT.encode('utf-8') + "\n\n" + \ WHY_REGISTER_DLD.encode('utf-8') + "\n" + \ WHY_REGISTER_DLD_TXT.encode('utf-8') + "\n\n" + \ WHY_REGISTER_SUPP.encode('utf-8') + "\n" + \ WHY_REGISTER_SUPP_TXT.encode('utf-8') + "\n\n" + \ WHY_REGISTER_COMP.encode('utf-8') + "\n" + \ WHY_REGISTER_COMP_TXT.encode('utf-8') + "\n\n" + \ CONFIRM_QUIT_WILLNOT.encode('utf-8') + "\n" + \ WHY_REGISTER_TIP.encode('utf-8'), [CONTINUE_REGISTERING.encode('utf-8'), REGISTER_LATER2.encode('utf-8')], width = 70) if button == string.lower(REGISTER_LATER2.encode('utf-8')): screen.finish() return 1 else: return 0
def askuserIP(self, nodename): # # ask the user for an IP address # done = 0 while not done: entry = snack.Entry(15) rc, values = snack.EntryWindow( self.screen, _("IP Address Selection"), _("Enter the IP address for host %s") % (nodename), [(_("IP Address"), entry)], buttons=['Ok']) ipaddr = entry.value() try: query = 'select id from networks where ' +\ 'ip="%s"' % ipaddr rows = self.sql.execute(query) if rows: raise ValueError, "Duplicate IP" self.setIPaddr(ipaddr) done = 1 except ValueError: msg = _("The IP address (%s) " % ipaddr +\ "already exists.\n" ) +\ _("Please select another.") snack.ButtonChoiceWindow(self.screen, _("Duplicate IP"), msg, buttons=[_("OK")]) return ipaddr
def run_selector(self): """ Compile and run the task selector. See: http://www.wanware.com/tsgdocs/snack.html for info on the python snack module. Also look at the code in snack.py to understand what it is doing. """ wdays_short = "M T W T F S S " extrahkeysdict = { '0': ' mod due:today', '1': ' mod due:1d', '2': ' mod due:2d', '3': ' mod due:3d', '4': ' mod due:4d', '5': ' mod due:5d', '6': ' mod due:6d', '7': ' mod due:7d', '8': ' mod due:1w', '9': ' mod due:2w', 'd': ' done', 'i': ' info', 'h': ' HELP' } for key in extrahkeysdict.keys(): snack.hotkeys[key] = ord(key) # Add to the snack hkey library snack.hotkeys[ord(key)] = key screen = snack.SnackScreen() buttonlist = [("1d", "1d", "F1"), ("2d", "2d", "F2"), ("3d", "3d", "F3"), ("1w", "1w", "F4"), ("2w", "2w", "F5")] mybuttonbar = snack.ButtonBar(screen, buttonlist, 1) lbox = snack.Listbox(height=20, width=90, returnExit=1, multiple=1, border=1, scroll=1) for task in self.tasks: # Step through list of task dictionary objects taskline, tdate = self.compile_taskline(task) lbox.append(taskline, task["id"]) grid = snack.GridForm(screen, wdays_short * self.weeks, 3, 3) # Note the padding option. It is set to shift the lbox content one # position to the right so as to allign with the dayheader at the top grid.add(lbox, 0, 0, padding=(1, 0, 0, 0)) grid.add(mybuttonbar, 0, 1, growx=1) grid.addHotKey('ESC') for key in extrahkeysdict.keys(): grid.addHotKey(key) result = grid.runOnce() # This is the key of the HotKey dict buttonpressed = mybuttonbar.buttonPressed(result) # The Hotkey dict \ # value of key in 'result'. Returns None if no hotkey or button \ # pressed selection = lbox.getSelection() # This is a list # The first set of if options deals with all the exceptions while \ # the last 'else' deals with actual task manupulations. if result == 'ESC': screen.finish() return (None, True) elif result == 'h': mytext = '' for mykey in sorted(extrahkeysdict): mytext = mytext + '\n' + mykey + ': ' + extrahkeysdict[mykey] snack.ButtonChoiceWindow(screen, 'Help', mytext, ['Ok']) screen.finish() return (None, False) elif result == 'i': basictaskstr = 'task ' + str(lbox.current()) + ' info' mytext = commands.getoutput(basictaskstr) snack.ButtonChoiceWindow(screen, 'Task information', mytext, \ ['Ok'],width=80) screen.finish() return (None, False) else: # Get the selected or current task/s from the listbox if len(selection) > 0: # Joins the selections into comma seperated list, and suppresses # confirmation for this number of tasks # basictaskstr = 'task ' + ','.join(map(repr, lbox.getSelection())) \ basictaskstr = 'task ' + ','.join(map(repr, selection)) \ + ' rc.bulk:' + str(len(selection) + 1) else: # If no selections have been made use the current task basictaskstr = 'task ' + str(lbox.current()) # Figure out what commands to add, if any given if buttonpressed: # TODO Change values in Buttonlist dict so that it provides the full command\ # so that it can be used in the same way as if any other hotkey was pressed basictaskstr = basictaskstr + ' mod due:' + buttonpressed elif result in extrahkeysdict: # If a hotkey not linked to button. basictaskstr = basictaskstr + extrahkeysdict[result] else: # Else type in the rest of the command. basictaskstr = basictaskstr + ' mod ' result2 = snack.EntryWindow(screen, "Command details...", \ "", [('Command to be executed:', basictaskstr)], width=50, \ entryWidth=30, buttons=[('OK', 'OK', 'F1'), ('Cancel', 'Cancel', 'ESC')]) # Look at the code for this function to understand this screen.finish() if result2[0] == 'Cancel': return (None, True) else: print '>' + result2[1][0] return (commands.getoutput(result2[1][0]), False)
def set_hosts(self, val=None): i = snack.ListboxChoiceWindow(self.screen, self.task_type[0], "Select Servers", [('Specific Servers', "hosts_ind"), ('All Linux Servers', 'hosts_all')], buttons=['Ok', 'Back'], width=65) if i[0] != 'back': self.task_hosts = i if i[1] == 'hosts_ind': if val: ind = snack.EntryWindow(self.screen, self.task_type[0], "Provide Hostnames: " "(ie: server1,server2,server3)", [("Hosts: ", val)], buttons=['Ok', 'Back'], width=65, entryWidth=40) else: ind = snack.EntryWindow(self.screen, self.task_type[0], "Provide Host Names\n" "ie: server1,server2,server3", ["Hosts: "], buttons=['Ok', 'Back'], width=65, entryWidth=40) if ind[0] != 'back' and len(ind[1][0].split(',')) >= 1: taskhosts = str() invalhosts = str() hostlist = ind[1][0].split(',') hostlist = list(set(hostlist)) hostlist.sort() for host in hostlist: if host in validhosts: taskhosts = taskhosts + (host + ',') else: invalhosts = invalhosts + (host + ',') taskhosts = taskhosts.rstrip(",") invalhosts = invalhosts.rstrip(",") if taskhosts == '': snack.ButtonChoiceWindow(self.screen, self.task_type[0], "No Valid Hostnames Provided", buttons=['Ok'], width=65) self.set_hosts() elif len(invalhosts) > 1: snack.ButtonChoiceWindow(self.screen, self.task_type[0], "Valid hostnames: %s\n" "\nInvalid hostnames: %s\n" "\nPlease re-verify hosts.." % (taskhosts, invalhosts), buttons=['Verify Hosts'], width=65) self.set_hosts(taskhosts) else: self.task_hostsind = ind else: self.set_hosts() else: self.get_task()
def ErrorWindow(screen, errmsg): snack.ButtonChoiceWindow(screen, sstr(ERROR), sstr(u"%s" % errmsg), [sstr(BACK)])
def WarningWindow(screen, errmsg): snack.ButtonChoiceWindow(screen, WARNING.encode('utf-8'), ("%s" % errmsg).encode('utf-8'), [OK.encode('utf-8')]) screen.finish()
def FatalErrorWindow(screen, errmsg): snack.ButtonChoiceWindow(screen, FATAL_ERROR.encode('utf-8'), (u"%s" % errmsg).encode('utf-8'), [OK.encode('utf-8')]) screen.finish() sys.exit(1)
def ErrorWindow(screen, errmsg): snack.ButtonChoiceWindow(screen, ERROR.encode('utf-8'), (u"%s" % errmsg).encode('utf-8'), [BACK.encode('utf-8')])
def FatalErrorWindow(screen, errmsg): snack.ButtonChoiceWindow(screen, sstr(FATAL_ERROR), sstr(u"%s" % errmsg), [sstr(OK)]) screen.finish() sys.exit(1)
def WarningWindow(screen, errmsg): snack.ButtonChoiceWindow(screen, sstr(WARNING), sstr("%s" % errmsg), [sstr(OK)]) screen.finish()
def MessageBox(self, title, text, buttons=BaseUI.MB_OK, width=30): buttons = self._NormalizeButtons(buttons) return snack.ButtonChoiceWindow(self.screen, title, text, buttons, width)