| 721 | |
| 722 | def getPrinterUserAndUserPQuota(self) : |
| 723 | """Returns a tuple (policy, printer, user, and user print quota) on this printer. |
| 724 | |
| 725 | "OK" is returned in the policy if both printer, user and user print quota |
| 726 | exist in the Quota Storage. |
| 727 | Otherwise, the policy as defined for this printer in pykota.conf is returned. |
| 728 | |
| 729 | If policy was set to "EXTERNAL" and one of printer, user, or user print quota |
| 730 | doesn't exist in the Quota Storage, then an external command is launched, as |
| 731 | defined in the external policy for this printer in pykota.conf |
| 732 | This external command can do anything, like automatically adding printers |
| 733 | or users, for example, and finally extracting printer, user and user print |
| 734 | quota from the Quota Storage is tried a second time. |
| 735 | |
| 736 | "EXTERNALERROR" is returned in case policy was "EXTERNAL" and an error status |
| 737 | was returned by the external command. |
| 738 | """ |
| 739 | for passnumber in range(1, 3) : |
| 740 | printer = self.storage.getPrinter(self.printername) |
| 741 | user = self.storage.getUser(self.username) |
| 742 | userpquota = self.storage.getUserPQuota(user, printer) |
| 743 | if printer.Exists and user.Exists and userpquota.Exists : |
| 744 | policy = "OK" |
| 745 | break |
| 746 | (policy, args) = self.config.getPrinterPolicy(self.printername) |
| 747 | if policy == "EXTERNAL" : |
| 748 | commandline = self.formatCommandLine(args, user, printer) |
| 749 | if not printer.Exists : |
| 750 | self.logger.log_message(_("Printer %s not registered in the PyKota system, applying external policy (%s) for printer %s") % (self.printername, commandline, self.printername), "info") |
| 751 | if not user.Exists : |
| 752 | self.logger.log_message(_("User %s not registered in the PyKota system, applying external policy (%s) for printer %s") % (self.username, commandline, self.printername), "info") |
| 753 | if not userpquota.Exists : |
| 754 | self.logger.log_message(_("User %s doesn't have quota on printer %s in the PyKota system, applying external policy (%s) for printer %s") % (self.username, self.printername, commandline, self.printername), "info") |
| 755 | if os.system(commandline) : |
| 756 | # if an error occured, we die without error, |
| 757 | # so that the job doesn't stop the print queue. |
| 758 | self.logger.log_message(_("External policy %s for printer %s produced an error. Job rejected. Please check PyKota's configuration files.") % (commandline, self.printername), "error") |
| 759 | policy = "EXTERNALERROR" |
| 760 | break |
| 761 | else : |
| 762 | break |
| 763 | return (policy, printer, user, userpquota) |
| 764 | |
| 765 | def main(self) : |
| 766 | """Main work is done here.""" |
| 767 | (policy, printer, user, userpquota) = self.getPrinterUserAndUserPQuota() |
| 768 | if policy == "EXTERNALERROR" : |
| 769 | # Policy was 'EXTERNAL' and the external command returned an error code |
| 770 | pass # TODO : reject job |
| 771 | elif policy == "EXTERNAL" : |
| 772 | # Policy was 'EXTERNAL' and the external command wasn't able |
| 773 | # to add either the printer, user or user print quota |
| 774 | pass # TODO : reject job |
| 775 | elif policy == "ALLOW": |
| 776 | # Either printer, user or user print quota doesn't exist, |
| 777 | # but the job should be allowed anyway. |
| 778 | pass # TODO : accept job |
| 779 | elif policy == "OK" : |
| 780 | # Both printer, user and user print quota exist, job should |
| 781 | # be allowed if current user is allowed to print on this |
| 782 | # printer |
| 783 | pass # TODO : decide what to do based on user quota. |
| 784 | else : # DENY |
| 785 | # Either printer, user or user print quota doesn't exist, |
| 786 | # and the job should be rejected. |
| 787 | pass # TODO : reject job |