Exemplo n.º 1
0
def reformatFunctions(file):

    text_file = os.path.splitext(file)[0] + '.txt'
    local_file = os.path.split(file)[1]

    if not newer(file, text_file):
        return

    pf = PickleFile(file)
    functions = pf.read()

    if local_file.count('.') == 2:
        # Core functions
        label = 'wx'
    else:
        label = '.'.join(local_file.split('.')[0:2])

    names = list(functions.keys())
    names = [name.lower() for name in names]
    names.sort()

    text = templates.TEMPLATE_FUNCTION_SUMMARY % (label, label)

    letters = []
    for fun in names:
        upper = fun[0].upper()
        if upper not in letters:
            letters.append(upper)

    text += '  |  '.join(
        [':ref:`%s <%s %s>`' % (letter, label, letter) for letter in letters])
    text += '\n\n\n'

    names = list(functions.keys())
    names = sorted(names, key=str.lower)
    imm = ItemModuleMap()

    for letter in letters:
        text += '.. _%s %s:\n\n%s\n^\n\n' % (label, letter, letter)
        for fun in names:
            if fun[0].upper() != letter:
                continue

            text += '* :func:`%s`\n' % imm.get_fullname(fun)

        text += '\n\n'

    text += 'Functions\n=============\n\n'

    for fun in names:
        text += functions[fun] + '\n'

    writeIfChanged(text_file, text)
Exemplo n.º 2
0
def reformatFunctions(file):

    text_file = os.path.splitext(file)[0] + '.txt'
    local_file = os.path.split(file)[1]

    if not newer(file, text_file):
        return

    pf = PickleFile(file)
    functions = pf.read()

    if local_file.count('.') == 2:
        # Core functions
        label = 'wx'
    else:
        label = '.'.join(local_file.split('.')[0:2])

    names = list(functions.keys())
    names = [name.lower() for name in names]
    names.sort()

    text = templates.TEMPLATE_FUNCTION_SUMMARY % (label, label)

    letters = []
    for fun in names:
        upper = fun[0].upper()
        if upper not in letters:
            letters.append(upper)

    text += '  |  '.join([':ref:`%s <%s %s>`'%(letter, label, letter) for letter in letters])
    text += '\n\n\n'

    names = list(functions.keys())
    names = sorted(names, key=str.lower)
    imm = ItemModuleMap()

    for letter in letters:
        text += '.. _%s %s:\n\n%s\n^\n\n'%(label, letter, letter)
        for fun in names:
            if fun[0].upper() != letter:
                continue

            text += '* :func:`%s`\n' % imm.get_fullname(fun)

        text += '\n\n'

    text += 'Functions\n=============\n\n'

    for fun in names:
        text += functions[fun] + '\n'

    writeIfChanged(text_file, text)
Exemplo n.º 3
0
def wx2Sphinx(name):
    """
    Converts a wxWidgets specific string into a Phoenix-ReST-ready string.

    :param string `name`: any string.
    """
    from etgtools.tweaker_tools import removeWxPrefix

    if '<' in name:
        name = name[0:name.index('<')]

    name = name.strip()
    newname = fullname = removeWxPrefix(name)

    if '.' in newname and len(newname) > 3:
        lookup, remainder = newname.split('.')
        remainder = '.%s' % remainder
    else:
        lookup = newname
        remainder = ''

    from etgtools.item_module_map import ItemModuleMap
    imm = ItemModuleMap()
    if lookup in imm:
        fullname = imm[lookup] + lookup + remainder

    return newname, fullname
Exemplo n.º 4
0
def convertToPython(text):
    """
    Converts the input `text` into a more ReSTified version of it.

    This involves the following steps:

    1. Any C++ specific declaration (like ``unsigned``, ``size_t`` and so on
       is removed.
    2. Lines starting with "Include file" or "#include" are ignored.
    3. Uppercase constants (i.e., like ID_ANY, HORIZONTAL and so on) are converted
       into inline literals (i.e., ``ID_ANY``, ``HORIZONTAL``).
    4. The "wx" prefix is removed from all the words in the input `text`.  #***

    :param string `text`: any string.

    :rtype: `string`
    """
    from etgtools.tweaker_tools import removeWxPrefix
    from etgtools.item_module_map import ItemModuleMap

    newlines = []
    unwanted = ['Include file', '#include']

    for line in text.splitlines():

        newline = []

        for remove in unwanted:
            if remove in line:
                line = line[0:line.index(remove)]
                break

        spacer = ' ' * (len(line) - len(line.lstrip()))

        line = replaceCppItems(line)

        for word in RE_KEEP_SPACES.split(line):

            if word == VERSION:
                newline.append(word)
                continue

            newword = word
            for s in PUNCTUATION:
                newword = newword.replace(s, "")

            if newword in VALUE_MAP:
                word = word.replace(newword, VALUE_MAP[newword])
                newline.append(word)
                continue

            if newword not in IGNORE and not newword.startswith('wx.'):
                word = removeWxPrefix(word)
                newword = removeWxPrefix(newword)

            if "::" in word and not word.endswith("::"):
                # Bloody SetCursorEvent...
                word = word.replace("::wx", ".")  # ***
                word = word.replace("::", ".")
                word = "`%s`" % word
                newline.append(word)
                continue

            if (newword.upper() == newword and newword not in PUNCTUATION
                    and newword not in IGNORE and len(newword.strip()) > 1
                    and not isNumeric(newword)
                    and newword not in ['DC', 'GCDC']):

                if '``' not in newword and '()' not in word and '**' not in word:
                    word = word.replace(
                        newword,
                        "``%s``" % ItemModuleMap().get_fullname(newword))

            word = word.replace('->', '.')
            newline.append(word)

        newline = spacer + ''.join(newline)
        newline = newline.replace(':see:', '.. seealso::')
        newline = newline.replace(':note:', '.. note::')
        newlines.append(newline)

    formatted = "\n".join(newlines)
    formatted = formatted.replace('\\', '\\\\')

    return formatted
Exemplo n.º 5
0
def makeModuleIndex(sphinxDir, file):

    text_file = os.path.splitext(file)[0] + '.txt'
    local_file = os.path.split(file)[1]

    if not newer(file, text_file):
        return

    pf = PickleFile(file)
    classes = pf.read()
    module_docstring = classes.get(DOCSTRING_KEY)
    if module_docstring is not None:
        del classes[DOCSTRING_KEY]

    if local_file.startswith('wx.1'):
        # Core functions
        label = 'wx'
        module = 'wx'
        enumDots = 2
        # Take care to get only files starting with "wx.UpperName", not
        # "wx.lower.UpperName". This is so we don't put all the enums in the
        # submodules in the core wx module too.
        # TODO: This may not work on case-insensitive file systems, check it.
        enum_files = glob.glob(sphinxDir + '/wx.[A-Z]*.enumeration.txt')
    else:
        label = '.'.join(local_file.split('.')[0:2])
        module = label
        enumDots = 3
        enum_files = glob.glob(sphinxDir + '/%s*.enumeration.txt' % module)

    enum_base = [os.path.split(os.path.splitext(enum)[0])[1] for enum in enum_files]

    imm = ItemModuleMap()
    names = list(classes.keys())
    names.sort(key=lambda n: imm.get_fullname(n))

    # Workaround to sort names in a case-insensitive way
    lower_to_name = {}
    for name in names:
        lower_to_name[name.lower()] = name

    text = ''
    if module:
        text += '\n\n.. module:: %s\n\n' % module

    text += templates.TEMPLATE_CLASS_INDEX % (label, module_docstring)

    text += 80*'=' + ' ' + 80*'=' + '\n'
    text += '%-80s **Short Description**\n' % '**Class**'
    text += 80*'=' + ' ' + 80*'=' + '\n'

    lower_names = list(lower_to_name.keys())
    lower_names.sort()

    for lower in lower_names:
        cls = lower_to_name[lower]
        out = classes[cls]
        if '=====' in out:
            out = ''
        text += '%-80s %s\n' % (':ref:`~%s`' % wx2Sphinx(cls)[1], out)

    text += 80*'=' + ' ' + 80*'=' + '\n\n'

    contents = []
    for lower in lower_names:
        cls = lower_to_name[lower]
        contents.append(wx2Sphinx(cls)[1])

    for enum in enum_base:
        if enum.count('.') == enumDots:
            contents.append(enum)

    contents.sort()

    # Are there functions for this module too?
    functionsFile = os.path.join(sphinxDir, module + '.functions.pkl')
    if os.path.exists(functionsFile):
        pf = PickleFile(functionsFile)
        functions = list(pf.read().keys())
        functions.sort(key=lambda n: imm.get_fullname(n))

        pf = PickleFile(os.path.join(SPHINXROOT, 'function_summary.pkl'))
        function_summaries = pf.read()

        text += templates.TEMPLATE_MODULE_FUNCTION_SUMMARY
        text += 80*'=' + ' ' + 80*'=' + '\n'
        text += '%-80s **Short Description**\n' % '**Function**'
        text += 80*'=' + ' ' + 80*'=' + '\n'

        for func_name in functions:
            fullname = imm.get_fullname(func_name)
            doc = function_summaries.get(fullname, '')
            text += '%-80s %s\n' % (':func:`~%s`' % fullname, doc)

        text += 80 * '=' + ' ' + 80 * '=' + '\n\n'
        contents.append(module + '.functions')

    toctree = ''
    for item in contents:
        toctree += '   %s\n' % item

    text += templates.TEMPLATE_TOCTREE % toctree

    writeIfChanged(text_file, text)