Changeset 1605
- Timestamp:
- 07/20/04 00:37:25 (20 years ago)
- Location:
- pykota/trunk
- Files:
-
- 1 added
- 13 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/pkprinters
r1584 r1605 24 24 # 25 25 # $Log$ 26 # Revision 1.14 2004/07/19 22:37:13 jalet 27 # pykosd is now a very good tool 28 # 26 29 # Revision 1.13 2004/07/01 19:56:41 jalet 27 30 # Better dispatching of error messages … … 73 76 from pykota import version 74 77 from pykota.tool import PyKotaTool, PyKotaToolError, crashed 75 from pykota.config import PyKotaConfigError76 from pykota.storage import PyKotaStorageError77 78 78 79 __doc__ = """pkprinters v%s (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres -
pykota/trunk/bin/pykosd
r1597 r1605 24 24 # 25 25 # $Log$ 26 # Revision 1.4 2004/07/19 22:37:13 jalet 27 # pykosd is now a very good tool 28 # 26 29 # Revision 1.3 2004/07/07 21:44:15 jalet 27 30 # Formatting improvements … … 42 45 import pyosd 43 46 47 from pykota import version 44 48 from pykota.tool import PyKotaTool, PyKotaToolError, crashed 45 49 46 DURATION = 5 50 __doc__ = """pykosd v%s (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 51 An OSD quota monitor for PyKota. 47 52 48 if __name__ == "__main__" : 49 retcode = -1 50 try : 51 cmd = PyKotaTool(doc="A tool to display remaining print units") 52 except : 53 crashed("Initialization problem.") 54 else : 55 try : 56 uid = os.geteuid() 57 uname = pwd.getpwuid(uid)[0] 58 user = cmd.storage.getUser(uname) 53 command line usage : 54 55 pykosd [options] 56 57 options : 58 59 -v | --version Prints pkprinters's version number then exits. 60 -h | --help Prints this message then exits. 61 62 -d | --duration d Sets the duration of the display in seconds. 63 Defaults to 3 seconds. 64 65 -l | --loop n Sets the number of times the info will be displayed. 66 Defaults to 0, which means loop forever. 67 68 -s | --sleep s Sets the sleeping duration between two displays 69 in seconds. Defaults to 180 seconds (3 minutes). 70 71 72 examples : 73 74 $ pykosd -s 60 --loop 5 75 76 Will launch pykosd. Display will be refreshed every 60 seconds, 77 and will last for 3 seconds (the default) each time. After five 78 iterations, the program will exit. 79 80 This program is free software; you can redistribute it and/or modify 81 it under the terms of the GNU General Public License as published by 82 the Free Software Foundation; either version 2 of the License, or 83 (at your option) any later version. 84 85 This program is distributed in the hope that it will be useful, 86 but WITHOUT ANY WARRANTY; without even the implied warranty of 87 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 88 GNU General Public License for more details. 89 90 You should have received a copy of the GNU General Public License 91 along with this program; if not, write to the Free Software 92 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 93 94 Please e-mail bugs to: %s""" % (version.__version__, version.__author__) 95 96 97 class PyKOSD(PyKotaTool) : 98 def main(self, args, options) : 99 """Main function starts here.""" 100 try : 101 duration = int(options["duration"]) 102 except : 103 raise PyKotaToolError, "Invalid duration option %s" % str(options["duration"]) 104 105 try : 106 loop = int(options["loop"]) 107 except : 108 raise PyKotaToolError, "Invalid loop option %s" % str(options["loop"]) 109 110 try : 111 sleep = float(options["sleep"]) 112 except : 113 raise PyKotaToolError, "Invalid sleep option %s" % str(options["sleep"]) 114 115 uid = os.geteuid() 116 uname = pwd.getpwuid(uid)[0] 117 while 1 : 118 user = cmd.storage.getUserFromBackend(uname) # don't use cache 59 119 if not user.Exists : 60 120 raise PyKotaToolError, "User %s doesn't exist in PyKota's database." % uname 61 121 if user.LimitBy == "quota" : 62 122 printers = cmd.storage.getMatchingPrinters("*") 63 upquotas = [ cmd.storage.getUserPQuota (user, p) for p in printers ]123 upquotas = [ cmd.storage.getUserPQuotaFromBackend(user, p) for p in printers ] # don't use cache 64 124 nblines = len(upquotas) 65 display = pyosd.osd(colour="#00FF00", timeout= DURATION, shadow=2, lines=nblines)125 display = pyosd.osd(colour="#00FF00", timeout=duration, shadow=2, lines=nblines) 66 126 for line in range(nblines) : 67 127 upq = upquotas[line] … … 73 133 else : 74 134 percent = "%s%%" % min((upq.PageCounter * 100) / upq.HardLimit, 100) 75 display.display( "Pages used on %s : %s"% (upq.Printer.Name, percent), type=pyosd.TYPE_STRING, line=line)135 display.display(_("Pages used on %s : %s") % (upq.Printer.Name, percent), type=pyosd.TYPE_STRING, line=line) 76 136 else : 77 137 if user.AccountBalance <= 0 : … … 79 139 else : 80 140 color = "#00FF00" 81 display = pyosd.osd(colour=color, timeout=DURATION, shadow=2) 82 display.display("PyKota Units left : %.2f" % user.AccountBalance, type=pyosd.TYPE_STRING) 83 time.sleep(DURATION + 1) 84 except : 85 cmd.crashed("Strange problem : please report it ASAP to alet@librelogiciel.com") 86 else : 87 retcode = 0 141 display = pyosd.osd(colour=color, timeout=duration, shadow=2) 142 display.display(_("PyKota Units left : %.2f") % user.AccountBalance, type=pyosd.TYPE_STRING) 143 time.sleep(duration + 1) 144 if loop : 145 loop -= 1 146 if not loop : 147 break 148 time.sleep(sleep) 149 150 return 0 151 152 if __name__ == "__main__" : 153 retcode = -1 154 try : 155 defaults = { \ 156 "duration" : "3", \ 157 "loop" : "0", \ 158 "sleep" : "180", \ 159 } 160 short_options = "hvd:l:s:" 161 long_options = ["help", "version", "duration=", "loop=", "sleep="] 162 163 cmd = PyKOSD(doc=__doc__) 164 165 # parse and checks the command line 166 (options, args) = cmd.parseCommandline(sys.argv[1:], short_options, long_options, allownothing=1) 167 168 # sets long options 169 options["help"] = options["h"] or options["help"] 170 options["version"] = options["v"] or options["version"] 171 options["duration"] = options["d"] or options["duration"] or defaults["duration"] 172 options["loop"] = options["l"] or options["loop"] or defaults["loop"] 173 options["sleep"] = options["s"] or options["sleep"] or defaults["sleep"] 174 175 if options["help"] : 176 cmd.display_usage_and_quit() 177 elif options["version"] : 178 cmd.display_version_and_quit() 179 else : 180 retcode = cmd.main(args, options) 181 except KeyboardInterrupt : 182 retcode = 0 183 except SystemExit : 184 pass 185 except : 88 186 try : 89 cmd. storage.close()187 cmd.crashed("pykosd failed") 90 188 except : 91 pass 189 crashed("pykosd failed") 190 191 try : 192 cmd.storage.close() 193 except : 194 pass 195 92 196 sys.exit(retcode) -
pykota/trunk/docs/pykosd.sgml
r1600 r1605 13 13 Whenever you launch <filename>pykosd</filename>, it will display the current user's print quota 14 14 information in the top-left corner of the screen, above all existing windows, and with 15 a transparent background. Then after five seconds, the information displayed will disappear 16 and the program will exit. 15 a transparent background. 17 16 </para> 18 17 19 18 <para> 20 In the future, this command will accept some parameters which will render it more 21 useful. 19 By default, the information will remain displayed during <literal>3</literal> seconds, and 20 will be refreshed every <literal>180</literal> seconds. The program will loop forever 21 until <keysym>Ctrl+C</keysym> is pressed, unless a specific number of iterations was 22 asked for. 23 24 <tip> 25 <title>Tip</title> 26 <para> 27 Use command line options to change this behaviour. 28 </para> 29 </tip> 22 30 </para> 23 31 … … 27 35 <cmdsynopsis> 28 36 <command>pykosd</command> 37 <group choice="opt"><arg>-v</arg><arg>--version</arg></group> 38 <group choice="opt"><arg>-h</arg><arg>--help</arg></group> 39 <group choice="opt"> 40 <arg>-d <replaceable>d</replaceable></arg> 41 <arg>--duration <replaceable>d</replaceable></arg> 42 </group> 43 <group choice="opt"> 44 <arg>-l <replaceable>n</replaceable></arg> 45 <arg>--loop <replaceable>n</replaceable></arg> 46 </group> 47 <group choice="opt"> 48 <arg>-s <replaceable>s</replaceable></arg> 49 <arg>--sleep <replaceable>s</replaceable></arg> 50 </group> 29 51 </cmdsynopsis> 30 <warning>31 <para>32 <filename>pykosd</filename> doesn't currently accept any command line33 option. This will change in the future.34 </para>35 </warning>36 52 </para> 37 53 </sect1> … … 41 57 42 58 $Log$ 59 Revision 1.2 2004/07/19 22:37:13 jalet 60 pykosd is now a very good tool 61 43 62 Revision 1.1 2004/07/16 12:22:46 jalet 44 63 LPRng support early version -
pykota/trunk/man/edpykota.1
r1582 r1605 2 2 .TH EDPYKOTA "1" "July 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 3 3 .SH NAME 4 edpykota \- manual page for edpykota 1.19alpha 28_unofficial4 edpykota \- manual page for edpykota 1.19alpha33_unofficial 5 5 .SH DESCRIPTION 6 edpykota v1.19alpha 28_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres6 edpykota v1.19alpha33_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 7 7 A Print Quota editor for PyKota. 8 8 .PP -
pykota/trunk/man/genman.sh
r1338 r1605 14 14 # $Id$ 15 15 # 16 for prog in edpykota pykotme repykota warnpykota pkprinters pkhint ; do16 for prog in edpykota pykotme repykota warnpykota pkprinters pkhint pykosd ; do 17 17 help2man --section=1 --manual "User Commands" --source="C@LL - Conseil Internet & Logiciels Libres" --output=$prog.1 --no-info $prog ; 18 18 done -
pykota/trunk/man/Makefile.am
r1430 r1605 9 9 waitprinter.sh.1 \ 10 10 pkpgcounter.1 \ 11 pykosd.1 \ 11 12 warnpykota.1 12 13 -
pykota/trunk/man/pkhint.1
r1582 r1605 2 2 .TH PKHINT "1" "July 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 3 3 .SH NAME 4 pkhint \- manual page for pkhint 1.19alpha 28_unofficial4 pkhint \- manual page for pkhint 1.19alpha33_unofficial 5 5 .SH DESCRIPTION 6 pkhint v1.19alpha 28_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres6 pkhint v1.19alpha33_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 7 7 A tool to give hints on what accounting method is best for each printer. 8 8 .PP -
pykota/trunk/man/pkprinters.1
r1582 r1605 2 2 .TH PKPRINTERS "1" "July 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 3 3 .SH NAME 4 pkprinters \- manual page for pkprinters 1.19alpha 28_unofficial4 pkprinters \- manual page for pkprinters 1.19alpha33_unofficial 5 5 .SH DESCRIPTION 6 pkprinters v1.19alpha 28_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres6 pkprinters v1.19alpha33_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 7 7 A Printers Manager for PyKota. 8 8 .PP -
pykota/trunk/man/pykotme.1
r1582 r1605 2 2 .TH PYKOTME "1" "July 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 3 3 .SH NAME 4 pykotme \- manual page for pykotme 1.19alpha 28_unofficial4 pykotme \- manual page for pykotme 1.19alpha33_unofficial 5 5 .SH DESCRIPTION 6 pykotme v1.19alpha 28_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres6 pykotme v1.19alpha33_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 7 7 .PP 8 8 Gives print quotes to users. -
pykota/trunk/man/repykota.1
r1582 r1605 2 2 .TH REPYKOTA "1" "July 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 3 3 .SH NAME 4 repykota \- manual page for repykota 1.19alpha 28_unofficial4 repykota \- manual page for repykota 1.19alpha33_unofficial 5 5 .SH DESCRIPTION 6 repykota v1.19alpha 28_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres6 repykota v1.19alpha33_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 7 7 .PP 8 8 Generates print quota reports. -
pykota/trunk/man/warnpykota.1
r1582 r1605 2 2 .TH WARNPYKOTA "1" "July 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 3 3 .SH NAME 4 warnpykota \- manual page for warnpykota 1.19alpha 28_unofficial4 warnpykota \- manual page for warnpykota 1.19alpha33_unofficial 5 5 .SH DESCRIPTION 6 warnpykota v1.19alpha 28_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres6 warnpykota v1.19alpha33_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 7 7 .PP 8 8 Sends mail to users over print quota. -
pykota/trunk/NEWS
r1604 r1605 22 22 PyKota NEWS : 23 23 24 25 - 1.19alpha33 : 26 27 - pykosd now accepts command line arguments. Enjoy ! 28 NB : due to a bug in xosd, you need xosd version 2.2.8 29 or higher if you don't use the default C locale. 30 24 31 - 1.19alpha32 : 25 32 -
pykota/trunk/pykota/version.py
r1600 r1605 22 22 # 23 23 24 __version__ = "1.19alpha3 2_unofficial"24 __version__ = "1.19alpha33_unofficial" 25 25 26 26 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""