<commit_before>#!/usr/bin/env python2

import os
import dxr
import cgi
import itertools
import sys
import subprocess
from string import Template
from ConfigParser import ConfigParser

class HtmlBuilder:
  def _zipper(self, func):
    """ Returns all contents from all plugins. """
    if func not in self.resmap:
      return []
    return itertools.chain(*[f(self.blob.get(name, None), self.filepath, self.tree, self.conn, self.dbpath)
      for name, f in self.resmap[func]])

  def __init__(self, tree, filepath, dstpath, blob, resmap, conn = None, dbpath=None):
    # Read and expand all templates
    self.html_header = tree.getTemplateFile("dxr-header.html")
    self.html_footer = tree.getTemplateFile("dxr-footer.html")
    self.html_sidebar_header = tree.getTemplateFile("dxr-sidebar-header.html")
    self.html_sidebar_footer = tree.getTemplateFile("dxr-sidebar-footer.html")
    self.html_main_header = tree.getTemplateFile("dxr-main-header.html")
    self.html_main_footer = tree.getTemplateFile("dxr-main-footer.html")
    
    self.source = dxr.readFile(filepath)
    self.virtroot = tree.virtroot
    self.treename = tree.tree
    self.filename = os.path.basename(filepath)
    self.filepath = filepath
    self.srcroot = tree.sourcedir
    self.dstpath = os.path.normpath(dstpath)
    self.srcpath = filepath.replace(self.srcroot + '/', '')
    self.dbpath = dbpath

    self.show_sidebar = False

    self.blob = blob
    self.resmap = resmap
    self.tree = tree
    self.conn = conn

    # Config info used by dxr.js
    self.globalScript = ['var virtroot = "%s", tree = "%s";' % (self.virtroot, self.treename)]

  def getSidebarActions(self):
    html = ''
    blameLinks = { \
      'Log': 'http://hg.mozilla.org/mozilla-central/filelog/$rev/$filename', \
      'Blame': 'http://hg.mozilla.org/mozilla-central/annotate/$rev/$filename', \
      'Diff': 'http://hg.mozilla.org/mozilla-central/diff/$rev/$filename', \
      'Raw': 'http://hg.mozilla.org/mozilla-central/raw-diff/$rev/$filename' }
    html+=('<div id="sidebarActions"><b>Actions</b>\n')
    # Pick up revision command and URLs from config file
    source_dir = self.srcroot
    if 'revision' in globals():
      revision = globals()['revision']
    else:
      try:
        revision_command = self.tree.getOption('revision')
        revision_command = revision_command.replace('$source', source_dir)
        revision_process = subprocess.Popen ([revision_command], stdout=subprocess.PIPE, shell=True)
        revision = revision_process.stdout.readline().strip()<commit_msg>www: have the "raw" link point to the raw file contents<commit_after>#!/usr/bin/env python2

import os
import dxr
import cgi
import itertools
import sys
import subprocess
from string import Template
from ConfigParser import ConfigParser

class HtmlBuilder:
  def _zipper(self, func):
    """ Returns all contents from all plugins. """
    if func not in self.resmap:
      return []
    return itertools.chain(*[f(self.blob.get(name, None), self.filepath, self.tree, self.conn, self.dbpath)
      for name, f in self.resmap[func]])

  def __init__(self, tree, filepath, dstpath, blob, resmap, conn = None, dbpath=None):
    # Read and expand all templates
    self.html_header = tree.getTemplateFile("dxr-header.html")
    self.html_footer = tree.getTemplateFile("dxr-footer.html")
    self.html_sidebar_header = tree.getTemplateFile("dxr-sidebar-header.html")
    self.html_sidebar_footer = tree.getTemplateFile("dxr-sidebar-footer.html")
    self.html_main_header = tree.getTemplateFile("dxr-main-header.html")
    self.html_main_footer = tree.getTemplateFile("dxr-main-footer.html")
    
    self.source = dxr.readFile(filepath)
    self.virtroot = tree.virtroot
    self.treename = tree.tree
    self.filename = os.path.basename(filepath)
    self.filepath = filepath
    self.srcroot = tree.sourcedir
    self.dstpath = os.path.normpath(dstpath)
    self.srcpath = filepath.replace(self.srcroot + '/', '')
    self.dbpath = dbpath

    self.show_sidebar = False

    self.blob = blob
    self.resmap = resmap
    self.tree = tree
    self.conn = conn

    # Config info used by dxr.js
    self.globalScript = ['var virtroot = "%s", tree = "%s";' % (self.virtroot, self.treename)]

  def getSidebarActions(self):
    html = ''
    blameLinks = { \
      'Log': 'http://hg.mozilla.org/mozilla-central/filelog/$rev/$filename', \
      'Blame': 'http://hg.mozilla.org/mozilla-central/annotate/$rev/$filename', \
      'Diff': 'http://hg.mozilla.org/mozilla-central/diff/$rev/$filename', \
      'Raw': 'http://hg.mozilla.org/mozilla-central/raw-file/$rev/$filename' }
    html+=('<div id="sidebarActions"><b>Actions</b>\n')
    # Pick up revision command and URLs from config file
    source_dir = self.srcroot
    if 'revision' in globals():
      revision = globals()['revision']
    else:
      try:
        revision_command = self.tree.getOption('revision')
        revision_command = revision_command.replace('$source', source_dir)
        revision_process = subprocess.Popen ([revision_command], stdout=subprocess.PIPE, shell=True)
        revision = revision_process.stdout.readline().strip()
{'fraction_non_alphanumeric': 0.13629313687475766, 'fraction_numerical': 0.00038774718883288094, 'mean_word_length': 3.5294117647058822, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7616704', 'n_tokens_mistral': 1690, 'n_tokens_neox': 1657, 'n_words': 337}