root / pykota / trunk / bin / dumpykota @ 2266

Revision 2266, 6.9 kB (checked in by jerome, 19 years ago)

Now dumpykota and dumpykota.cgi accept start= and end=
to specify the starting and ending dates when dumping the
history.
Syntax allowed is :

start|end=YYYY[MM[DD[hh[mm[ss]]]]]

and this is REALLY powerful !

  • 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 Data Dumper
5#
6# PyKota - Print Quotas for CUPS and LPRng
7#
8# (c) 2003, 2004, 2005 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#
26
27import sys
28import os
29
30from pykota import version
31from pykota.tool import PyKotaToolError, crashed, N_
32from pykota.dumper import DumPyKota
33
34__doc__ = N_("""dumpykota v%s (c) 2003, 2004, 2005 C@LL - Conseil Internet & Logiciels Libres
35
36Dumps PyKota database's content.
37
38command line usage :
39
40  dumpykota [options] [filterexpr]
41
42options :
43
44  -v | --version       Prints dumpykota's version number then exits.
45  -h | --help          Prints this message then exits.
46 
47  -d | --data type     Dumps 'type' datas. Allowed types are :
48                       
49                         - history : dumps the jobs history.
50                         - users : dumps users.
51                         - groups : dumps user groups.
52                         - printers : dump printers.
53                         - upquotas : dump user quotas.
54                         - gpquotas : dump user groups quotas.
55                         - payments : dumps user payments.
56                         - pmembers : dumps printer groups members.
57                         - umembers : dumps user groups members.
58                         
59                       NB : the -d | --data command line option   
60                       is MANDATORY.
61 
62  -f | --format fmt    Dumps datas in the 'fmt' format. When not specified,
63                       the format is to dump datas in the csv format (comma
64                       separated values). All data dumped is between double
65                       quotes. Allowed formats are :
66                       
67                         - csv : separate datas with commas
68                         - ssv : separate datas with semicolons
69                         - tsv : separate datas with tabs
70                         - xml : dump data as XML
71                         - cups : dump datas in CUPS' page_log format :
72                                  ONLY AVAILABLE WITH --data history
73                         
74  -o | --output fname  All datas will be dumped to the file instead of
75                       to the standard output. The special '-' filename
76                       is the default value and means stdout.
77                       WARNING : existing files are truncated !
78                       
79  Use the filter expressions to extract only parts of the
80  datas. Allowed filters are of the form :
81               
82         key=value
83                         
84  Allowed keys for now are : 
85                       
86         username       User's name
87         groupname      Users group's name
88         printername    Printer's name
89         pgroupname     Printers group's name
90         hostname       Client's hostname
91         billingcode    Job's billing code
92         start          Job's date of printing
93         end            Job's date of printing
94         
95  Contrary to other PyKota management tools, wildcard characters are not
96  expanded, so you can't use them.
97 
98  NB : not all keys are allowed for each data type, so the result may be
99  empty if you use a key not available for a particular data type.
100 
101Examples :
102
103  $ dumpykota --data history --format csv >myfile.csv
104 
105  This dumps the history in a comma separated values file, for possible
106  use in a spreadsheet.
107 
108  $ dumpykota --data users --format xml -o users.xml
109 
110  Dumps all users datas to the users.xml file.
111 
112  $ dumpykota --data history printername=HP2100 username=jerome
113 
114  Dumps the job history for user jerome on printer HP2100 only.
115 
116  $ dumpykota --data history start=200503 end=20050730234615
117 
118  Dumps all jobs printed between March 1st 2005 at midnight and
119  July 30th 2005 at 23 hours 46 minutes and 15 secondes included.
120 
121This program is free software; you can redistribute it and/or modify
122it under the terms of the GNU General Public License as published by
123the Free Software Foundation; either version 2 of the License, or
124(at your option) any later version.
125
126This program is distributed in the hope that it will be useful,
127but WITHOUT ANY WARRANTY; without even the implied warranty of
128MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
129GNU General Public License for more details.
130
131You should have received a copy of the GNU General Public License
132along with this program; if not, write to the Free Software
133Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
134
135Please e-mail bugs to: %s""")
136       
137if __name__ == "__main__" : 
138    retcode = 0
139    try :
140        defaults = { \
141                     "format" : "csv", \
142                     "output" : "-", \
143                   }
144        short_options = "vhd:f:o:"
145        long_options = ["help", "version", "data=", "format=", "output="]
146       
147        # Initializes the command line tool
148        dumper = DumPyKota(doc=__doc__)
149        dumper.deferredInit()
150       
151        # parse and checks the command line
152        (options, args) = dumper.parseCommandline(sys.argv[1:], short_options, long_options, allownothing=1)
153       
154        # sets long options
155        options["help"] = options["h"] or options["help"]
156        options["version"] = options["v"] or options["version"]
157        options["data"] = options["d"] or options["data"]
158        options["format"] = options["f"] or options["format"] or defaults["format"]
159        options["output"] = options["o"] or options["output"] or defaults["output"]
160       
161        if options["help"] :
162            dumper.display_usage_and_quit()
163        elif options["version"] :
164            dumper.display_version_and_quit()
165        elif options["data"] is None :   
166            raise PyKotaToolError, _("The -d | --data command line option is mandatory, see help.")
167        else :
168            retcode = dumper.main(args, options)
169    except KeyboardInterrupt :       
170        sys.stderr.write("\nInterrupted with Ctrl+C !\n")
171    except SystemExit :       
172        pass
173    except :
174        try :
175            dumper.crashed("dumpykota failed")
176        except :   
177            crashed("dumpykota failed")
178        retcode = -1
179
180    try :
181        dumper.storage.close()
182    except (TypeError, NameError, AttributeError) :   
183        pass
184       
185    sys.exit(retcode)   
Note: See TracBrowser for help on using the browser.