示例#1
0
    def setUp(self):
        self.baseDate = dt.datetime(2008, 12, 25, tzinfo=UTC)
        self.rawuuids = []
        self.yyyyoids = []
        self.dyyoids = []
        self.depths = [4, 4, 3, 3, 3, 2, 2, 2, 1, 1]
        self.badooid0 = "%s%s" % (str(uu.uuid4())[:-8], 'ffeea1b2')
        self.badooid1 = "%s%s" % (str(uu.uuid4())[:-8], 'f3eea1b2')

        for i in range(10):
            self.rawuuids.append(str(uu.uuid4()))
        assert len(self.depths) == len(self.rawuuids)

        for i in self.rawuuids:
            self.yyyyoids.append("%s%4d%02d%02d" %
                                 (i[:-8], self.baseDate.year,
                                  self.baseDate.month, self.baseDate.day))

        for i in range(len(self.rawuuids)):
            self.dyyoids.append(
                "%s%d%02d%02d%02d" %
                (self.rawuuids[i][:-7], self.depths[i], self.baseDate.year %
                 100, self.baseDate.month, self.baseDate.day))

        today = utc_now()
        self.nowstamp = dt.datetime(today.year,
                                    today.month,
                                    today.day,
                                    tzinfo=UTC)
        self.xmas05 = dt.datetime(2005, 12, 25, tzinfo=UTC)
示例#2
0
  def ensure_contacts(self, cursor, email_rows):
    """ Returns a list of five-element dicts
        * id
        * email
        * crash_date
        * ooid
        * token

        Also inserts into email_contacts table.
    """
    # tupple tied to determine_emails SQL (id, email, token) id and token NULL for new entries
    new_emails = []
    contacts = []
    for row in email_rows:
      logger.info('dbid: %s, email: %s, crash_date: %s, ooid: %s, token: %s' % row)
      dbid, email, crash_date, ooid, token = row
      if '@' not in email:
        continue
      if not dbid:
        logger.info('new email address found')
        new_token = str(uuid.uuid4())
        new_emails.append((email, new_token, ooid, crash_date))
        logger.info('using token %s for email %s' % (new_token, email))
        contacts.append({'id': None, 'email': email, 'crash_date': crash_date, 'ooid': ooid, 'token': new_token})
      else:
        contacts.append({'id': dbid, 'email': email, 'crash_date': crash_date, 'ooid': ooid, 'token': token})
    if new_emails:
      logger.info('inserting new email addresses into emailcontacts')
      table = EmailContactsTable(logger)
      cursor.executemany(table.insertSql, new_emails)
    return contacts
示例#3
0
  def ensure_contacts(self, cursor, email_rows):
    """ Returns a list of five-element dicts
        * id
        * email
        * crash_date
        * ooid
        * token

        Also inserts into email_contacts table.
    """
    # tupple tied to determine_emails SQL (id, email, token) id and token NULL for new entries
    new_emails = []
    contacts = []
    for row in email_rows:
      logger.info('dbid: %s, email: %s, crash_date: %s, ooid: %s, token: %s' % row)
      dbid, email, crash_date, ooid, token = row
      if '@' not in email:
        continue
      if not dbid:
        logger.info('new email address found')
        new_token = str(uuid.uuid4())
        new_emails.append((email, new_token, ooid, crash_date))
        logger.info('using token %s for email %s' % (new_token, email))
        contacts.append({'id': None, 'email': email, 'crash_date': crash_date, 'ooid': ooid, 'token': new_token})
      else:
        contacts.append({'id': dbid, 'email': email, 'crash_date': crash_date, 'ooid': ooid, 'token': token})
    if new_emails:
      logger.info('inserting new email addresses into emailcontacts')
      table = EmailContactsTable(logger)
      cursor.executemany(table.insertSql, new_emails)
    return contacts
示例#4
0
  def setUp(self):
    self.baseDate = dt.datetime(2008,12,25, tzinfo=UTC)
    self.rawuuids = []
    self.yyyyoids = []
    self.dyyoids = []
    self.depths = [4,4,3,3,3,2,2,2,1,1]
    self.badooid0 = "%s%s" %(str(uu.uuid4())[:-8],'ffeea1b2')
    self.badooid1 = "%s%s" %(str(uu.uuid4())[:-8],'f3eea1b2')

    for i in range(10):
      self.rawuuids.append(str(uu.uuid4()))
    assert len(self.depths) == len(self.rawuuids)

    for i in self.rawuuids:
      self.yyyyoids.append("%s%4d%02d%02d" % (i[:-8],self.baseDate.year,self.baseDate.month,self.baseDate.day))

    for i in range(len(self.rawuuids)):
      self.dyyoids.append("%s%d%02d%02d%02d" %(self.rawuuids[i][:-7],self.depths[i],self.baseDate.year%100,self.baseDate.month,self.baseDate.day))

    today = utc_now()
    self.nowstamp = dt.datetime(today.year,today.month,today.day,tzinfo=UTC)
    self.xmas05 = dt.datetime(2005,12,25,tzinfo=UTC)
示例#5
0
def createNewOoid(timestamp=None, depth=None):
  """Create a new Ooid for a given time, to be stored at a given depth
  timestamp: the year-month-day is encoded in the ooid. If none, use current day
  depth: the expected storage depth is encoded in the ooid. If non, use the defaultDepth
  returns a new opaque id string holding 24 random hex digits and encoded date and depth info
  """
  if not timestamp:
    timestamp = utc_now().date()
  if not depth:
    depth = defaultDepth
  assert depth <= 4 and depth >=1
  uuid = str(uu.uuid4())
  return "%s%d%02d%02d%02d" %(uuid[:-7],depth,timestamp.year%100,timestamp.month,timestamp.day)
示例#6
0
  def submitCrashReport (jsonFilePathName, binaryFilePathName, serverURL, uniqueHang):
    jsonFile = open(jsonFilePathName)
    try:
      data = json.load(jsonFile)
    finally:
      jsonFile.close()

    if uniqueHang:
      try:
        if data['HangId'] in existingHangIdCache:
          data['HangId'] = existingHangIdCache
        else:
          data['HangId'] = existingHangIdCache[data['HangId']] = uuid.uuid4()
      except:
        pass

    fields = dict([(t[0],t[1]) for t in data.items()])
    fields['upload_file_minidump'] = open(binaryFilePathName, 'rb')
    datagen, headers = poster.encode.multipart_encode(fields);
    request = urllib2.Request(serverURL, datagen, headers)
    print urllib2.urlopen(request).read(),
示例#7
0
  def submitCrashReport (jsonFilePathName, binaryFilePathName, serverURL, uniqueHang):
    jsonFile = open(jsonFilePathName)
    try:
      data = json.load(jsonFile)
    finally:
      jsonFile.close()

    if uniqueHang:
      try:
        if data['HangId'] in existingHangIdCache:
          data['HangId'] = existingHangIdCache
        else:
          data['HangId'] = existingHangIdCache[data['HangId']] = uuid.uuid4()
      except:
        pass

    fields = dict([(t[0],t[1]) for t in data.items()])
    fields['upload_file_minidump'] = open(binaryFilePathName, 'rb')
    datagen, headers = poster.encode.multipart_encode(fields);
    request = urllib2.Request(serverURL, datagen, headers)
    print urllib2.urlopen(request).read(),