root / pykota / trunk / bin / pykosd @ 1595

Revision 1595, 2.0 kB (checked in by jalet, 20 years ago)

Introduction of the pykosd command

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1#! /usr/bin/env python
2# -*- coding: ISO-8859-15 -*-
3
4# PyKota Print Quota Editor
5#
6# PyKota - Print Quotas for CUPS and LPRng
7#
8# (c) 2003-2004 Jerome Alet <alet@librelogiciel.com>
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 2 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22#
23# $Id$
24#
25# $Log$
26# Revision 1.1  2004/07/07 13:21:27  jalet
27# Introduction of the pykosd command
28#
29#
30#
31
32import sys
33import os
34import pwd
35import time
36import pyosd
37
38from pykota.tool import PyKotaTool, PyKotaToolError, crashed
39
40if __name__ == "__main__" :
41    retcode = -1
42    try :
43        cmd = PyKotaTool(doc="A tool to display remaining print units")
44    except :   
45        crashed("Initialization problem.")
46    else :   
47        try :
48            uid = os.geteuid()
49            uname = pwd.getpwuid(uid)[0]
50            user = cmd.storage.getUser(uname)
51            if not user.Exists :
52                raise PyKotaToolError, "User %s doesn't exist in PyKota's database." % uname
53            display = pyosd.osd(colour="#FF0000", timeout=5, shadow=2)
54            display.display("PyKota Units left : %.2f" % user.AccountBalance, type=pyosd.TYPE_STRING)   
55            time.sleep(6)
56        except :
57            cmd.crashed("Strange problem : please report it ASAP to alet@librelogiciel.com")
58        else :
59            retcode = 0
60        try :
61            cmd.storage.close()
62        except :   
63            pass
64    sys.exit(retcode)
Note: See TracBrowser for help on using the browser.