Changeset 1771

Show
Ignore:
Timestamp:
10/04/04 23:25:29 (20 years ago)
Author:
jalet
Message:

dumpykota can now output datas in the XML format

Location:
pykota/trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/dumpykota

    r1724 r1771  
    2424# 
    2525# $Log$ 
     26# Revision 1.7  2004/10/04 21:25:29  jalet 
     27# dumpykota can now output datas in the XML format 
     28# 
    2629# Revision 1.6  2004/09/15 18:28:41  jalet 
    2730# Updated help for dumpykota 
     
    5154import os 
    5255import pwd 
     56 
     57try : 
     58    import jaxml 
     59except ImportError :     
     60    sys.stderr.write("The jaxml Python module is not installed. XML output is disabled.\n") 
     61    sys.stderr.write("Download jaxml from http://www.librelogiciel.com/software/ or from your Debian archive of choice\n") 
     62    hasJAXML = 0 
     63else :     
     64    hasJAXML = 1 
    5365 
    5466from pykota import version 
     
    93105                         - ssv : separate datas with semicolons 
    94106                         - tsv : separate datas with tabs 
     107                         - xml : dump data as XML 
     108                          
     109  -o | --output fname  All datas will be dumped to the file instead of 
     110                       to the standard output. The special '-' filename 
     111                       is the default value and means stdout. 
     112                       WARNING : existing files are truncated ! 
     113   
     114Examples : 
     115 
     116  $ dumpykota --data history --format csv >myfile.csv 
     117   
     118  This dumps the history in a comma separated values file, for possible 
     119  use in a spreadsheet. 
     120   
     121  $ dumpykota --data users --format xml -o users.xml 
     122   
     123  Dumps all users datas to the users.xml file. 
    95124   
    96125This program is free software; you can redistribute it and/or modify 
     
    131160                           "ssv", 
    132161                           "tsv", 
     162                           "xml", 
    133163                         ] : 
    134164            raise PyKotaToolError, _("Invalid modifier [%s] for --format command line option, see help.") % datatype 
    135165             
     166        if (format == "xml") and not hasJAXML : 
     167            raise PyKotaToolError, _("XML output is disabled because the jaxml module is not available.") 
     168             
    136169        entries = getattr(self.storage, "extract%s" % datatype.title())()     
    137         if entries is not None : 
    138             return getattr(self, "dump%s" % format.title())(entries) 
     170        if entries : 
     171            mustclose = 0     
     172            if options["output"].strip() == "-" :     
     173                self.outfile = sys.stdout 
     174            else :     
     175                self.outfile = open(options["output"], "w") 
     176                mustclose = 1 
     177                 
     178            retcode = getattr(self, "dump%s" % format.title())(entries, datatype) 
     179             
     180            if mustclose : 
     181                self.outfile.close() 
     182                 
     183            return retcode     
    139184        return 0 
    140185         
     
    144189            line = separator.join([ '"%s"' % field for field in entry ]) 
    145190            try : 
    146                 print line 
     191                self.outfile.write("%s\n" % line) 
    147192            except IOError, msg :     
    148193                sys.stderr.write("%s : %s\n" % (_("PyKota data dumper failed : I/O error"), msg)) 
     
    150195        return 0         
    151196         
    152     def dumpCsv(self, entries) :     
     197    def dumpCsv(self, entries, dummy) :     
    153198        """Dumps datas with a comma as the separator.""" 
    154199        return self.dumpWithSeparator(",", entries) 
    155200                            
    156     def dumpSsv(self, entries) :     
     201    def dumpSsv(self, entries, dummy) :     
    157202        """Dumps datas with a comma as the separator.""" 
    158203        return self.dumpWithSeparator(";", entries) 
    159204                            
    160     def dumpTsv(self, entries) :     
     205    def dumpTsv(self, entries, dummy) :     
    161206        """Dumps datas with a comma as the separator.""" 
    162207        return self.dumpWithSeparator("\t", entries) 
     208         
     209    def dumpXml(self, entries, datatype) :     
     210        """Dumps datas as XML.""" 
     211        x = jaxml.XML_document(encoding="UTF-8") 
     212        x.pykota(version=version.__version__) 
     213        x.dump(storage=self.config.getStorageBackend()["storagebackend"], type=datatype) 
     214        headers = entries[0] 
     215        for entry in entries[1:] : 
     216            x._push() 
     217            x.entry() 
     218            for i in range(len(entry)) : 
     219                value = entry[i] 
     220                strvalue = str(value).decode(self.getCharset()).encode("UTF-8") 
     221                x.attribute(strvalue, type=type(value).__name__, name=headers[i]) 
     222            x._pop()     
     223        x._output(self.outfile) 
    163224                            
    164225if __name__ == "__main__" :  
     
    167228        defaults = { \ 
    168229                     "format" : "csv", \ 
     230                     "output" : "-", \ 
    169231                   } 
    170         short_options = "vhd:f:" 
    171         long_options = ["help", "version", "data=", "format="] 
     232        short_options = "vhd:f:o:" 
     233        long_options = ["help", "version", "data=", "format=", "output="] 
    172234         
    173235        # Initializes the command line tool 
     
    182244        options["data"] = options["d"] or options["data"] 
    183245        options["format"] = options["f"] or options["format"] or defaults["format"] 
     246        options["output"] = options["o"] or options["output"] or defaults["output"] 
    184247         
    185248        if options["help"] : 
  • pykota/trunk/man/dumpykota.1

    r1758 r1771  
    11.\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.33. 
    2 .TH DUMPYKOTA "1" "September 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 
     2.TH DUMPYKOTA "1" "October 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 
    33.SH NAME 
    4 dumpykota \- manual page for dumpykota 1.20alpha18_unofficial 
     4dumpykota \- manual page for dumpykota 1.20alpha20_unofficial 
    55.SH DESCRIPTION 
    6 dumpykota v1.20alpha18_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 
     6dumpykota v1.20alpha20_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 
    77.PP 
    88Dumps PyKota database's content. 
     
    4545- ssv : separate datas with semicolons 
    4646- tsv : separate datas with tabs 
     47- xml : dump data as XML 
     48.TP 
     49\fB\-o\fR | \fB\-\-output\fR fname 
     50All datas will be dumped to the file instead of 
     51to the standard output. The special '-' filename 
     52is the default value and means stdout. 
     53WARNING : existing files are truncated ! 
     54.PP 
     55Examples : 
     56.IP 
     57\f(CW$ dumpykota --data history --format csv >myfile.csv\fR 
     58.IP 
     59This dumps the history in a comma separated values file, for possible 
     60use in a spreadsheet. 
     61.IP 
     62\f(CW$ dumpykota --data users --format xml -o users.xml\fR 
     63.IP 
     64Dumps all users datas to the users.xml file. 
    4765.PP 
    4866This program is free software; you can redistribute it and/or modify 
  • pykota/trunk/NEWS

    r1769 r1771  
    2222PyKota NEWS : 
    2323 
     24    - 1.20alpha20 : 
     25     
     26        - dumpykota can now output XML. 
     27         
    2428    - 1.20alpha19 : 
    2529     
  • pykota/trunk/pykota/version.py

    r1761 r1771  
    2222# 
    2323 
    24 __version__ = "1.20alpha19_unofficial" 
     24__version__ = "1.20alpha20_unofficial" 
    2525 
    2626__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng.""" 
  • pykota/trunk/README

    r1744 r1771  
    210210    - Python v2.1 or above 
    211211    - eGenix' mxDateTime Python extension 
    212     - SNMP tools (specifically the snmpget command) if you plan to 
    213       request your printer's lifetime page counter via SNMP. 
     212    - The JAXML Python module to be able to dump datas in the XML format. 
     213    - The Python-SNMP module to query printers for their page counter. 
     214    - The Python-OSD module to use the graphical print quota reminder. 
     215    - SNMP tools (specifically the snmpget command) if you prefer to 
     216      use your own script to request query printers. 
    214217    - Netatalk (specifically the pap command) if you plan to 
    215218      request your printer's lifetime page counter via AppleTalk. 
     
    221224      if you plan to use OpenLDAP as the Quota Storage backend. 
    222225     
    223   On Intel i386 architecture, and for performance reasons if you  
    224   print in PCL5 or PCL6 format, it is strongly suggested that you  
    225   install the Python accelerator Psyco, available at : 
     226  On Intel i386 architecture, and for performance reasons, it is 
     227  strongly suggested that you install the Python accelerator Psyco,  
     228  available at : 
    226229   
    227230      http://psyco.sourceforge.net 
  • pykota/trunk/setup.py

    r1758 r1771  
    2424# 
    2525# $Log$ 
     26# Revision 1.53  2004/10/04 21:25:29  jalet 
     27# dumpykota can now output datas in the XML format 
     28# 
    2629# Revision 1.52  2004/09/30 09:52:45  jalet 
    2730# Initial release of autopykota. Reading help or manpage is greatly 
     
    429432                       ("Python-OSD", "pyosd", "Python-OSD is recommended if you plan to use the X Window On Screen Display\nprint quota reminder named pykosd."), 
    430433                       ("Python-SNMP", "pysnmp", "Python-SNMP is recommended if you plan to use hardware\naccounting with printers which support SNMP.\nSee http://pysnmp.sf.net"), 
     434                       ("Python-JAXML", "jaxml", "Python-JAXML is recommended if you plan to dump datas in the XML format.\nSee http://www.librelogiciel.com/software/"), 
    431435                     ] 
    432436    commandstocheck = [("SNMP Tools", "snmpget", "SNMP Tools are needed if you want to use SNMP enabled printers."), ("Netatalk", "pap", "Netatalk is needed if you want to use AppleTalk enabled printers.")]