def build_link_map(directory):
    # find all html files
    html_files = []
    for root, dirnames, filenames in os.walk(directory):
        for filename in fnmatch.filter(filenames, '*.html'):
            html_files.append(os.path.join(root, filename))

    link_map = LinkMap()

    for fn in html_files:
        f = open(fn, "r")
        text = f.read()
        f.close()

        m = re.search('<script>[^<]*mw\.config\.set([^<]*wgPageName[^<]*)</script>', text)
        if not m:
            continue
        text = m.group(1)
        text = re.sub('\s*', '', text)
        m = re.search('"wgPageName":"([^"]*)"', text)
        if not m:
            continue

        title = m.group(1)

        target = os.path.relpath(os.path.abspath(fn), os.path.abspath(directory))
        link_map.add_link(title, target)
    return link_map
Example #2
0
def main():
    parser = argparse.ArgumentParser(prog='index2doxygen-tag')
    parser.add_argument('link_map_fn',
                        type=str,
                        help='Path to index file to process')

    parser.add_argument(
        'in_fn',
        type=str,
        help='the file name of the link map or \'web\' if no link remap '
        'should be done')

    parser.add_argument('chapters_fn',
                        type=str,
                        help='the file name of the source file')

    parser.add_argument('dest_fn',
                        type=str,
                        help='the file name of the destination file')

    args = parser.parse_args()

    link_map_fn = args.link_map_fn
    in_fn = args.in_fn
    chapters_fn = args.chapters_fn
    dest_fn = args.dest_fn

    out_f = open(dest_fn, 'w', encoding='utf-8')

    link_map = None
    if link_map_fn != 'web':
        link_map = LinkMap()
        link_map.read(link_map_fn)

    ns_map = Item()

    out_f.write('<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>\n')
    out_f.write('<tagfile>\n')

    with open(chapters_fn, encoding='utf-8') as chapters_f:
        chapters_tree = etree.parse(chapters_f)
        for header_chapter in \
                chapters_tree.getroot().findall(".//*[@name='Headers']/*"):
            out_f.write('  <compound kind="file">\n')
            out_f.write('    <name>{0}</name>\n'.format(
                header_chapter.attrib['name']))
            out_f.write('    <filename>{0}</filename>\n'.format(
                header_chapter.attrib['link']))
            out_f.write('    <namespace>std</namespace>\n')
            out_f.write('  </compound>\n')

    tr = Index2DoxygenTag(ns_map)
    tr.transform_file(in_fn)
    print_map(out_f, link_map, ns_map)
    out_f.write('''</tagfile>
''')
def main():
    parser = argparse.ArgumentParser(prog='index2doxygen-tag')
    parser.add_argument(
        'link_map_fn', type=str,
        help='Path to index file to process')

    parser.add_argument(
        'in_fn', type=str,
        help='the file name of the link map or \'web\' if no link remap '
             'should be done')

    parser.add_argument(
        'chapters_fn', type=str,
        help='the file name of the source file')

    parser.add_argument(
        'dest_fn', type=str,
        help='the file name of the destination file')

    args = parser.parse_args()

    link_map_fn = args.link_map_fn
    in_fn = args.in_fn
    chapters_fn = args.chapters_fn
    dest_fn = args.dest_fn

    out_f = open(dest_fn, 'w', encoding='utf-8')

    link_map = None
    if link_map_fn != 'web':
        link_map = LinkMap()
        link_map.read(link_map_fn)

    ns_map = Item()

    out_f.write('<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>\n')
    out_f.write('<tagfile>\n')

    with open(chapters_fn, encoding='utf-8') as chapters_f:
        chapters_tree = etree.parse(chapters_f)
        for header_chapter in \
                chapters_tree.getroot().findall(".//*[@name='Headers']/*"):
            out_f.write('  <compound kind="file">\n')
            out_f.write('    <name>{0}</name>\n'.format(
                header_chapter.attrib['name']))
            out_f.write('    <filename>{0}</filename>\n'.format(
                header_chapter.attrib['link']))
            out_f.write('    <namespace>std</namespace>\n')
            out_f.write('  </compound>\n')

    tr = Index2DoxygenTag(ns_map)
    tr.transform_file(in_fn)
    print_map(out_f, link_map, ns_map)
    out_f.write('''</tagfile>
''')
Example #4
0
def create_app(link_list_path=None,
               local_root=None,
               host_url=None,
               secret_key=None):
    link_list_path = link_list_path or _DEFAULT_LINKS_FILE_PATH
    link_map = LinkMap(link_list_path)
    local_static_app = None
    if local_root:
        local_static_app = StaticApplication(local_root)
    host_url = (host_url or 'localhost:5000').rstrip('/') + '/'
    full_host_url = 'http://' + host_url
    resources = {
        'link_map': link_map,
        'local_root': local_root,
        'local_static_app': local_static_app,
        'host_url': host_url,
        'full_host_url': full_host_url
    }

    pdm = PostDataMiddleware({
        'target_url': unicode,
        'target_file': unicode,
        'alias': unicode,
        'max_count': int,
        'expiry_time': unicode
    })
    submit_route = POST('/submit',
                        add_entry,
                        add_entry_render,
                        middlewares=[pdm])

    routes = [('/', home, 'home.html'), submit_route, ('/<alias>', use_entry)]
    scm = SignedCookieMiddleware(secret_key=secret_key)
    scp = SimpleContextProcessor('local_root', 'full_host_url')
    middlewares = [scm, scp]

    arf = AshesRenderFactory(_CUR_PATH, keep_whitespace=False)
    app = Application(routes, resources, middlewares, arf)
    return app
Example #5
0
 * the file name of the source file
 * the file name of the destination file
''')
    sys.exit(1)

link_map_fn = sys.argv[1]
in_fn = sys.argv[2]
dest_fn = sys.argv[3]

indent_level_inc = 2

out_f = open(dest_fn, 'w')

link_map = None
if link_map_fn != 'web':
    link_map = LinkMap()
    link_map.read(link_map_fn)


class ItemKind:
    VARIABLE = 0,
    FUNCTION = 1,
    CLASS = 2,
    TYPEDEF = 3,
    NAMESPACE = 4


class Item:
    def __init__(self):
        self.name = ""
        self.full_name = ""
'''

import lxml.etree as e
from link_map import LinkMap
import sys

if len(sys.argv) != 3:
    print('''Please provide the following 2 argument:
 * the file name of the source file
 * the file name of the destination file
''')

in_fn = sys.argv[1]
out_fn = sys.argv[2]

mapping = LinkMap()
mapping.read('output/link-map.xml')

root = e.parse(in_fn)

el_mod = root.xpath('//*[@link]')
for el in el_mod:
    link = el.get('link')
    target = mapping.get_dest(link)
    if target == None:
        print('Could not find ' + link + ' in mapping')
        target = '404'
    el.set('link', target)

out_f = open(out_fn, 'w')
out_f.write(e.tostring(root, encoding='unicode', pretty_print=True))
"""
    )
    sys.exit(1)

link_map_fn = sys.argv[1]
in_fn = sys.argv[2]
chapters_fn = sys.argv[3]
dest_fn = sys.argv[4]

indent_level_inc = 2

out_f = open(dest_fn, "w")

link_map = None
if link_map_fn != "web":
    link_map = LinkMap()
    link_map.read(link_map_fn)


class ItemKind:
    VARIABLE = (0,)
    FUNCTION = (1,)
    CLASS = (2,)
    TYPEDEF = (3,)
    NAMESPACE = 4


@total_ordering
class Item:
    def __init__(self):
        self.name = ""