root / pykota / trunk / cgi-bin / dumpykota.cgi @ 2023

Revision 2023, 6.8 kB (checked in by jalet, 20 years ago)

Fixed the default datatype which is now set to 'history'

  • 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/python
2# -*- coding: ISO-8859-15 -*-
3
4# PyKota Print Quota Reports generator
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.3  2005/01/10 14:57:29  jalet
27# Fixed the default datatype which is now set to 'history'
28#
29# Revision 1.2  2005/01/08 19:47:00  jalet
30# Fixed a bad copy&paste
31#
32# Revision 1.1  2005/01/08 19:13:11  jalet
33# dumpykota.cgi was added to allow the use of dumpykota through the web.
34# This makes real time interfacing with the third party software phpPrintAnalyzer
35# a breeze !
36#
37#
38
39import sys
40import os
41import cgi
42import urllib
43
44from pykota import version
45from pykota.tool import PyKotaToolError
46from pykota.dumper import DumPyKota
47from pykota.cgifuncs import getLanguagePreference, getCharsetPreference
48
49header = """Content-type: text/html
50
51<?xml version="1.0" encoding="%s"?>
52<html>
53  <head>
54    <title>%s</title>
55    <link rel="stylesheet" type="text/css" href="/pykota.css" />
56  </head>
57  <body>
58    <form action="dumpykota.cgi" method="GET">
59      <table>
60        <tr>
61          <td>
62            <p>
63              <a href="http://www.librelogiciel.com/software/"><img src="http://www.librelogiciel.com/software/PyKota/pykota.png" alt="PyKota's Logo" /></a>
64              <br />
65              <a href="http://www.librelogiciel.com/software/">PyKota v%s</a>
66            </p>
67          </td>
68          <td colspan="2">
69            <h1>%s</h1>
70          </td>
71        </tr>
72        <tr>
73          <td colspan="3" align="center">
74            <input type="submit" name="report" value="%s" />
75          </td>
76        </tr>
77      </table>
78      <p>
79        %s
80      </p>"""
81   
82footer = """
83      <table>
84        <tr>
85          <td colspan="3" align="center">
86            <input type="submit" name="report" value="%s" />
87          </td>
88        </tr>
89      </table> 
90    </form>
91  </body>
92</html>""" 
93
94class PyKotaDumperGUI(DumPyKota) :
95    """PyKota Dumper GUI"""
96    def guiDisplay(self) :
97        """Displays the dumper interface."""
98        global header, footer
99        print header % (self.getCharset(), _("PyKota Data Dumper"), version.__version__, _("PyKota Data Dumper"), _("Dump"), _("Please click on the above button"))
100        print self.htmlListDataTypes(self.options.get("data", ""))
101        print "<br />"
102        print self.htmlListFormats(self.options.get("format", ""))
103        print "<br />"
104        print self.htmlFilterInput(" ".join(self.arguments))
105        print footer % _("Dump")
106       
107    def htmlListDataTypes(self, selected="") :   
108        """Displays the datatype selection list."""
109        message = '<table><tr><td valign="top">%s :</td><td valign="top"><select name="datatype">' % _("Data Type")
110        for dt in self.validdatatypes.items() :
111            if dt[0] == selected :
112                message += '<option value="%s" selected="selected">%s (%s)</option>' % (dt[0], dt[0], dt[1])
113            else :
114                message += '<option value="%s">%s (%s)</option>' % (dt[0], dt[0], dt[1])
115        message += '</select></td></tr></table>'
116        return message
117       
118    def htmlListFormats(self, selected="") :   
119        """Displays the formats selection list."""
120        message = '<table><tr><td valign="top">%s :</td><td valign="top"><select name="format">' % _("Output Format")
121        for fmt in self.validformats.items() :
122            if fmt[0] == selected :
123                message += '<option value="%s" selected="selected">%s (%s)</option>' % (fmt[0], fmt[0], fmt[1])
124            else :
125                message += '<option value="%s">%s (%s)</option>' % (fmt[0], fmt[0], fmt[1])
126        message += '</select></td></tr></table>'
127        return message
128       
129    def htmlFilterInput(self, value="") :   
130        """Input the optional dump filter."""
131        return _("Filter") + (' : <input type="text" name="filter" size="40" value="%s" /> <em>e.g. <strong>username=jerome printername=HP2100</strong></em>' % (value or ""))
132       
133    def guiAction(self) :
134        """Main function"""
135        try :
136            wantreport = self.form.has_key("report")
137        except TypeError :   
138            pass # WebDAV request probably, seen when trying to open a csv file in OOo
139        else :   
140            if wantreport :
141                if self.form.has_key("datatype") :
142                    self.options["data"] = self.form["datatype"].value
143                if self.form.has_key("format") :
144                    self.options["format"] = self.form["format"].value
145                if self.form.has_key("filter") :   
146                    self.arguments = self.form["filter"].value.split()
147                   
148                if self.options["format"] in ("csv", "ssv") :
149                    #ctype = "application/vnd.sun.xml.calc"
150                    ctype = "text/comma-separated-values"
151                    fname = "dump.csv"
152                elif self.options["format"] == "tsv" :
153                    #ctype = "application/vnd.sun.xml.calc"
154                    ctype = "text/tab-separated-values"
155                    fname = "dump.tsv"
156                elif self.options["format"] == "xml" :
157                    ctype = "text/xml"
158                    fname = "dump.xml"
159                elif self.options["format"] == "cups" :
160                    ctype = "text/plain"
161                    fname = "page_log"
162                print "Content-type: %s" % ctype   
163                print "Content-disposition: attachment; filename=%s" % fname
164                print
165                try :
166                    self.main(self.arguments, self.options)
167                except PyKotaToolError, msg :   
168                    print msg
169            else :       
170                self.guiDisplay()
171           
172if __name__ == "__main__" :
173    os.environ["LC_ALL"] = getLanguagePreference()
174    admin = PyKotaDumperGUI(lang=os.environ["LC_ALL"], charset=getCharsetPreference())
175    admin.form = cgi.FieldStorage()
176    admin.options = { "output" : "-",
177                "data" : "history",
178                "format" : "cups",
179              }
180    admin.arguments = []
181    admin.guiAction()
182    try :
183        admin.storage.close()
184    except (TypeError, NameError, AttributeError) :   
185        pass
186       
187    sys.exit(0)
Note: See TracBrowser for help on using the browser.