Ejemplo n.º 1
0
 def WriteCustomInfoInXMLFormat(self, outfile, indent):
   if self.lower_bound is not None:
     _helpers.WriteSimpleXMLElement(outfile, 'lower_bound', self.lower_bound,
                                    indent)
   if self.upper_bound is not None:
     _helpers.WriteSimpleXMLElement(outfile, 'upper_bound', self.upper_bound,
                                    indent)
Ejemplo n.º 2
0
 def WriteCustomInfoInXMLFormat(self, outfile, indent):
     BaseListParser.WriteCustomInfoInXMLFormat(self, outfile, indent)
     separators = list(string.whitespace)
     separators.sort()
     for ws_char in string.whitespace:
         _helpers.WriteSimpleXMLElement(outfile, 'list_separator',
                                        repr(ws_char), indent)
Ejemplo n.º 3
0
    def WriteHelpInXMLFormat(self, outfile=None):
        """Outputs flag documentation in XML format.

    NOTE: We use element names that are consistent with those used by
    the C++ command-line flag library, from
    http://code.google.com/p/google-gflags
    We also use a few new elements (e.g., <key>), but we do not
    interfere / overlap with existing XML elements used by the C++
    library.  Please maintain this consistency.

    Args:
      outfile: File object we write to.  Default None means sys.stdout.
    """
        outfile = outfile or sys.stdout

        outfile.write('<?xml version=\"1.0\"?>\n')
        outfile.write('<AllFlags>\n')
        indent = '  '
        _helpers.WriteSimpleXMLElement(outfile, 'program',
                                       os.path.basename(sys.argv[0]), indent)

        usage_doc = sys.modules['__main__'].__doc__
        if not usage_doc:
            usage_doc = '\nUSAGE: %s [flags]\n' % sys.argv[0]
        else:
            usage_doc = usage_doc.replace('%s', sys.argv[0])
        _helpers.WriteSimpleXMLElement(outfile, 'usage', usage_doc, indent)

        # Get list of key flags for the main module.
        key_flags = self._GetKeyFlagsForModule(_helpers.GetMainModule())

        # Sort flags by declaring module name and next by flag name.
        flags_by_module = self.FlagsByModuleDict()
        all_module_names = list(flags_by_module.keys())
        all_module_names.sort()
        for module_name in all_module_names:
            flag_list = [(f.name, f) for f in flags_by_module[module_name]]
            flag_list.sort()
            for unused_flag_name, flag in flag_list:
                is_key = flag in key_flags
                flag.WriteInfoInXMLFormat(outfile,
                                          module_name,
                                          is_key=is_key,
                                          indent=indent)

        outfile.write('</AllFlags>\n')
        outfile.flush()
Ejemplo n.º 4
0
 def WriteCustomInfoInXMLFormat(self, outfile, indent):
   BaseListParser.WriteCustomInfoInXMLFormat(self, outfile, indent)
   separators = list(string.whitespace)
   if self._comma_compat:
     separators.append(',')
   separators.sort()
   for sep_char in separators:
     _helpers.WriteSimpleXMLElement(outfile, 'list_separator', repr(sep_char),
                                    indent)
Ejemplo n.º 5
0
    def WriteInfoInXMLFormat(self,
                             outfile,
                             module_name,
                             is_key=False,
                             indent=''):
        """Writes common info about this flag, in XML format.

    This is information that is relevant to all flags (e.g., name,
    meaning, etc.).  If you defined a flag that has some other pieces of
    info, then please override _WriteCustomInfoInXMLFormat.

    Please do NOT override this method.

    Args:
      outfile: File object we write to.
      module_name: A string, the name of the module that defines this flag.
      is_key: A boolean, True iff this flag is key for main module.
      indent: A string that is prepended to each generated line.
    """
        outfile.write(indent + '<flag>\n')
        inner_indent = indent + '  '
        if is_key:
            _helpers.WriteSimpleXMLElement(outfile, 'key', 'yes', inner_indent)
        _helpers.WriteSimpleXMLElement(outfile, 'file', module_name,
                                       inner_indent)
        # Print flag features that are relevant for all flags.
        _helpers.WriteSimpleXMLElement(outfile, 'name', self.name,
                                       inner_indent)
        if self.short_name:
            _helpers.WriteSimpleXMLElement(outfile, 'short_name',
                                           self.short_name, inner_indent)
        if self.help:
            _helpers.WriteSimpleXMLElement(outfile, 'meaning', self.help,
                                           inner_indent)
        # The default flag value can either be represented as a string like on the
        # command line, or as a Python object.  We serialize this value in the
        # latter case in order to remain consistent.
        if self.serializer and not isinstance(self.default, str):
            if self.default is not None:
                default_serialized = self.serializer.Serialize(self.default)
            else:
                default_serialized = ''
        else:
            default_serialized = self.default
        _helpers.WriteSimpleXMLElement(outfile, 'default', default_serialized,
                                       inner_indent)
        _helpers.WriteSimpleXMLElement(outfile, 'current', self.value,
                                       inner_indent)
        _helpers.WriteSimpleXMLElement(outfile, 'type', self.Type(),
                                       inner_indent)
        # Print extra flag features this flag may have.
        self._WriteCustomInfoInXMLFormat(outfile, inner_indent)
        outfile.write(indent + '</flag>\n')
Ejemplo n.º 6
0
 def _WriteCustomInfoInXMLFormat(self, outfile, indent):
   if hasattr(self.parser, 'enum_values'):
     for enum_value in self.parser.enum_values:
       _helpers.WriteSimpleXMLElement(outfile, 'enum_value',
                                      enum_value, indent)
Ejemplo n.º 7
0
 def WriteCustomInfoInXMLFormat(self, outfile, indent):
   BaseListParser.WriteCustomInfoInXMLFormat(self, outfile, indent)
   _helpers.WriteSimpleXMLElement(outfile, 'list_separator', repr(','), indent)