Changeset 3413 for pykota/trunk/bin/pykotme
- Timestamp:
- 09/27/08 22:02:37 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/pykotme
r3411 r3413 9 9 # the Free Software Foundation, either version 3 of the License, or 10 10 # (at your option) any later version. 11 # 11 # 12 12 # This program is distributed in the hope that it will be useful, 13 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 15 # GNU General Public License for more details. 16 # 16 # 17 17 # You should have received a copy of the GNU General Public License 18 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. … … 34 34 from pykota.tool import PyKotaTool 35 35 from pykota.accounter import openAccounter 36 37 class PyKotMe(PyKotaTool) : 36 37 class PyKotMe(PyKotaTool) : 38 38 """A class for pykotme.""" 39 39 def main(self, files, options) : … … 46 46 # TODO : over the second printer below. 47 47 files.append("-") 48 48 49 49 printers = self.storage.getMatchingPrinters(options.printer) 50 50 if not printers : 51 51 raise PyKotaCommandLineError, _("There's no printer matching %s") % options.printer 52 52 53 53 username = pwd.getpwuid(os.getuid())[0] 54 54 if options.user : 55 55 if not self.config.isAdmin : 56 56 self.printInfo(_("The --user command line option will be ignored because you are not a PyKota Administrator."), "warn") 57 else : 57 else : 58 58 username = options.user 59 59 60 60 user = self.storage.getUser(username) 61 61 if not user.Exists : 62 62 self.printInfo(_("There's no user matching '%(username)s'.") \ 63 63 % locals(), 64 "error") 65 else : 64 "error") 65 else : 66 66 if user.LimitBy and (user.LimitBy.lower() == "balance"): 67 67 self.display("%s\n" % (_("Your account balance : %.2f") % (user.AccountBalance or 0.0))) 68 68 69 69 sizeprinted = False 70 70 done = {} 71 71 for printer in printers : 72 # Now fake some values. TODO : improve API to not need this anymore 72 # Now fake some values. TODO : improve API to not need this anymore 73 73 printername = printer.Name 74 74 self.PrinterName = printer.Name … … 77 77 key = self.preaccounter.name + self.preaccounter.arguments 78 78 if not done.has_key(key) : 79 totalsize = 0 79 totalsize = 0 80 80 inkusage = [] 81 for filename in files : 81 for filename in files : 82 82 self.DataFile = filename 83 83 self.preaccounter.beginJob(None) … … 85 85 totalsize += self.preaccounter.getJobSize(None) 86 86 inkusage.extend(self.preaccounter.inkUsage) 87 done[key] = (totalsize, inkusage) 88 (totalsize, inkusage) = done[key] 89 if not sizeprinted : 87 done[key] = (totalsize, inkusage) 88 (totalsize, inkusage) = done[key] 89 if not sizeprinted : 90 90 self.display("%s\n" % (_("Job size : %i pages") % totalsize)) 91 91 sizeprinted = True … … 94 94 if printer.MaxJobSize and (totalsize > printer.MaxJobSize) : 95 95 self.display("%s\n" % (_("User %(username)s is not allowed to print so many pages on printer %(printername)s at this time.") % locals())) 96 else : 96 else : 97 97 cost = userpquota.computeJobPrice(totalsize, inkusage) 98 98 msg = _("Cost on printer %s : %.2f") % (printer.Name, cost) 99 99 if printer.PassThrough : 100 100 msg = "%s (%s)" % (msg, _("won't be charged, printer is in passthrough mode")) 101 elif user.LimitBy == "nochange" : 101 elif user.LimitBy == "nochange" : 102 102 msg = "%s (%s)" % (msg, _("won't be charged, account is immutable")) 103 103 self.display("%s\n" % msg) 104 104 if user.LimitBy == "noprint" : 105 105 self.display("%s\n" % (_("User %(username)s is forbidden to print at this time.") % locals())) 106 107 if __name__ == "__main__" : 106 107 if __name__ == "__main__" : 108 108 parser = PyKotaOptionParser(description=_("Generates print quotes for end users."), 109 109 usage="pykotme [options] [files]") … … 116 116 help=_("Acts on this user only. Only one username can be specified this way. The default value is the name of the user who launched this command. This option is ignored when the command is not launched by a PyKota Administrator.")) 117 117 118 parser.add_example("--printer apple file1.ps <file2.pclxl", 118 parser.add_example("--printer apple file1.ps <file2.pclxl", 119 119 _("This would show the number of pages needed to print these two files, as well as the cost of printing them to the 'apple' printer for the user who launched this command.")) 120 120 parser.add_example("--user john",