# Path: django/crashreport/processor/models.py
# class ProcessedCrash(models.Model):
#     # custom manager
#     objects = ProcessedCrashManager()
# 
#     crash_id = models.CharField(max_length=100,
#             unique=True)
# 
#     upload_time = models.DateTimeField()
# 
#     process_time = models.DateTimeField(auto_now_add=True)
# 
#     version = models.ForeignKey(Version,
#             null=True)
# 
#     # Look for better solution to store dictionary
#     additional_data = models.TextField(default='{}')
# 
#     # OS info
#     LINUX = 'linux'
#     WINDOWS = 'windows'
#     OSX = 'osx'
#     ANDROID = 'android'
#     IOS = 'ios'
#     OS_NAMES = (
#             (LINUX, 'Linux'),
#             (WINDOWS, 'Windows'),
#             (OSX, 'OSX'),
#             (ANDROID, 'Android'),
#             (IOS, 'IOS')
#             )
#     os_name = models.CharField(max_length=10,
#             choices=OS_NAMES)
# 
#     os_detail = models.CharField(max_length=100,
#             default='')
# 
#     # CPU info
#     cpu_architecture = models.CharField(max_length=20)
# 
#     cpu_info = models.CharField(max_length=100,
#             default='')
# 
#     signature = models.ForeignKey(Signature, on_delete=models.CASCADE)
# 
#     # crash info
#     crash_cause = models.CharField(max_length=100,
#             default='SIGSEGV')
# 
#     crash_address = models.CharField(max_length=100,
#             default='0x0')
# 
#     crash_thread = models.SmallIntegerField(
#             default=0,
#             help_text='The id of the thread that caused the crash')
# 
#     # modules
#     modules = models.TextField()
# 
#     # TODO: moggi: look for better solutions
#     # threads
#     crashing_thread = models.TextField()
# 
#     threads = models.TextField()
# 
#     raw = models.TextField()
# 
#     def __str__(self):
#         return self.crash_id
# 
#     def set_view_os_name_to_model(self, view_os_name):
#         if view_os_name.lower() == ProcessedCrash.LINUX:
#             self.os_name = ProcessedCrash.LINUX
#         elif view_os_name.lower().startswith(ProcessedCrash.WINDOWS):
#             self.os_name = ProcessedCrash.WINDOWS
#         elif view_os_name.lower() == ProcessedCrash.OSX:
#             self.os_name = ProcessedCrash.OSX
#         else:
#             logger.warning("could not determine the os: " + view_os_name)
# 
#     def _convert_frames(self, frame_list):
#         text = ""
#         for frame in frame_list:
#             text += self._convert_frames(frame) + "\n"
#         return text
# 
#     def _find_frame(self, json_frame_list):
#         for frame in json_frame_list:
#             function = frame['lib_name']
#             if function not in module_blacklist and function is not "":
#                 return frame
# 
#         return json_frame_list[0]
# 
#     def _set_signature(self, frame_list):
#         text = ""
#         json_frame_list = json.loads(frame_list)
#         if len(json_frame_list) > 0:
#             frame = self._find_frame(json_frame_list)
#             function = frame['function']
#             if len(function) > 0:
#                 text = function
#             else:
#                 text = frame['lib_name']
# 
#         if len(text) is 0:
#             text = "Invalid signature"
#             logger.warn("could not create a valid signature for %s" % self.crash_id)
# 
#         text = text[:255] if len(text) > 255 else text
#         signatures = Signature.objects.filter(signature=text)
#         if len(signatures) < 1:
#             signature = Signature()
#             signature.signature = text
#             signature.first_observed = self.upload_time
#             signature.last_observed = self.upload_time
#         else:
#             signature = signatures[0]
# 
#         if signature.last_observed < self.upload_time:
#             signature.last_observed = self.upload_time
#         try:
#             signature.save()
#         except DataError as e:
#             logger.error("error trying to save signature %s" % text)
#             logger.error(str(e))
#         self.signature = signature
# 
#     def set_thread_to_model(self, threads):
#         other_threads = {}
#         for thread_id, frame_list in threads.iteritems():
#             if int(thread_id) == int(self.crash_thread):
#                 self._set_signature(frame_list)
#                 self.crashing_thread = frame_list
#             else:
#                 other_threads[thread_id] = json.loads(frame_list)
# 
#         self.threads = json.dumps(other_threads)
# 
#     def set_modules_to_model(self, modules):
#         self.modules = "\n".join(modules)
# 
#     def get_split_module_list(self):
#         modules = self.modules.splitlines()
#         ret = []
#         for module in modules:
#             line = module.split('|')
#             module_name = line[1]
#             if module_name.startswith('LC_'):
#                 continue
#             version = line[2]
#             debug_id = line[4]
#             ret.append({'name':module_name,
#                 'version':version, 'id':debug_id})
#         return ret


import subprocess, re, json
import logging
import os
from .models import ProcessedCrash
from django.db import IntegrityError
from django.conf import settings
from crashsubmit import models as submit_model
# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#





logger = logging.getLogger(__name__)

class MinidumpProcessor(object):
    def __init__(self):
        self.minidump_stackwalker = settings.MINIDUMP_STACKWALK
        self.symbol_path = settings.SYMBOL_LOCATION

    def process(self, crash_id):


# Path: django/crashreport/processor/models.py
# class ProcessedCrash(models.Model):
#     # custom manager
#     objects = ProcessedCrashManager()
# 
#     crash_id = models.CharField(max_length=100,
#             unique=True)
# 
#     upload_time = models.DateTimeField()
# 
#     process_time = models.DateTimeField(auto_now_add=True)
# 
#     version = models.ForeignKey(Version,
#             null=True)
# 
#     # Look for better solution to store dictionary
#     additional_data = models.TextField(default='{}')
# 
#     # OS info
#     LINUX = 'linux'
#     WINDOWS = 'windows'
#     OSX = 'osx'
#     ANDROID = 'android'
#     IOS = 'ios'
#     OS_NAMES = (
#             (LINUX, 'Linux'),
#             (WINDOWS, 'Windows'),
#             (OSX, 'OSX'),
#             (ANDROID, 'Android'),
#             (IOS, 'IOS')
#             )
#     os_name = models.CharField(max_length=10,
#             choices=OS_NAMES)
# 
#     os_detail = models.CharField(max_length=100,
#             default='')
# 
#     # CPU info
#     cpu_architecture = models.CharField(max_length=20)
# 
#     cpu_info = models.CharField(max_length=100,
#             default='')
# 
#     signature = models.ForeignKey(Signature, on_delete=models.CASCADE)
# 
#     # crash info
#     crash_cause = models.CharField(max_length=100,
#             default='SIGSEGV')
# 
#     crash_address = models.CharField(max_length=100,
#             default='0x0')
# 
#     crash_thread = models.SmallIntegerField(
#             default=0,
#             help_text='The id of the thread that caused the crash')
# 
#     # modules
#     modules = models.TextField()
# 
#     # TODO: moggi: look for better solutions
#     # threads
#     crashing_thread = models.TextField()
# 
#     threads = models.TextField()
# 
#     raw = models.TextField()
# 
#     def __str__(self):
#         return self.crash_id
# 
#     def set_view_os_name_to_model(self, view_os_name):
#         if view_os_name.lower() == ProcessedCrash.LINUX:
#             self.os_name = ProcessedCrash.LINUX
#         elif view_os_name.lower().startswith(ProcessedCrash.WINDOWS):
#             self.os_name = ProcessedCrash.WINDOWS
#         elif view_os_name.lower() == ProcessedCrash.OSX:
#             self.os_name = ProcessedCrash.OSX
#         else:
#             logger.warning("could not determine the os: " + view_os_name)
# 
#     def _convert_frames(self, frame_list):
#         text = ""
#         for frame in frame_list:
#             text += self._convert_frames(frame) + "\n"
#         return text
# 
#     def _find_frame(self, json_frame_list):
#         for frame in json_frame_list:
#             function = frame['lib_name']
#             if function not in module_blacklist and function is not "":
#                 return frame
# 
#         return json_frame_list[0]
# 
#     def _set_signature(self, frame_list):
#         text = ""
#         json_frame_list = json.loads(frame_list)
#         if len(json_frame_list) > 0:
#             frame = self._find_frame(json_frame_list)
#             function = frame['function']
#             if len(function) > 0:
#                 text = function
#             else:
#                 text = frame['lib_name']
# 
#         if len(text) is 0:
#             text = "Invalid signature"
#             logger.warn("could not create a valid signature for %s" % self.crash_id)
# 
#         text = text[:255] if len(text) > 255 else text
#         signatures = Signature.objects.filter(signature=text)
#         if len(signatures) < 1:
#             signature = Signature()
#             signature.signature = text
#             signature.first_observed = self.upload_time
#             signature.last_observed = self.upload_time
#         else:
#             signature = signatures[0]
# 
#         if signature.last_observed < self.upload_time:
#             signature.last_observed = self.upload_time
#         try:
#             signature.save()
#         except DataError as e:
#             logger.error("error trying to save signature %s" % text)
#             logger.error(str(e))
#         self.signature = signature
# 
#     def set_thread_to_model(self, threads):
#         other_threads = {}
#         for thread_id, frame_list in threads.iteritems():
#             if int(thread_id) == int(self.crash_thread):
#                 self._set_signature(frame_list)
#                 self.crashing_thread = frame_list
#             else:
#                 other_threads[thread_id] = json.loads(frame_list)
# 
#         self.threads = json.dumps(other_threads)
# 
#     def set_modules_to_model(self, modules):
#         self.modules = "\n".join(modules)
# 
#     def get_split_module_list(self):
#         modules = self.modules.splitlines()
#         ret = []
#         for module in modules:
#             line = module.split('|')
#             module_name = line[1]
#             if module_name.startswith('LC_'):
#                 continue
#             version = line[2]
#             debug_id = line[4]
#             ret.append({'name':module_name,
#                 'version':version, 'id':debug_id})
#         return ret


# Path: django/crashreport/processor/processor.py
import subprocess, re, json
import logging
import os
from .models import ProcessedCrash
from django.db import IntegrityError
from django.conf import settings
from crashsubmit import models as submit_model

# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#





logger = logging.getLogger(__name__)

class MinidumpProcessor(object):
    def __init__(self):
        self.minidump_stackwalker = settings.MINIDUMP_STACKWALK
        self.symbol_path = settings.SYMBOL_LOCATION

    def process(self, crash_id):


        if len(ProcessedCrash.objects.filter(crash_id=crash_id)) != 0: