130 | | pipe = os.popen("pkpgcounter %s" % " ".join([' "%s"' % f for f in files])) |
131 | | answer = pipe.readline().strip() |
132 | | status = pipe.close() |
133 | | try : |
134 | | if status is None : |
135 | | nbpages = int(answer) |
136 | | else : |
137 | | raise ValueError, "ERROR in pkpgcounter" |
138 | | except ValueError, msg : |
139 | | sys.stderr.write(_("Unable to compute size of %s in number of pages.\n") % files) |
140 | | sys.stderr.write("%s\n" % msg) |
141 | | else : |
142 | | # get current user |
143 | | uid = os.geteuid() |
144 | | username = pwd.getpwuid(uid)[0] |
145 | | user = self.storage.getUser(username) |
146 | | if user.Exists and user.LimitBy and (user.LimitBy.lower() == "balance"): |
147 | | print _("Your account balance : %.2f") % (user.AccountBalance or 0.0) |
148 | | |
149 | | printers = self.storage.getMatchingPrinters(options["printer"]) |
150 | | if not printers : |
151 | | raise PyKotaToolError, _("There's no printer matching %s") % options["printer"] |
152 | | |
153 | | print _("Job size : %i pages") % nbpages |
154 | | for printer in printers : |
155 | | userpquota = self.storage.getUserPQuota(user, printer) |
156 | | cost = userpquota.computeJobPrice(nbpages) |
157 | | print _("Cost on printer %s : %.2f") % (printer.Name, cost) |
| 136 | totalsize = 0 |
| 137 | for filename in files : |
| 138 | try : |
| 139 | parser = PDLAnalyzer(filename) |
| 140 | totalsize += parser.getJobSize() |
| 141 | except PDLAnalyzerError, msg : |
| 142 | sys.stderr.write("%s\n" % msg) |
| 143 | sys.stderr.flush() |
| 144 | |
| 145 | # get current user |
| 146 | uid = os.geteuid() |
| 147 | username = pwd.getpwuid(uid)[0] |
| 148 | user = self.storage.getUser(username) |
| 149 | if user.Exists and user.LimitBy and (user.LimitBy.lower() == "balance"): |
| 150 | print _("Your account balance : %.2f") % (user.AccountBalance or 0.0) |
| 151 | |
| 152 | printers = self.storage.getMatchingPrinters(options["printer"]) |
| 153 | if not printers : |
| 154 | raise PyKotaToolError, _("There's no printer matching %s") % options["printer"] |
| 155 | |
| 156 | print _("Job size : %i pages") % totalsize |
| 157 | for printer in printers : |
| 158 | userpquota = self.storage.getUserPQuota(user, printer) |
| 159 | cost = userpquota.computeJobPrice(totalsize) |
| 160 | print _("Cost on printer %s : %.2f") % (printer.Name, cost) |