root / pykota / trunk / bin / dumpykota @ 2303

Revision 2303, 7.0 kB (checked in by jerome, 19 years ago)

Updated the FSF's address

  • 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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) %s %s
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  -s | --sum           Summarize the selected datas.
80                           ONLY AVAILABLE WITH --data history or payments
81
82  Use the filter expressions to extract only parts of the
83  datas. Allowed filters are of the form :
84               
85         key=value
86                         
87  Allowed keys for now are : 
88                       
89         username       User's name
90         groupname      Users group's name
91         printername    Printer's name
92         pgroupname     Printers group's name
93         hostname       Client's hostname
94         billingcode    Job's billing code
95         start          Job's date of printing
96         end            Job's date of printing
97         
98  Contrary to other PyKota management tools, wildcard characters are not
99  expanded, so you can't use them.
100 
101  NB : not all keys are allowed for each data type, so the result may be
102  empty if you use a key not available for a particular data type.
103 
104Examples :
105
106  $ dumpykota --data history --format csv >myfile.csv
107 
108  This dumps the history in a comma separated values file, for possible
109  use in a spreadsheet.
110 
111  $ dumpykota --data users --format xml -o users.xml
112 
113  Dumps all users datas to the users.xml file.
114 
115  $ dumpykota --data history printername=HP2100 username=jerome
116 
117  Dumps the job history for user jerome on printer HP2100 only.
118 
119  $ dumpykota --data history start=200503 end=20050730234615
120 
121  Dumps all jobs printed between March 1st 2005 at midnight and
122  July 30th 2005 at 23 hours 46 minutes and 15 secondes included.
123 
124This program is free software; you can redistribute it and/or modify
125it under the terms of the GNU General Public License as published by
126the Free Software Foundation; either version 2 of the License, or
127(at your option) any later version.
128
129This program is distributed in the hope that it will be useful,
130but WITHOUT ANY WARRANTY; without even the implied warranty of
131MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
132GNU General Public License for more details.
133
134You should have received a copy of the GNU General Public License
135along with this program; if not, write to the Free Software
136Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
137
138Please e-mail bugs to: %s""")
139       
140if __name__ == "__main__" : 
141    retcode = 0
142    try :
143        defaults = { \
144                     "format" : "csv", \
145                     "output" : "-", \
146                   }
147        short_options = "vhd:f:o:s"
148        long_options = ["help", "version", "data=", "format=", "output=", "sum"]
149       
150        # Initializes the command line tool
151        dumper = DumPyKota(doc=__doc__)
152        dumper.deferredInit()
153       
154        # parse and checks the command line
155        (options, args) = dumper.parseCommandline(sys.argv[1:], short_options, long_options, allownothing=1)
156       
157        # sets long options
158        options["help"] = options["h"] or options["help"]
159        options["version"] = options["v"] or options["version"]
160        options["data"] = options["d"] or options["data"]
161        options["format"] = options["f"] or options["format"] or defaults["format"]
162        options["output"] = options["o"] or options["output"] or defaults["output"]
163        options["sum"] = options["s"] or options["sum"]
164       
165        if options["help"] :
166            dumper.display_usage_and_quit()
167        elif options["version"] :
168            dumper.display_version_and_quit()
169        elif options["data"] is None :   
170            raise PyKotaToolError, _("The -d | --data command line option is mandatory, see help.")
171        else :
172            retcode = dumper.main(args, options)
173    except KeyboardInterrupt :       
174        sys.stderr.write("\nInterrupted with Ctrl+C !\n")
175    except SystemExit :       
176        pass
177    except :
178        try :
179            dumper.crashed("dumpykota failed")
180        except :   
181            crashed("dumpykota failed")
182        retcode = -1
183
184    try :
185        dumper.storage.close()
186    except (TypeError, NameError, AttributeError) :   
187        pass
188       
189    sys.exit(retcode)   
Note: See TracBrowser for help on using the browser.