84 | | out = os.popen("repykota") |
85 | | print out.read().strip() |
86 | | out.close() |
87 | | |
88 | | print footer |
| 96 | class PyKotaReportGUI(PyKotaTool) : |
| 97 | """PyKota Administrative GUI""" |
| 98 | def guiDisplay(self) : |
| 99 | """Displays the administrative interface.""" |
| 100 | global header, footer |
| 101 | print header |
| 102 | print self.body |
| 103 | print footer |
| 104 | |
| 105 | def error(self, message) : |
| 106 | """Adds an error message to the GUI's body.""" |
| 107 | if message : |
| 108 | self.body = '<p><font color="red">%s</font></p>\n%s' % (message, self.body) |
| 109 | |
| 110 | def htmlListPrinters(self, selected=[], mask="*") : |
| 111 | """Displays the printers multiple selection list.""" |
| 112 | printers = self.storage.getMatchingPrinters(mask) |
| 113 | selectednames = [p.Name for p in selected] |
| 114 | message = 'Printer : <select name="printers" multiple="multiple">' |
| 115 | for printer in printers : |
| 116 | if printer.Name in selectednames : |
| 117 | message += '<option value="%s" selected="selected">%s</option>' % (printer.Name, printer.Name) |
| 118 | else : |
| 119 | message += '<option value="%s">%s</option>' % (printer.Name, printer.Name) |
| 120 | message += '</select>' |
| 121 | return message |
| 122 | |
| 123 | def htmlUGNamesInput(self, value="*") : |
| 124 | """Input field for user/group names wildcard.""" |
| 125 | return 'User / Group names mask : <input type="text" name="ugmask" size="20" value="%s" /> <em>e.g. <strong>jo*</strong></em>' % (value or "*") |
| 126 | |
| 127 | def htmlGroupsCheckbox(self, isgroup=0) : |
| 128 | """Groups checkbox.""" |
| 129 | if isgroup : |
| 130 | return 'Groups report : <input type="checkbox" checked="checked" name="isgroup" />' |
| 131 | else : |
| 132 | return 'Groups report : <input type="checkbox" name="isgroup" />' |
| 133 | |
| 134 | def guiAction(self) : |
| 135 | """Main function""" |
| 136 | printers = ugmask = isgroup = None |
| 137 | self.body = "<p>Please click on the menu above</p>\n" |
| 138 | if self.form.has_key("action") : |
| 139 | action = self.form["action"].value |
| 140 | if action == "Report" : |
| 141 | if self.form.has_key("printers") : |
| 142 | printersfield = self.form["printers"] |
| 143 | if type(printersfield) != type([]) : |
| 144 | printersfield = [ printersfield ] |
| 145 | printers = [self.storage.getPrinter(p.value) for p in printersfield] |
| 146 | else : |
| 147 | printers = self.storage.getMatchingPrinters("*") |
| 148 | if self.form.has_key("ugmask") : |
| 149 | ugmask = self.form["ugmask"].value |
| 150 | else : |
| 151 | ugmask = "*" |
| 152 | if self.form.has_key("isgroup") : |
| 153 | isgroup = 1 |
| 154 | else : |
| 155 | isgroup = 0 |
| 156 | else : |
| 157 | self.error(body, "Invalid action [%s]" % action) |
| 158 | self.body += self.htmlListPrinters(printers or []) |
| 159 | self.body += "<br />" |
| 160 | self.body += self.htmlUGNamesInput(ugmask) |
| 161 | self.body += "<br />" |
| 162 | self.body += self.htmlGroupsCheckbox(isgroup) |
| 163 | if printers and ugmask : |
| 164 | self.reportingtool = openReporter(admin, "text", printers, [ ugmask ], isgroup) |
| 165 | self.body += "<pre>%s</pre>" % self.reportingtool.generateReport() |
| 166 | |
| 167 | if __name__ == "__main__" : |
| 168 | admin = PyKotaReportGUI() |
| 169 | admin.form = cgi.FieldStorage() |
| 170 | admin.guiAction() |
| 171 | admin.guiDisplay() |