Changeset 3413 for pykota/trunk/bin/pykosd
- Timestamp:
- 09/27/08 22:02:37 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/pykosd
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/>. … … 31 31 try : 32 32 import pyosd 33 except ImportError : 33 except ImportError : 34 34 sys.stderr.write("Sorry ! You need both xosd and the Python OSD library (pyosd) for this software to work.\n") 35 35 sys.exit(-1) … … 53 53 if not user.Exists : 54 54 raise PyKotaCommandLineError, _("You %(username)s don't have a PyKota printing account. Please contact your administrator.") % locals() 55 if user.LimitBy == "quota" : 55 if user.LimitBy == "quota" : 56 56 printers = self.storage.getMatchingPrinters("*") 57 57 upquotas = [ self.storage.getUserPQuotaFromBackend(user, p) for p in printers ] # don't use cache 58 58 nblines = len(upquotas) 59 display = pyosd.osd(font=options.font, 60 colour=color, 61 timeout=options.duration, 62 shadow=2, 59 display = pyosd.osd(font=options.font, 60 colour=color, 61 timeout=options.duration, 62 shadow=2, 63 63 lines=nblines) 64 64 for line in range(nblines) : … … 67 67 if upq.SoftLimit is None : 68 68 percent = "%i" % upq.PageCounter 69 else : 69 else : 70 70 percent = "%i%%" % min((upq.PageCounter * 100) / upq.SoftLimit, 100) 71 else : 71 else : 72 72 percent = "%i%%" % min((upq.PageCounter * 100) / upq.HardLimit, 100) 73 printername = upq.Printer.Name 73 printername = upq.Printer.Name 74 74 msg = _("Pages used on %(printername)s : %(percent)s") % locals() 75 display.display(msg.encode(self.charset, "replace"), 76 type=pyosd.TYPE_STRING, 75 display.display(msg.encode(self.charset, "replace"), 76 type=pyosd.TYPE_STRING, 77 77 line=line) 78 78 elif user.LimitBy == "balance" : 79 79 if user.AccountBalance <= self.config.getBalanceZero() : 80 80 color = "#FF0000" 81 display = pyosd.osd(font=options.font, 82 colour=color, 83 timeout=options.duration, 81 display = pyosd.osd(font=options.font, 82 colour=color, 83 timeout=options.duration, 84 84 shadow=2) 85 balance = user.AccountBalance 85 balance = user.AccountBalance 86 86 msg = _("PyKota Units left : %(balance).2f") % locals() 87 display.display(msg.encode(self.charset, "replace"), 87 display.display(msg.encode(self.charset, "replace"), 88 88 type=pyosd.TYPE_STRING) 89 elif user.LimitBy == "noprint" : 90 display = pyosd.osd(font=options.font, 91 colour="#FF0000", 92 timeout=options.duration, 89 elif user.LimitBy == "noprint" : 90 display = pyosd.osd(font=options.font, 91 colour="#FF0000", 92 timeout=options.duration, 93 93 shadow=2) 94 94 msg = _("Printing denied.") 95 display.display(msg.encode(self.charset, "replace"), 95 display.display(msg.encode(self.charset, "replace"), 96 96 type=pyosd.TYPE_STRING) 97 elif user.LimitBy == "noquota" : 98 display = pyosd.osd(font=options.font, 99 colour=savecolor, 100 timeout=options.duration, 97 elif user.LimitBy == "noquota" : 98 display = pyosd.osd(font=options.font, 99 colour=savecolor, 100 timeout=options.duration, 101 101 shadow=2) 102 102 msg = _("Printing not limited.") 103 display.display(msg.encode(self.charset, "replace"), 103 display.display(msg.encode(self.charset, "replace"), 104 104 type=pyosd.TYPE_STRING) 105 elif user.LimitBy == "nochange" : 106 display = pyosd.osd(font=options.font, 107 colour=savecolor, 108 timeout=options.duration, 105 elif user.LimitBy == "nochange" : 106 display = pyosd.osd(font=options.font, 107 colour=savecolor, 108 timeout=options.duration, 109 109 shadow=2) 110 110 msg = _("Printing not limited, no accounting.") 111 display.display(msg.encode(self.charset, "replace"), 111 display.display(msg.encode(self.charset, "replace"), 112 112 type=pyosd.TYPE_STRING) 113 else : 113 else : 114 114 limitby = repr(user.LimitBy) 115 115 raise PyKotaToolError, "Incorrect limitation factor %(limitby)s for user %(username)s" % locals() 116 116 117 117 time.sleep(options.duration + 1) 118 118 if loop : … … 120 120 if not loop : 121 121 break 122 time.sleep(options.sleep) 123 124 return 0 125 122 time.sleep(options.sleep) 123 124 return 0 125 126 126 if __name__ == "__main__" : 127 def checkandset_positiveint(option, opt, value, optionparser) : 127 def checkandset_positiveint(option, opt, value, optionparser) : 128 128 """Checks and sets positive integer values.""" 129 129 if value < 0 : 130 130 loginvalidparam(opt, value, option.default) 131 131 setattr(optionparser.values, option.dest, option.default) 132 else : 132 else : 133 133 setattr(optionparser.values, option.dest, value) 134 135 def checkandset_color(option, opt, value, optionparser) : 134 135 def checkandset_color(option, opt, value, optionparser) : 136 136 """Checks and sets the color value.""" 137 137 if not value.startswith("#") : 138 138 value = "#%s" % value 139 try : 139 try : 140 140 int(value[1:], 16) 141 except (ValueError, TypeError) : 141 except (ValueError, TypeError) : 142 142 error = True 143 else : 143 else : 144 144 error = False 145 145 if (len(value) != 7) or error : 146 146 loginvalidparam(opt, value, option.default) 147 147 setattr(optionparser.values, option.dest, option.default) 148 else : 148 else : 149 149 setattr(optionparser.values, option.dest, value) 150 150 151 151 parser = PyKotaOptionParser(description=_("An On Screen Display (OSD) monitor for PyKota's end users.")) 152 152 parser.add_option("-c", "--color", "--colour", … … 182 182 default=180, 183 183 help=_("Set the sleeping time in seconds between two refreshes. Defaults to %default seconds.")) 184 184 185 185 parser.add_example('-s 60 --loop 5', 186 186 _("This would tell pykosd to display the current user's status for 3 seconds (the default) every 60 seconds, and exit after 5 iterations.")) 187 187 188 188 run(parser, PyKOSD)