root / pykota / trunk / bin / dumpykota @ 2147

Revision 2147, 6.4 kB (checked in by jerome, 19 years ago)

Removed all references to $Log$

  • 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         
91  Contrary to other PyKota management tools, wildcard characters are not
92  expanded, so you can't use them.
93 
94  NB : not all keys are allowed for each data type, so the result may be
95  empty if you use a key not available for a particular data type.
96 
97Examples :
98
99  $ dumpykota --data history --format csv >myfile.csv
100 
101  This dumps the history in a comma separated values file, for possible
102  use in a spreadsheet.
103 
104  $ dumpykota --data users --format xml -o users.xml
105 
106  Dumps all users datas to the users.xml file.
107 
108  $ dumpykota --data history printername=HP2100 username=jerome
109 
110  Dumps the job history for user jerome on printer HP2100 only.
111 
112This program is free software; you can redistribute it and/or modify
113it under the terms of the GNU General Public License as published by
114the Free Software Foundation; either version 2 of the License, or
115(at your option) any later version.
116
117This program is distributed in the hope that it will be useful,
118but WITHOUT ANY WARRANTY; without even the implied warranty of
119MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
120GNU General Public License for more details.
121
122You should have received a copy of the GNU General Public License
123along with this program; if not, write to the Free Software
124Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
125
126Please e-mail bugs to: %s""")
127       
128if __name__ == "__main__" : 
129    retcode = 0
130    try :
131        defaults = { \
132                     "format" : "csv", \
133                     "output" : "-", \
134                   }
135        short_options = "vhd:f:o:"
136        long_options = ["help", "version", "data=", "format=", "output="]
137       
138        # Initializes the command line tool
139        dumper = DumPyKota(doc=__doc__)
140       
141        # parse and checks the command line
142        (options, args) = dumper.parseCommandline(sys.argv[1:], short_options, long_options, allownothing=1)
143       
144        # sets long options
145        options["help"] = options["h"] or options["help"]
146        options["version"] = options["v"] or options["version"]
147        options["data"] = options["d"] or options["data"]
148        options["format"] = options["f"] or options["format"] or defaults["format"]
149        options["output"] = options["o"] or options["output"] or defaults["output"]
150       
151        if options["help"] :
152            dumper.display_usage_and_quit()
153        elif options["version"] :
154            dumper.display_version_and_quit()
155        elif options["data"] is None :   
156            raise PyKotaToolError, _("The -d | --data command line option is mandatory, see help.")
157        else :
158            retcode = dumper.main(args, options)
159    except SystemExit :       
160        pass
161    except :
162        try :
163            dumper.crashed("dumpykota failed")
164        except :   
165            crashed("dumpykota failed")
166        retcode = -1
167
168    try :
169        dumper.storage.close()
170    except (TypeError, NameError, AttributeError) :   
171        pass
172       
173    sys.exit(retcode)   
Note: See TracBrowser for help on using the browser.