Beispiel #1
0
def config_file_as_text():

    import Ganga.Utility.external.textwrap as textwrap

    text = ''

    sections = sorted(stripProxy(config).keys())
    INDENT = "#  "
    INDENT_value = "# "
    for p in sections:

        sect = stripProxy(config)[p]
        if not sect.cfile:
            continue

        text += "\n"
        text += "#=======================================================================\n"
        text += textwrap.fill(sect.docstring.strip(), width=80,
                              initial_indent=INDENT, subsequent_indent=INDENT) + "\n"
        text += "[%s]\n\n" % p

        opts = sorted(sect.options.keys())
        for o in opts:
            if sect.options[o].cfile:
                text += ""
                text += textwrap.fill(sect.options[o].docstring.strip(
                ), width=80, initial_indent=INDENT, subsequent_indent=INDENT) + "\n"

                examples = sect.options[o].examples
                if examples:
                    text += INDENT + "Examples:\n"
                    for e in examples.splitlines():
                        text += INDENT + "  " + e.strip() + "\n"
                if sect.getEffectiveLevel(o) == 0:
                    value = sect[o]
                    def_value = sect.options[o].default_value
                    try:
                        lines = value.splitlines()
                        def_lines = def_value.splitlines()
                        if len(lines) > 1:
                            value = "\n# ".join(lines)
                            def_value = "\n# ".join(def_lines)
                    except AttributeError as err:
                        print("Attrib Err: %s" % str(err))
                        pass
                    text += '#%s = %s\n' % (o, def_value)
                    text += '%s = %s\n\n' % (o, value)
                else:
                    value = sect.getEffectiveOption(o)
                    if isinstance(value, str):
                        lines = value.splitlines()
                        if len(lines) > 1:
                            value = "\n# ".join(lines)
                    text += '#%s = %s\n\n' % (o, value)

    return text
Beispiel #2
0
    def getString(self):

        maxitem = 0
        for it in self.items:
            if len(it) > maxitem:
                maxitem = len(it)

        indent = " " * (len(self.head) / 2)

        buf = self.head + "\n"

        import Ganga.Utility.external.textwrap as textwrap

        for it, d in zip(self.items, self.desc):
            if not self.linesep is None:
                buf += self.linesep + "\n"
            buf2 = "%-*s%s%s" % (maxitem, it, self.sep, d)
            buf += (
                textwrap.fill(
                    buf2,
                    width=self.width,
                    initial_indent=indent,
                    subsequent_indent=" " * (maxitem + len(self.sep)) + indent,
                )
                + "\n"
            )

        return buf
Beispiel #3
0
    def _display(self, colour):
        from Ganga.Utility.ColourText import ANSIMarkup, NoMarkup, getColour, Foreground, Effects
        import Ganga.Utility.external.textwrap as textwrap

        if colour:
            markup = ANSIMarkup()
        else:
            markup = NoMarkup()

        fg = Foreground()
        fx = Effects()

        display_config = getConfig('Display')

        name_colour = getColour(display_config['config_name_colour'])
        docstring_colour = getColour(
            display_config['config_docstring_colour'])  # fg.boldgrey
        value_colour = getColour(
            display_config['config_value_colour'])  # fx.normal

        levels = ['**', '* ', '  ']
        levels = map(lambda x: markup(x, fg.red), levels)
        from cStringIO import StringIO
        sio = StringIO()
        sio.write('%s' % markup(stripProxy(self).name, name_colour) +
                  ' : ' + markup(stripProxy(self).docstring, docstring_colour) + '\n')
        opts = sorted(stripProxy(self).options.keys())
        INDENT = '     ' * 2
        for o in opts:
            sio.write(levels[stripProxy(self).getEffectiveLevel(
                o)] + '   ' + markup(o, name_colour) + ' = ' + markup(repr(stripProxy(self)[o]), value_colour) + '\n')
            sio.write(textwrap.fill(markup(stripProxy(self).options[o].docstring.strip(
            ), docstring_colour), width=80, initial_indent=INDENT, subsequent_indent=INDENT) + '\n')
            typelist = stripProxy(self).options[o].typelist
            if not typelist:
                typedesc = 'Type: ' + \
                    str(type(stripProxy(self).options[o].default_value))
            else:
                typedesc = 'Allowed types: ' + \
                    str([t.split('.')[-1] for t in typelist])
            sio.write(markup(INDENT + typedesc, docstring_colour) + '\n')
            filter = stripProxy(self).options[o].filter
            if filter:
                filter_doc = filter.__doc__
                if not filter_doc:
                    filter_doc = "undocumented"
                sio.write(
                    markup(INDENT + "Filter: " + filter_doc, docstring_colour) + '\n')
            examples = stripProxy(self).options[o].examples
            if examples:
                sio.write(
                    markup(INDENT + "Examples:", docstring_colour) + '\n')
                for e in examples.splitlines():
                    sio.write(
                        markup(INDENT + e.strip(), docstring_colour) + '\n')

        return sio.getvalue()
Beispiel #4
0
def config_file_as_text():

    import Ganga.Utility.external.textwrap as textwrap

    text = ''

    sections = config._impl.keys()
    sections.sort()
    INDENT = "#  "      
    INDENT_value = "# "      
    for p in sections:

        sect = config._impl[p]
        if not sect.cfile:
            continue

        text += "\n"
        text += "#=======================================================================\n"
	text += textwrap.fill(sect.docstring.strip(),width=80, initial_indent=INDENT,subsequent_indent=INDENT)+"\n"
        text += "[%s]\n\n"%p

        opts = sect.options.keys()
        opts.sort()
        for o in opts:
            if sect.options[o].cfile:
                text += ""
                text += textwrap.fill(sect.options[o].docstring.strip(),width=80, initial_indent=INDENT,subsequent_indent=INDENT)+"\n"

                examples = sect.options[o].examples
                if examples:
                    text += INDENT+"Examples:\n"
                    for e in examples.splitlines():
                        text += INDENT+"  "+e.strip()+"\n"
                value = sect.options[o].default_value
		try:
		    lines = value.splitlines()
		    if len(lines)>1:
		        value = "\n# ".join(lines)
		except:
		    pass
                text +='#%s = %s\n\n'%(o,value)
 
    return text
Beispiel #5
0
    def getString(self):

        maxitem = 0
        for it in self.items:
            if len(it) > maxitem:
                maxitem = len(it)

        indent = ' ' * int(self.head_size*0.5)

        buf = self.head + '\n'

        for it, d in zip(self.items, self.desc):
            if self.linesep is not None:
                buf += self.linesep + '\n'
            buf2 = '%-*s%s%s' % (maxitem, it, self.sep, d)
            buf += textwrap.fill(buf2, width=self.width, initial_indent=indent,
                                 subsequent_indent=' ' * (maxitem + self.sep_size) + indent) + '\n'

        return buf