Package doapfiend :: Package plugins :: Module xml
[hide private]
[frames] | no frames]

Source Code for Module doapfiend.plugins.xml

 1  #!/usr/bin/env python 
 2   
 3  # pylint: disable-msg=W0221,R0201 
 4   
 5  """ 
 6   
 7  Serialize DOAP as XML/RDF 
 8  ========================= 
 9   
10  This plugin outputs DOAP in RDF/XML 
11  It basically does nothing because all DOAP today is in RDF/XML. 
12  In the future this may take N3, Turtle, RDFa etc. and convert it to RDF/XML. 
13   
14  """ 
15   
16  __docformat__ = 'epytext' 
17   
18   
19  from doapfiend.plugins.base import Plugin 
20   
21   
22 -class OutputPlugin(Plugin):
23 24 """Class for formatting DOAP output""" 25 26 #This will be the opt_parser option (--xml) in the output group 27 name = "xml" 28 enabled = False 29 enable_opt = None 30
31 - def __init__(self):
32 '''Setup RDF/XML OutputPlugin class''' 33 super(OutputPlugin, self).__init__() 34 self.options = None
35
36 - def add_options(self, parser, output, search):
37 """Add plugin's options to doapfiend's opt parser""" 38 output.add_option('-x', '--%s' % self.name, 39 action='store_true', 40 dest=self.enable_opt, 41 help='Output DOAP as RDF/XML') 42 return parser, output, search
43
44 - def serialize(self, doap_xml, color=False):
45 ''' 46 Serialize RDF/XML DOAP as N3 syntax 47 48 @param doap_xml: DOAP in RDF/XML serialization 49 @type doap_xml: string 50 51 @rtype: unicode 52 @returns: DOAP 53 ''' 54 55 if hasattr(self.options, 'no_color'): 56 color = not self.options.no_color 57 if color: 58 #pygments plugin fools pylint 59 # pylint: disable-msg=E0611 60 try: 61 from pygments import highlight 62 from pygments.lexers import XmlLexer 63 from pygments.formatters import TerminalFormatter 64 except ImportError: 65 return doap_xml 66 return highlight(doap_xml, 67 XmlLexer(), 68 TerminalFormatter(full=False)) 69 else: 70 return doap_xml
71