<commit_before>#! /usr/bin/env python
"""
builds.py is used to get the primary nightly builds from ftp.mozilla.org, record
the build information and provide that information through the Crash Reporter website.

This script is expected to be run once per day, and will be called from scripts/startBuilds.py.
"""

import logging
import os
import urllib2
from sgmllib import SGMLParser

logger = logging.getLogger("builds")

import socorro.lib.psycopghelper as psy
import socorro.lib.util as util


def buildExists(databaseCursor, product, version, platform, buildid):
  """ Determine whether or not a particular build exists already in the database """
  sql = """
    SELECT * 
    FROM builds
    WHERE product = %s 
    AND version = %s
    AND platform = %s
    AND buildid = %s
  """

  try:
    values = (product, version, platform, buildid)
    build = psy.singleRowSql(databaseCursor, sql, values)
    return True 
  except Exception:
    databaseCursor.connection.rollback()
    logger.info("Did not find build entries in builds table for %s %s %s %s" % (product, version, platform, buildid))
    return None


def fetchBuild(build_url, urllib2=urllib2):
  """ Grab a particular build from the Mozilla FTP site. """
  response = urllib2.urlopen(build_url)
  if response.code == 200:
    data = response.read()
    response.close()
    try: 
      return data.strip().split(" ")
    except Exception:
      util.reportExceptionAndAbort(logger)
      return None
  else: 
    util.reportExceptionAndAbort(logger)
    return None


def insertBuild(databaseCursor, product, version, platform, buildid, platform_changeset, app_changeset_1, app_changeset_2, filename):
  """ Insert a particular build into the database """
  build = buildExists(databaseCursor, product, version, platform, buildid)
  if not build:
    sql = """
      INSERT INTO builds 
      (product, version, platform, buildid, platform_changeset, app_changeset_1, app_changeset_2, filename)
      VALUES 
      (%s, %s, %s, %s, %s, %s, %s, %s)
    """<commit_msg>bug 630559 - split on newline not space for nightly changesets<commit_after>#! /usr/bin/env python
"""
builds.py is used to get the primary nightly builds from ftp.mozilla.org, record
the build information and provide that information through the Crash Reporter website.

This script is expected to be run once per day, and will be called from scripts/startBuilds.py.
"""

import logging
import os
import urllib2
from sgmllib import SGMLParser

logger = logging.getLogger("builds")

import socorro.lib.psycopghelper as psy
import socorro.lib.util as util


def buildExists(databaseCursor, product, version, platform, buildid):
  """ Determine whether or not a particular build exists already in the database """
  sql = """
    SELECT * 
    FROM builds
    WHERE product = %s 
    AND version = %s
    AND platform = %s
    AND buildid = %s
  """

  try:
    values = (product, version, platform, buildid)
    build = psy.singleRowSql(databaseCursor, sql, values)
    return True 
  except Exception:
    databaseCursor.connection.rollback()
    logger.info("Did not find build entries in builds table for %s %s %s %s" % (product, version, platform, buildid))
    return None


def fetchBuild(build_url, urllib2=urllib2):
  """ Grab a particular build from the Mozilla FTP site. """
  response = urllib2.urlopen(build_url)
  if response.code == 200:
    data = response.read()
    response.close()
    try: 
      return data.strip().split()
    except Exception:
      util.reportExceptionAndAbort(logger)
      return None
  else: 
    util.reportExceptionAndAbort(logger)
    return None


def insertBuild(databaseCursor, product, version, platform, buildid, platform_changeset, app_changeset_1, app_changeset_2, filename):
  """ Insert a particular build into the database """
  build = buildExists(databaseCursor, product, version, platform, buildid)
  if not build:
    sql = """
      INSERT INTO builds 
      (product, version, platform, buildid, platform_changeset, app_changeset_1, app_changeset_2, filename)
      VALUES 
      (%s, %s, %s, %s, %s, %s, %s, %s)
    """
{'fraction_non_alphanumeric': 0.09548104956268222, 'fraction_numerical': 0.006802721088435374, 'mean_word_length': 3.7376294591484465, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4786583', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1205, 'n_words': 429}