Beispiel #1
0
def build_folder(tree, conn, folder, indexed_files, indexed_folders):
    """Build an HTML index file for a single folder."""
    # Create the subfolder if it doesn't exist:
    ensure_folder(os.path.join(tree.target_folder, folder))

    # Build the folder listing:
    # Name is either basename (or if that is "" name of tree)
    name = os.path.basename(folder) or tree.name

    # Generate list of folders and their mod dates:
    folders = [('folder',
                f,
                datetime.fromtimestamp(stat(os.path.join(tree.source_folder,
                                                         folder,
                                                         f)).st_mtime),
                # TODO: DRY with Flask route. Use url_for:
                _join_url(tree.name, 'source', folder, f))
               for f in indexed_folders]

    # Generate list of files:
    files = []
    for f in indexed_files:
        # Get file path on disk
        path = os.path.join(tree.source_folder, folder, f)
        file_info = stat(path)
        files.append((dxr.mime.icon(path),
                      f,
                      datetime.fromtimestamp(file_info.st_mtime),
                      file_info.st_size,
                      _join_url(tree.name, 'source', folder, f)))

    # Lay down the HTML:
    jinja_env = load_template_env(tree.config.temp_folder,
                                  tree.config.dxrroot)
    dst_path = os.path.join(tree.target_folder,
                            folder,
                            tree.config.directory_index)

    _fill_and_write_template(
        jinja_env,
        'folder.html',
        dst_path,
        {# Common template variables:
         'wwwroot': tree.config.wwwroot,
         'tree': tree.name,
         'tree_tuples': [(t.name,
                          browse_url(t.name, tree.config.wwwroot, folder),
                          t.description)
                         for t in tree.config.sorted_tree_order],
         'generated_date': tree.config.generated_date,
         'paths_and_names': linked_pathname(folder, tree.name),
         'filters': filter_menu_items(tree.config.filter_language),
         # Autofocus only at the root of each tree:
         'should_autofocus_query': folder == '',

         # Folder template variables:
         'name': name,
         'path': folder,
         'folders': folders,
         'files': files})
Beispiel #2
0
def htmlify(tree, conn, icon, path, text, dst_path, plugins):
    """ Build HTML for path, text save it to dst_path """
    # Create htmlifiers for this source
    htmlifiers = []
    for plugin in plugins:
        htmlifier = plugin.htmlify(path, text)
        if htmlifier:
            htmlifiers.append(htmlifier)
    # Load template
    env = load_template_env(tree.config.temp_folder)

    arguments = {
        # Set common template variables
        'wwwroot':
        tree.config.wwwroot,
        'tree':
        tree.name,
        'tree_tuples': [(t.name, browse_url(t.name, tree.config.wwwroot,
                                            path), t.description)
                        for t in tree.config.sorted_tree_order],
        'generated_date':
        tree.config.generated_date,
        'filters':
        filter_menu_items(tree.config.filter_language),

        # google analytics
        'google_analytics_key':
        tree.config.google_analytics_key,

        # Set file template variables
        'paths_and_names':
        linked_pathname(path, tree.name),
        'icon':
        icon,
        'path':
        path,
        'name':
        os.path.basename(path),

        # Someday, it would be great to stream this and not concretize the
        # whole thing in RAM. The template will have to quit looping through
        # the whole thing 3 times.
        'lines':
        list(
            lines_and_annotations(
                build_lines(text, htmlifiers, tree.source_encoding),
                htmlifiers)),
        'sections':
        build_sections(tree, conn, path, text, htmlifiers)
    }

    _fill_and_write_template(env, 'file.html', dst_path, arguments)
Beispiel #3
0
def htmlify(tree, conn, icon, path, text, dst_path, plugins):
    """ Build HTML for path, text save it to dst_path """
    # Create htmlifiers for this source
    htmlifiers = []
    for plugin in plugins:
        htmlifier = plugin.htmlify(path, text)
        if htmlifier:
            htmlifiers.append(htmlifier)
    # Load template
    env = load_template_env(tree.config.temp_folder)

    arguments = {
        # Set common template variables
        'wwwroot': tree.config.wwwroot,
        'tree': tree.name,
        'tree_tuples': [(t.name,
                         browse_url(t.name, tree.config.wwwroot, path),
                         t.description)
                        for t in tree.config.sorted_tree_order],
        'generated_date': tree.config.generated_date,
        'filters': filter_menu_items(tree.config.filter_language),

        # google analytics
        'google_analytics_key': tree.config.google_analytics_key,

        # Set file template variables
        'paths_and_names': linked_pathname(path, tree.name),
        'icon': icon,
        'path': path,
        'name': os.path.basename(path),

        # Someday, it would be great to stream this and not concretize the
        # whole thing in RAM. The template will have to quit looping through
        # the whole thing 3 times.
        'lines': list(lines_and_annotations(build_lines(text, htmlifiers,
                                                        tree.source_encoding),
                                            htmlifiers)),

        'sections': build_sections(tree, conn, path, text, htmlifiers)
    }

    _fill_and_write_template(env, 'file.html', dst_path, arguments)
Beispiel #4
0
def build_folder(tree, conn, folder, indexed_files, indexed_folders):
    """Build an HTML index file for a single folder."""
    # Create the subfolder if it doesn't exist:
    ensure_folder(os.path.join(tree.target_folder, folder))

    # Build the folder listing:
    # Name is either basename (or if that is "" name of tree)
    name = os.path.basename(folder) or tree.name

    # Generate list of folders and their mod dates:
    folders = [
        (
            'folder',
            f,
            datetime.fromtimestamp(
                stat(os.path.join(tree.source_folder, folder, f)).st_mtime),
            # TODO: DRY with Flask route. Use url_for:
            _join_url(tree.name, 'source', folder, f)) for f in indexed_folders
    ]

    # Generate list of files:
    files = []
    for f in indexed_files:
        # Get file path on disk
        path = os.path.join(tree.source_folder, folder, f)
        file_info = stat(path)
        files.append(
            (dxr.mime.icon(path), f,
             datetime.fromtimestamp(file_info.st_mtime), file_info.st_size,
             _join_url(tree.name, 'source', folder, f)))

    # Lay down the HTML:
    jinja_env = load_template_env(tree.config.temp_folder, tree.config.dxrroot)
    dst_path = os.path.join(tree.target_folder, folder,
                            tree.config.directory_index)

    _fill_and_write_template(
        jinja_env,
        'folder.html',
        dst_path,
        {  # Common template variables:
            'wwwroot':
            tree.config.wwwroot,
            'tree':
            tree.name,
            'tree_tuples':
            [(t.name, browse_url(t.name, tree.config.wwwroot,
                                 folder), t.description)
             for t in tree.config.sorted_tree_order],
            'generated_date':
            tree.config.generated_date,
            'paths_and_names':
            linked_pathname(folder, tree.name),
            'filters':
            filter_menu_items(tree.config.filter_language),
            # Autofocus only at the root of each tree:
            'should_autofocus_query':
            folder == '',

            # Folder template variables:
            'name':
            name,
            'path':
            folder,
            'folders':
            folders,
            'files':
            files
        })