<commit_before>#!/usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import cgi
import logging
import os
import re

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import memcache
from google.appengine.api import urlfetch

import app_known_issues

DEFAULT_CACHE_TIME = 300
VIEW_VC_ROOT = 'http://src.chromium.org'


class Channel():
  def __init__(self, name, tag):
    self.name = name
    self.tag = tag

Channel.DEV = Channel("dev", "2.0-dev")
Channel.BETA = Channel("beta", "1.1-beta")
Channel.STABLE = Channel("stable", "")
Channel.TRUNK = Channel("trunk", "")
Channel.CHANNELS = [Channel.TRUNK, Channel.DEV, Channel.BETA, Channel.STABLE]
Channel.DEFAULT = Channel.STABLE


def GetChannelByName(channelName):
  for channel in Channel.CHANNELS:
    if channel.name == channelName:
      return channel

  return None


def GetBranchRoot(branch):
  if branch is None:
    return '%s/viewvc/chrome/trunk/src/' % VIEW_VC_ROOT
  else:
    return '%s/viewvc/chrome/branches/%s/src/' % (VIEW_VC_ROOT, branch)


def GetExtensionsRoot(branch):
  return GetBranchRoot(branch) + 'chrome/common/extensions/'


def GetDocsRoot(branch, docFamily):
  if docFamily is None:
    return GetExtensionsRoot(branch) + 'docs/'
  else:
    return GetExtensionsRoot(branch) + ('docs/%s/' % docFamily)


def GetSrcUrl(branch, docFamily, path):
  # TODO(aa): Need cooler favicon.
  if path[0] == 'favicon.ico':
    return '%s/%s' % (VIEW_VC_ROOT, path[0])

  pathstr = '/'.join(path)

  if path[0] == 'api' and path[-1].endswith('.json'):
    return GetExtensionsRoot(branch) + pathstr

  if path[0] == 'third_party':
    if path[-1] == 'jstemplate_compiled.js':
      return GetBranchRoot(branch) + ('chrome/%s' % pathstr)
    else:
      return GetBranchRoot(branch) + pathstr

  return GetDocsRoot(branch, docFamily) + pathstr


def GetBranch(channel):
  """ Gets the name of the branch in source control that contains the code for
  the Chrome version currently being served on |channel|."""
  branch = memcache.get(channel.name)
  if branch is not None:
    return branch

  # query Omaha to figure out which version corresponds to this channel
  postdata = """<?xml version="1.0" encoding="UTF-8"?>
                <o:gupdate xmlns:o="http://www.google.com/update2/request"
                    protocol="2.0" testsource="crxdocs">
                <o:app appid="{8A69D345-D564-463C-AFF1-A69D9E530F96}"
                    version="0.0.0.0" lang="">
                <o:updatecheck tag="%s"
                    installsource="ondemandcheckforupdates" />
                </o:app>
                </o:gupdate>
                """ % channel.tag

  result = urlfetch.fetch(
      url="https://tools.google.com/service/update2",
      payload=postdata,
      method=urlfetch.POST,
      headers={'Content-Type':'application/x-www-form-urlencoded',
               'X-USER-IP': '192.168.3.11'})

  if result.status_code != 200:
    return None

  match = re.search(r'<updatecheck Version="\d+\.\d+\.(\d+)\.\d+"',
                    result.content)
  if match is None:
    logging.error("Cannot find branch for requested channel: " + result.content)
    return None

  branch = match.group(1)
  memcache.add(channel.name, branch, DEFAULT_CACHE_TIME)
  return branch

class MainPage(webapp.RequestHandler):
  def redirectToIndexIfNecessary(self):
    if len(self.path) > 0:
      return True
    newPath = self.request.path
    if not newPath.endswith('/'):
      newPath += '/'
    newPath += 'index.html'
    self.redirect(newPath)
    return False


  def initPath(self):
    self.path = self.request.path.split('/')

    # The first component is always empty.
    self.path.pop(0)

    # The last component might be empty if there was a trailing slash.
    if len(self.path) > 0 and self.path[-1] == '':
      self.path.pop()

    # Temporary hacks for apps.
    # TODO(aa): Remove once the apps content percolates through Chrome's release
    # process more.
    if self.path == ['apps'] or self.path == ['trunk', 'apps']:
      self.redirect('/trunk/apps/about_apps.html')
      return False

    # TODO(aa): Remove once we have a homepage for developer.chrome.com.
    if (self.path == [] and
        self.request.url.startswith('http://developer.chrome.com')):
      self.redirect('http://developers.google.com/chrome')
      return False

    # TODO(aa): Remove this soon.
    if (len(self.path) > 1 and self.path[1] == 'apps' and
        not self.request.url.startswith('http://localhost')):
      return False
<commit_msg>Remove TODO from extension/apps docs server now that developer.chrome.com is live.<commit_after>#!/usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import cgi
import logging
import os
import re

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import memcache
from google.appengine.api import urlfetch

import app_known_issues

DEFAULT_CACHE_TIME = 300
VIEW_VC_ROOT = 'http://src.chromium.org'


class Channel():
  def __init__(self, name, tag):
    self.name = name
    self.tag = tag

Channel.DEV = Channel("dev", "2.0-dev")
Channel.BETA = Channel("beta", "1.1-beta")
Channel.STABLE = Channel("stable", "")
Channel.TRUNK = Channel("trunk", "")
Channel.CHANNELS = [Channel.TRUNK, Channel.DEV, Channel.BETA, Channel.STABLE]
Channel.DEFAULT = Channel.STABLE


def GetChannelByName(channelName):
  for channel in Channel.CHANNELS:
    if channel.name == channelName:
      return channel

  return None


def GetBranchRoot(branch):
  if branch is None:
    return '%s/viewvc/chrome/trunk/src/' % VIEW_VC_ROOT
  else:
    return '%s/viewvc/chrome/branches/%s/src/' % (VIEW_VC_ROOT, branch)


def GetExtensionsRoot(branch):
  return GetBranchRoot(branch) + 'chrome/common/extensions/'


def GetDocsRoot(branch, docFamily):
  if docFamily is None:
    return GetExtensionsRoot(branch) + 'docs/'
  else:
    return GetExtensionsRoot(branch) + ('docs/%s/' % docFamily)


def GetSrcUrl(branch, docFamily, path):
  # TODO(aa): Need cooler favicon.
  if path[0] == 'favicon.ico':
    return '%s/%s' % (VIEW_VC_ROOT, path[0])

  pathstr = '/'.join(path)

  if path[0] == 'api' and path[-1].endswith('.json'):
    return GetExtensionsRoot(branch) + pathstr

  if path[0] == 'third_party':
    if path[-1] == 'jstemplate_compiled.js':
      return GetBranchRoot(branch) + ('chrome/%s' % pathstr)
    else:
      return GetBranchRoot(branch) + pathstr

  return GetDocsRoot(branch, docFamily) + pathstr


def GetBranch(channel):
  """ Gets the name of the branch in source control that contains the code for
  the Chrome version currently being served on |channel|."""
  branch = memcache.get(channel.name)
  if branch is not None:
    return branch

  # query Omaha to figure out which version corresponds to this channel
  postdata = """<?xml version="1.0" encoding="UTF-8"?>
                <o:gupdate xmlns:o="http://www.google.com/update2/request"
                    protocol="2.0" testsource="crxdocs">
                <o:app appid="{8A69D345-D564-463C-AFF1-A69D9E530F96}"
                    version="0.0.0.0" lang="">
                <o:updatecheck tag="%s"
                    installsource="ondemandcheckforupdates" />
                </o:app>
                </o:gupdate>
                """ % channel.tag

  result = urlfetch.fetch(
      url="https://tools.google.com/service/update2",
      payload=postdata,
      method=urlfetch.POST,
      headers={'Content-Type':'application/x-www-form-urlencoded',
               'X-USER-IP': '192.168.3.11'})

  if result.status_code != 200:
    return None

  match = re.search(r'<updatecheck Version="\d+\.\d+\.(\d+)\.\d+"',
                    result.content)
  if match is None:
    logging.error("Cannot find branch for requested channel: " + result.content)
    return None

  branch = match.group(1)
  memcache.add(channel.name, branch, DEFAULT_CACHE_TIME)
  return branch

class MainPage(webapp.RequestHandler):
  def redirectToIndexIfNecessary(self):
    if len(self.path) > 0:
      return True
    newPath = self.request.path
    if not newPath.endswith('/'):
      newPath += '/'
    newPath += 'index.html'
    self.redirect(newPath)
    return False


  def initPath(self):
    self.path = self.request.path.split('/')

    # The first component is always empty.
    self.path.pop(0)

    # The last component might be empty if there was a trailing slash.
    if len(self.path) > 0 and self.path[-1] == '':
      self.path.pop()

    # Temporary hacks for apps.
    # TODO(aa): Remove once the apps content percolates through Chrome's release
    # process more.
    if self.path == ['apps'] or self.path == ['trunk', 'apps']:
      self.redirect('/trunk/apps/about_apps.html')
      return False

    # TODO(aa): Remove once we have a homepage for developer.chrome.com.
    if (self.path == [] and
        self.request.url.startswith('http://developer.chrome.com')):
      self.redirect('http://developers.google.com/chrome')
      return False

{'fraction_non_alphanumeric': 0.13321187439717072, 'fraction_numerical': 0.014360733040402958, 'mean_word_length': 3.0715532286212914, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 2, '>': 20, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 4}, 'pii_count': 4, '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': '4813694', 'n_tokens_mistral': 3081, 'n_tokens_neox': 2927, 'n_words': 759}