Exemplo n.º 1
0
 def wrapper(*args, **kwargs):
     try:
         return func(*args, **kwargs)
     except exceptions, e:
         if not ignore:
             client.create_from_exception(sys.exc_info())
         return default
Exemplo n.º 2
0
        def log_exception_wrapper(*args, **kwargs):
            try:
                return func(*args, **kwargs)
            except exceptions, e:
                exec_info = sys.exc_info()
                frame = exec_info[2].tb_frame.f_back
                file_name = inspect.getfile(log_exception_wrapper)
                func_name = 'log_exception_wrapper'
                
                #check if func is called by other wrapped function
                #we should not catch execption in this case, because other function
                #can be waiting for it. Really exception can be caught by any not
                #wrapped function, but you always can use ignore=False
                while frame:
                    if frame.f_code.co_name == func_name and frame.f_code.co_filename == file_name:
                        if not hasattr(e, '_traceback'):
                            e._traceback = exec_info[2]
                        raise e
                        
                    frame = frame.f_back
                    
                data = {
                    'stack': traceback.extract_stack()
                }
                if hasattr(e, '_traceback'):
                    exec_info = exec_info[0], exec_info[1], e._traceback

                client.create_from_exception(exec_info, logger=logger, data=data)
                if not ignore:
                    raise e
Exemplo n.º 3
0
 def wrapper(*args, **kwargs):
     try:
         return func(*args, **kwargs)
     except exceptions, e:
         if not ignore:
             client.create_from_exception(sys.exc_info())
         return default
Exemplo n.º 4
0
        def log_exception_wrapper(*args, **kwargs):
            try:
                return func(*args, **kwargs)
            except exceptions, e:
                exec_info = sys.exc_info()
                frame = exec_info[2].tb_frame.f_back
                file_name = inspect.getfile(log_exception_wrapper)
                func_name = 'log_exception_wrapper'

                #check if func is called by other wrapped function
                #we should not catch execption in this case, because other function
                #can be waiting for it. Really exception can be caught by any not
                #wrapped function, but you always can use ignore=False
                while frame:
                    if frame.f_code.co_name == func_name and frame.f_code.co_filename == file_name:
                        if not hasattr(e, '_traceback'):
                            e._traceback = exec_info[2]
                        raise e

                    frame = frame.f_back

                data = {'stack': traceback.extract_stack()}
                if hasattr(e, '_traceback'):
                    exec_info = exec_info[0], exec_info[1], e._traceback

                client.create_from_exception(exec_info,
                                             logger=logger,
                                             data=data)
                if not ignore:
                    raise e
Exemplo n.º 5
0
def fixPdf(pdfFile):
	try:
		fileOpen = file(pdfFile, "a")
		fileOpen.write("%%EOF")
		fileOpen.close()
		return "Fixed"
	except Exception, e:
		sentry_client.create_from_exception(exc_info=sys.exc_info(), data={})
Exemplo n.º 6
0
def tumblr_post_photo(request, access_token, access_token_secret, blog_hostname, comment_id):
    comment = get_object_or_404(QuestComment, id=comment_id)

    try:
        models.post_photo(request.user, blog_hostname, comment)
    except requests.exceptions.HTTPError as e:
        client.create_from_exception()
        raise ServiceError("Error posting to Tumblr.")
Exemplo n.º 7
0
def ngram_bill_text():
	bill_files = Bill_File.objects.filter(parsed=False).exclude(converted_bill_text="")[0:20]
	for bill_file in bill_files:
		try:
			gram_parse_object_text(bill_file, bill_file.converted_bill_text)
			bill_file.parsed = True
			bill_file.save()
		except:
			sentry_client.create_from_exception(exc_info=sys.exc_info(), data={})
Exemplo n.º 8
0
def _post_request(worker, request, environ={}):
    from canvas import bgwork, util
    from sentry.client.models import client

    try:
        bgwork.perform()
    except Exception, e:
        util.logger.exception('post_request error in bgwork.perform:' + e.message)
        client.create_from_exception()
Exemplo n.º 9
0
 def do_graph_action():
     try:
         graph = GraphAPI(access_token)
         graph.put_object('me', send_action, quest=quest_url)
         if request:
             Metrics.share_to_timeline.record(request, quest=quest_url)
     except GraphAPIError as e:
         if request:
             Metrics.share_to_timeline_error.record(request, quest=quest_url)
         client.create_from_exception()
Exemplo n.º 10
0
    def server_error(self, request, exception):
        exc_info = sys.exc_info()
        client.create_from_exception(exc_info)

        if settings.DEBUG:
            (exc_type, exc_info, tb) = exc_info
            message = "%s\n" % exc_type.__name__
            message += "%s\n\n" % exc_info
            message += "TRACEBACK:\n"
            for tb in traceback.format_tb(tb):
                message += "%s\n" % tb
            return self.serialize_error(500, message)
        else:
            return self.serialize_error(500, _('Internal error'))
Exemplo n.º 11
0
 def server_error(self, request, exception):
     exc_info = sys.exc_info()
     client.create_from_exception(exc_info)
     
     if settings.DEBUG:
         (exc_type, exc_info, tb) = exc_info
         message = "%s\n" % exc_type.__name__
         message += "%s\n\n" % exc_info
         message += "TRACEBACK:\n"    
         for tb in traceback.format_tb(tb):
             message += "%s\n" % tb
         return self.serialize_error(500, message)
     else:
         return self.serialize_error(500, _('Internal error'))
Exemplo n.º 12
0
 def _save(self, name, content):
     name = name.replace('\\', '/')
     key = Key(self.bucket, name)
     try:
         if hasattr(content, 'temporary_file_path'):
             key.set_contents_from_filename(content.temporary_file_path())
         elif isinstance(content, File):
             key.set_contents_from_file(content)
         else:
             key.set_contents_from_string(content)
         key.make_public()
         return name
     except (BotoClientError, BotoServerError), e:
         client.create_from_exception()
         raise S3StorageError(*e.args)
Exemplo n.º 13
0
 def _save(self, name, content):
     name = name.replace('\\', '/')
     key = Key(self.bucket, name)
     try:
         if hasattr(content, 'temporary_file_path'):
             key.set_contents_from_filename(content.temporary_file_path())
         elif isinstance(content, File):
             key.set_contents_from_file(content)
         else:
             key.set_contents_from_string(content)
         key.make_public()
         return name
     except (BotoClientError, BotoServerError), e:
         client.create_from_exception()
         raise S3StorageError(*e.args)
Exemplo n.º 14
0
def convert_bill_text():

	bill_files = Bill_File.objects.filter(converted_bill_text="")[0:20]
	
	for bill_file in bill_files:
		mtype = mimetypes.guess_type(bill_file.file.path)[0]
		try:
			if mtype == "application/pdf":
				bill_file.converted_bill_text = convert_pdf(bill_file.file.path)
			elif mtype == "text/html":
				bill_file.converted_bill_text = strip_tags(bill_file.file.path)
			bill_file.save()
		except PdfReadError:
			fixPdf(bill_file.file.path)	
		except:
			sentry_client.create_from_exception(exc_info=sys.exc_info(), data={})	
Exemplo n.º 15
0
def process_mail(mail):
    translation.activate(settings.LANGUAGE_CODE)
    def run(mail_string):
        try:
            _process_mail(mail_string)
        except Exception:
            transaction.rollback()
            return sys.exc_info()
        else:
            transaction.commit()
            return None
    run = transaction.commit_manually(run)
    exc_info = run(mail)
    if exc_info is not None:
        from sentry.client.models import client
        client.create_from_exception(exc_info=exc_info, view="froide.foirequest.tasks.process_mail")
Exemplo n.º 16
0
def get_bill_details():

	json_objects = JSON_Archive.objects.filter(parsed=False)
	
	for json_object in json_objects:

		json_object_content = json.loads(json_object.content)
		bill = sunlight.openstates.bill(
			bill_id=json_object_content["id"],
		)
	
		bill = sunlight.openstates.bill(bill_id=json_object_content["id"],)
		try:
			old_bill = Bill.objects.get(json_archive_id=json_object.id)
		except Bill.DoesNotExist:
			try:
				local_bill = Bill()
				local_bill.json_details = json.dumps(bill)
				local_bill.json_archive = json_object
				local_bill.save()
		
				bill_file = Bill_File()
				bill_file.bill = local_bill
		
				if bill["documents"]:
					f = urllib.urlopen(bill["documents"][0]["url"])
					if f.getcode() == 200:
						contents = f.read()
						file_name = f.url.split("/")[-1]
						f.close()
				
						file_contents = ContentFile(contents)
						bill_file.file.save(file_name, file_contents, save=True)
					
						bill_file.save()
				json_object.parsed = True	
				json_object.save()
			except:
				sentry_client.create_from_exception(exc_info=sys.exc_info(), data={})
Exemplo n.º 17
0
 def handle_error(self, exc_info):
     client.create_from_exception(exc_info)