107 | | def main(arguments, options) : |
108 | | """Edit user or group quotas.""" |
109 | | pass |
110 | | |
| 113 | class EdPyKota(PyKotaTool) : |
| 114 | """A class for edpykota.""" |
| 115 | def main(self, names, options) : |
| 116 | """Edit user or group quotas.""" |
| 117 | printernames = self.storage.getMatchingPrinters(options["printer"]) |
| 118 | if not printernames : |
| 119 | raise PyKotaToolError, "There's no printer matching %s" % options["printer"] |
| 120 | softlimit = hardlimit = None |
| 121 | if options["softlimit"] : |
| 122 | try : |
| 123 | softlimit = int(options["softlimit"].strip()) |
| 124 | except ValueError : |
| 125 | raise PyKotaToolError, "Invalid softlimit value %s." % options["softlimit"] |
| 126 | if options["hardlimit"] : |
| 127 | try : |
| 128 | hardlimit = int(options["hardlimit"].strip()) |
| 129 | except ValueError : |
| 130 | raise PyKotaToolError, "Invalid hardlimit value %s." % options["hardlimit"] |
| 131 | if hardlimit < softlimit : |
| 132 | # error, exchange them |
| 133 | self.logger.log_message("Hard limit %i is less than soft limit %i, values will be exchanged." % (hardlimit, softlimit), "warn") |
| 134 | (softlimit, hardlimit) = (hardlimit, softlimit) |
| 135 | for printer in printernames : |
| 136 | if options["prototype"] : |
| 137 | if options["users"] : |
| 138 | prototype = self.storage.getUserPQuota(options["prototype"], printer) |
| 139 | else : |
| 140 | prototype = self.storage.getGroupPQuota(options["prototype"], printer) |
| 141 | if prototype is None : |
| 142 | self.logger.message("Prototype %s not found in Quota Storage for printer %s." % (options["prototype"], printer)) |
| 143 | continue # skip this printer |
| 144 | else : |
| 145 | (softlimit, hardlimit) = (prototype["softlimit"], prototype["hardlimit"]) |
| 146 | if (hardlimit is None) or (softlimit is None) : |
| 147 | raise PyKotaToolError, "Both hard and soft limits must be set ! Aborting." |
| 148 | if hardlimit is None : |
| 149 | hardlimit = softlimit |
| 150 | self.logger.message("Undefined hard limit set to %i on printer %s." % (hardlimit, printer)) |
| 151 | if softlimit is None : |
| 152 | softlimit = hardlimit |
| 153 | self.logger.message("Undefined soft limit set to %i on printer %s." % (softlimit, printer)) |
| 154 | for name in names : |
| 155 | if options["users"] : |
| 156 | quota = self.storage.getUserPQuota(name, printer) |
| 157 | else : |
| 158 | quota = self.storage.getGroupPQuota(name, printer) |
| 159 | if quota is None : |
| 160 | # not found |
| 161 | if options["add"] : |
| 162 | if options["users"] : |
| 163 | self.storage.addUserPQuota(name, printer) |
| 164 | quota = self.storage.getUserPQuota(name, printer) |
| 165 | else : |
| 166 | self.storage.addGroupPQuota(name, printer) |
| 167 | quota = self.storage.getGroupPQuota(name, printer) |
| 168 | if quota is None : |
| 169 | self.logger.log_message("Quota not found for object %s on printer %s." % (name, printer)) |
| 170 | else : |
| 171 | if options["users"] : |
| 172 | self.storage.setUserPQuota(name, printer, softlimit, hardlimit) |
| 173 | else : |
| 174 | self.storage.setGroupPQuota(name, printer, softlimit, hardlimit) |
| 175 | |