Changeset 1605

Show
Ignore:
Timestamp:
07/20/04 00:37:25 (20 years ago)
Author:
jalet
Message:

pykosd is now a very good tool

Location:
pykota/trunk
Files:
1 added
13 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkprinters

    r1584 r1605  
    2424# 
    2525# $Log$ 
     26# Revision 1.14  2004/07/19 22:37:13  jalet 
     27# pykosd is now a very good tool 
     28# 
    2629# Revision 1.13  2004/07/01 19:56:41  jalet 
    2730# Better dispatching of error messages 
     
    7376from pykota import version 
    7477from pykota.tool import PyKotaTool, PyKotaToolError, crashed 
    75 from pykota.config import PyKotaConfigError 
    76 from pykota.storage import PyKotaStorageError 
    7778 
    7879__doc__ = """pkprinters v%s (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 
  • pykota/trunk/bin/pykosd

    r1597 r1605  
    2424# 
    2525# $Log$ 
     26# Revision 1.4  2004/07/19 22:37:13  jalet 
     27# pykosd is now a very good tool 
     28# 
    2629# Revision 1.3  2004/07/07 21:44:15  jalet 
    2730# Formatting improvements 
     
    4245import pyosd 
    4346 
     47from pykota import version 
    4448from pykota.tool import PyKotaTool, PyKotaToolError, crashed 
    4549 
    46 DURATION = 5 
     50__doc__ = """pykosd v%s (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 
     51An OSD quota monitor for PyKota. 
    4752 
    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) 
     53command line usage : 
     54 
     55  pykosd [options] 
     56 
     57options : 
     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   
     72examples :                               
     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   
     80This program is free software; you can redistribute it and/or modify 
     81it under the terms of the GNU General Public License as published by 
     82the Free Software Foundation; either version 2 of the License, or 
     83(at your option) any later version. 
     84 
     85This program is distributed in the hope that it will be useful, 
     86but WITHOUT ANY WARRANTY; without even the implied warranty of 
     87MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     88GNU General Public License for more details. 
     89 
     90You should have received a copy of the GNU General Public License 
     91along with this program; if not, write to the Free Software 
     92Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 
     93 
     94Please e-mail bugs to: %s""" % (version.__version__, version.__author__) 
     95 
     96 
     97class 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 
    59119            if not user.Exists : 
    60120                raise PyKotaToolError, "User %s doesn't exist in PyKota's database." % uname 
    61121            if user.LimitBy == "quota" :     
    62122                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 
    64124                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) 
    66126                for line in range(nblines) : 
    67127                    upq = upquotas[line] 
     
    73133                    else :         
    74134                        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) 
    76136            else : 
    77137                if user.AccountBalance <= 0 : 
     
    79139                else :     
    80140                    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         
     152if __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 :     
    88186        try : 
    89             cmd.storage.close() 
     187            cmd.crashed("pykosd failed") 
    90188        except :     
    91             pass 
     189            crashed("pykosd failed") 
     190         
     191    try : 
     192        cmd.storage.close() 
     193    except :     
     194        pass 
     195         
    92196    sys.exit(retcode) 
  • pykota/trunk/docs/pykosd.sgml

    r1600 r1605  
    1313    Whenever you launch <filename>pykosd</filename>, it will display the current user's print quota 
    1414    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.  
    1716  </para> 
    1817   
    1918  <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> 
    2230  </para> 
    2331   
     
    2735      <cmdsynopsis> 
    2836        <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> 
    2951      </cmdsynopsis> 
    30       <warning> 
    31         <para> 
    32           <filename>pykosd</filename> doesn't currently accept any command line 
    33           option. This will change in the future. 
    34         </para>   
    35       </warning> 
    3652    </para> 
    3753  </sect1> 
     
    4157 
    4258$Log$ 
     59Revision 1.2  2004/07/19 22:37:13  jalet 
     60pykosd is now a very good tool 
     61 
    4362Revision 1.1  2004/07/16 12:22:46  jalet 
    4463LPRng support early version 
  • pykota/trunk/man/edpykota.1

    r1582 r1605  
    22.TH EDPYKOTA "1" "July 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 
    33.SH NAME 
    4 edpykota \- manual page for edpykota 1.19alpha28_unofficial 
     4edpykota \- manual page for edpykota 1.19alpha33_unofficial 
    55.SH DESCRIPTION 
    6 edpykota v1.19alpha28_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 
     6edpykota v1.19alpha33_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 
    77A Print Quota editor for PyKota. 
    88.PP 
  • pykota/trunk/man/genman.sh

    r1338 r1605  
    1414# $Id$ 
    1515# 
    16 for prog in edpykota pykotme repykota warnpykota pkprinters pkhint ; do  
     16for prog in edpykota pykotme repykota warnpykota pkprinters pkhint pykosd ; do  
    1717    help2man --section=1 --manual "User Commands" --source="C@LL - Conseil Internet & Logiciels Libres" --output=$prog.1 --no-info $prog ;  
    1818done 
  • pykota/trunk/man/Makefile.am

    r1430 r1605  
    99        waitprinter.sh.1        \ 
    1010        pkpgcounter.1   \ 
     11        pykosd.1        \ 
    1112        warnpykota.1 
    1213 
  • pykota/trunk/man/pkhint.1

    r1582 r1605  
    22.TH PKHINT "1" "July 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 
    33.SH NAME 
    4 pkhint \- manual page for pkhint 1.19alpha28_unofficial 
     4pkhint \- manual page for pkhint 1.19alpha33_unofficial 
    55.SH DESCRIPTION 
    6 pkhint v1.19alpha28_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 
     6pkhint v1.19alpha33_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 
    77A tool to give hints on what accounting method is best for each printer. 
    88.PP 
  • pykota/trunk/man/pkprinters.1

    r1582 r1605  
    22.TH PKPRINTERS "1" "July 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 
    33.SH NAME 
    4 pkprinters \- manual page for pkprinters 1.19alpha28_unofficial 
     4pkprinters \- manual page for pkprinters 1.19alpha33_unofficial 
    55.SH DESCRIPTION 
    6 pkprinters v1.19alpha28_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 
     6pkprinters v1.19alpha33_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 
    77A Printers Manager for PyKota. 
    88.PP 
  • pykota/trunk/man/pykotme.1

    r1582 r1605  
    22.TH PYKOTME "1" "July 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 
    33.SH NAME 
    4 pykotme \- manual page for pykotme 1.19alpha28_unofficial 
     4pykotme \- manual page for pykotme 1.19alpha33_unofficial 
    55.SH DESCRIPTION 
    6 pykotme v1.19alpha28_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 
     6pykotme v1.19alpha33_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 
    77.PP 
    88Gives print quotes to users. 
  • pykota/trunk/man/repykota.1

    r1582 r1605  
    22.TH REPYKOTA "1" "July 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 
    33.SH NAME 
    4 repykota \- manual page for repykota 1.19alpha28_unofficial 
     4repykota \- manual page for repykota 1.19alpha33_unofficial 
    55.SH DESCRIPTION 
    6 repykota v1.19alpha28_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 
     6repykota v1.19alpha33_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 
    77.PP 
    88Generates print quota reports. 
  • pykota/trunk/man/warnpykota.1

    r1582 r1605  
    22.TH WARNPYKOTA "1" "July 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 
    33.SH NAME 
    4 warnpykota \- manual page for warnpykota 1.19alpha28_unofficial 
     4warnpykota \- manual page for warnpykota 1.19alpha33_unofficial 
    55.SH DESCRIPTION 
    6 warnpykota v1.19alpha28_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 
     6warnpykota v1.19alpha33_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 
    77.PP 
    88Sends mail to users over print quota. 
  • pykota/trunk/NEWS

    r1604 r1605  
    2222PyKota NEWS : 
    2323 
     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           
    2431    - 1.19alpha32 : 
    2532     
  • pykota/trunk/pykota/version.py

    r1600 r1605  
    2222# 
    2323 
    24 __version__ = "1.19alpha32_unofficial" 
     24__version__ = "1.19alpha33_unofficial" 
    2525 
    2626__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""