root / pykota / trunk / bin / dumpykota @ 3404

Revision 3368, 4.9 kB (checked in by jerome, 17 years ago)

dumpykota now support new style command line options.
TODO : dumpykota.cgi

  • 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: UTF-8 -*-
3#
4# PyKota : Print Quotas for CUPS
5#
6# (c) 2003, 2004, 2005, 2006, 2007, 2008 Jerome Alet <alet@librelogiciel.com>
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19#
20# $Id$
21#
22#
23
24"""A versatile data dumper for PyKota"""
25
26import sys
27
28import pykota.appinit
29from pykota.utils import run
30from pykota.commandline import PyKotaOptionParser
31
32from pykota.errors import PyKotaCommandLineError
33from pykota.dumper import DumPyKota
34
35if __name__ == "__main__" : 
36    parser = PyKotaOptionParser(description=_("Data Dumper for PyKota."),
37                                usage="dumpykota [options] [filterexpr]")
38                               
39    parser.add_option("-d", "--data",                           
40                            dest="data",
41                            help=_("Select the type of datas to dump. This option is mandatory. Supported data types are : history, payments, billingcodes, users, groups, printers, upquotas, gpquotas, umembers, pmembers, and all. The 'all' value forces the output format to XML."))
42    parser.add_option("-f", "--format",                           
43                            default="csv",
44                            dest="format",
45                            help=_("Select the output format, the default being comma separated values. Supported formats are : csv, ssv, tsv, xml and cups. The 'cups' output format only works when dumping the history, and produces CUPS' page_log compatible output."))
46    parser.add_option("-o", "--output",                           
47                            dest="output",
48                            default=u"-",
49                            help=_("The name of the file the data dump will be written to. The default value is '-', which tells dumpykota to write the dump to stdout."))
50    parser.add_option("-O", "--orderby",                           
51                            dest="orderby",
52                            help=_("Change the ordering of the output based on a comma separated list of ordering statements. For example '-username,+printername' would sort the output by descending order of user names and ascending order of printer names. Not all expressions are supported, and you should not use this if you don't know the internal structure of PyKota's database." ))
53    parser.add_option("-s", "--sum",                           
54                            dest="sum",
55                            action="store_true",
56                            default=False,
57                            help=_("Summarize the output. Only available when dumping the printing history or the payments."))
58                               
59    parser.add_filterexpression("username", _("User's name"))
60    parser.add_filterexpression("groupname", _("Users group's name"))
61    parser.add_filterexpression("printername", _("Printer's name"))
62    parser.add_filterexpression("pgroupname", _("Printers group's name"))
63    parser.add_filterexpression("hostname", _("Host's name"))
64    parser.add_filterexpression("jobid", _("Job's id"))
65    parser.add_filterexpression("billingcode", _("Job's billing code"))
66    parser.add_filterexpression("start", _("Job's date of printing"))
67    parser.add_filterexpression("end", _("Job's date of printing"))
68   
69    parser.add_example('--unit EURO --output /tmp/invoices.pdf start=now-30', 
70                       _("This would generate a PDF document containing invoices for all users who have spent some credits last month. Amounts would be in EURO and not VAT information would be included."))
71
72    parser.add_example("--data history --format csv >myfile.csv",
73                       _("This would dump the whole printing history to stdout in the CSV format, and redirect the output to a file."))
74 
75    parser.add_example("--data users --format xml -o users.xml",
76                       _("This would dump all users into the 'users.xml' file in the XML format."))
77 
78    parser.add_example("--data history printername=HP2100 username=jerome",
79                       _("This would dump jerome's printing history on printer HP2100."))
80 
81    parser.add_example("--data history start=200503 end=20050730234615",
82                       _("This would dump all jobs printer between March 1st 2008 at midnight and July 30th 2008 at 23 hours 46 minutes and 15 seconds, included."))
83    run(parser, DumPyKota)                   
Note: See TracBrowser for help on using the browser.