1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-12-12 02:52:20 -05:00

Fixed issues with issue submitter and pastebin logs.

Added test for issue submitter.
This commit is contained in:
echel0n 2014-12-20 05:49:35 -08:00
parent 11e12b95d1
commit 3b37dc0540
4 changed files with 81 additions and 29 deletions

View File

@ -17,6 +17,7 @@
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
import re
import sys
import traceback
import sickbeard
@ -275,13 +276,6 @@ class UIError():
"""
def __init__(self, message):
try:
self.title = sys.exc_info()[1].message
except:
self.title = None
self.title = sys.exc_info()[-2]
self.message = message
self.time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
try:
self.exc_info = sys.exc_info()
except:
self.exc_info = None
self.time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

View File

@ -119,13 +119,14 @@ class Logger(object):
# pass exception information if debugging enabled
kwargs["exc_info"] = 1 if level == ERROR else 0
self.logger.log(level, message, *args, **kwargs)
if level == ERROR:
self.logger.exception(message, *args, **kwargs)
classes.ErrorViewer.add(classes.UIError(message))
#if sickbeard.GIT_AUTOISSUES:
# self.submit_errors()
else:
self.logger.log(level, message, *args, **kwargs)
def log_error_and_exit(self, error_msg, *args, **kwargs):
self.log(error_msg, ERROR, *args, **kwargs)
@ -139,8 +140,6 @@ class Logger(object):
if not (sickbeard.GIT_USERNAME and sickbeard.GIT_PASSWORD and len(classes.ErrorViewer.errors) > 0):
return
title = "[APP SUBMITTED]: "
gh_org = sickbeard.GIT_ORG or 'SiCKRAGETV'
gh_repo = 'sickrage-issues'
@ -148,28 +147,26 @@ class Logger(object):
user_agent="SiCKRAGE").get_organization(gh_org).get_repo(gh_repo)
try:
# read log file
if self.logFile and os.path.isfile(self.logFile):
with ek.ek(open, self.logFile) as f:
log_data = f.readlines()
except Exception as e:
pass
log_data = [line for line in reversed(log_data)]
try:
# parse and submit errors to issue tracker
for curError in sorted(classes.ErrorViewer.errors, key=lambda error: error.time, reverse=True)[:500]:
if not curError.title:
continue
regex = "^(%s)\s*([A-Z]+)\s*(.+?)\s*\:\:\s*(.*)$" % curError.time
maxlines = 50
pastebin_url = None
for i, x in enumerate(reversed(log_data)):
regex = "^(%s)\s*([A-Z]+)\s*(.+?)\s*\:\:\s*(.*)$" % curError.time
for i, x in enumerate(log_data):
x = ek.ss(x)
match = re.match(regex, x)
if match:
level = match.group(2)
if reverseNames[level] == ERROR:
paste_data = "".join(log_data[len(log_data) - i - 50:])
paste_data = "".join(log_data[i:50])
pastebin_url = PastebinAPI().paste('f59b8e9fa1fc2d033e399e6c7fb09d19', paste_data)
break
@ -187,14 +184,17 @@ class Logger(object):
message += u"---\n"
message += u"_STAFF NOTIFIED_: @SiCKRAGETV/owners @SiCKRAGETV/moderators"
issue = self.gh_issues.create_issue(title + curError.title, message)
issue = self.gh_issues.create_issue("[APP SUBMITTED]: " + curError.title, message)
if issue:
self.log('Your issue ticket #%s was submitted successfully!' % issue.number)
if not sickbeard.GIT_AUTOISSUES:
ui.notifications.message('Your issue ticket #%s was submitted successfully!' % issue.number)
finally:
classes.ErrorViewer.clear()
# clear error from error list
classes.ErrorViewer.errors.remove(curError)
except Exception as e:
self.log(sickbeard.exceptions.ex(e), ERROR)
class Wrapper(object):

View File

@ -0,0 +1,49 @@
# coding=UTF-8
# Author: Dennis Lutter <lad1337@gmail.com>
# URL: http://code.google.com/p/sickbeard/
#
# This file is part of SickRage.
#
# SickRage is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SickRage is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
from __future__ import with_statement
import unittest
import sys, os.path
from configobj import ConfigObj
sys.path.append(os.path.abspath('..'))
sys.path.append(os.path.abspath('../lib'))
import sickbeard
import test_lib as test
def error():
try:
raise Exception('FAKE EXCEPTION')
except Exception as e:
sickbeard.logger.log("FAKE ERROR: " + sickbeard.exceptions.ex(e), sickbeard.logger.ERROR)
sickbeard.logger.submit_errors()
raise
class IssueSubmitterBasicTests(unittest.TestCase):
def test_submitter(self):
self.assertRaises(Exception, error)
if __name__ == "__main__":
print "=================="
print "STARTING - ISSUE SUBMITTER TESTS"
print "=================="
print "######################################################################"
suite = unittest.TestLoader().loadTestsFromTestCase(IssueSubmitterBasicTests)

View File

@ -25,6 +25,7 @@ import sqlite3
import sys
import os.path
from configobj import ConfigObj
sys.path.append(os.path.abspath('..'))
sys.path.append(os.path.abspath('../lib'))
@ -54,9 +55,6 @@ FILEDIR = os.path.join(TESTDIR, SHOWNAME)
FILEPATH = os.path.join(FILEDIR, FILENAME)
SHOWDIR = os.path.join(TESTDIR, SHOWNAME + " final")
sickbeard.logger.logFile = os.path.join(os.path.join(TESTDIR, 'Logs'), 'test_sickbeard.log')
sickbeard.logger.initLogging()
#=================
# prepare env functions
#=================
@ -74,6 +72,7 @@ def createTestCacheFolder():
# sickbeard globals
#=================
sickbeard.SYS_ENCODING = 'UTF-8'
sickbeard.showList = []
sickbeard.QUALITY_DEFAULT = 4 # hdtv
sickbeard.FLATTEN_FOLDERS_DEFAULT = 0
@ -90,13 +89,23 @@ sickbeard.providerList = providers.makeProviderList()
sickbeard.PROG_DIR = os.path.abspath('..')
sickbeard.DATA_DIR = sickbeard.PROG_DIR
sickbeard.CONFIG_FILE = os.path.join(sickbeard.DATA_DIR, "config.ini")
sickbeard.CFG = ConfigObj(sickbeard.CONFIG_FILE)
sickbeard.BRANCG = sickbeard.config.check_setting_str(sickbeard.CFG, 'General', 'branch', '')
sickbeard.CUR_COMMIT_HASH = sickbeard.config.check_setting_str(sickbeard.CFG, 'General', 'cur_commit_hash', '')
sickbeard.GIT_USERNAME = sickbeard.config.check_setting_str(sickbeard.CFG, 'General', 'git_username', '')
sickbeard.GIT_PASSWORD = sickbeard.config.check_setting_str(sickbeard.CFG, 'General', 'git_password', '', censor_log=True)
sickbeard.LOG_DIR = os.path.join(TESTDIR, 'Logs')
sickbeard.logger.logFile = os.path.join(sickbeard.LOG_DIR, 'test_sickbeard.log')
createTestLogFolder()
sickbeard.logger.initLogging(False)
sickbeard.CACHE_DIR = os.path.join(TESTDIR, 'cache')
createTestCacheFolder()
sickbeard.logger.initLogging(False, True)
#=================
# dummy functions
#=================