Private GIT

Skip to content
Snippets Groups Projects
Commit 3b37dc05 authored by echel0n's avatar echel0n
Browse files

Fixed issues with issue submitter and pastebin logs.

Added test for issue submitter.
parent 11e12b95
Branches
Tags
No related merge requests found
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
# along with SickRage. If not, see <http://www.gnu.org/licenses/>. # along with SickRage. If not, see <http://www.gnu.org/licenses/>.
import re import re
import sys import sys
import traceback
import sickbeard import sickbeard
...@@ -275,13 +276,6 @@ class UIError(): ...@@ -275,13 +276,6 @@ class UIError():
""" """
def __init__(self, message): def __init__(self, message):
try: self.title = sys.exc_info()[-2]
self.title = sys.exc_info()[1].message
except:
self.title = None
self.message = message self.message = message
self.time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') self.time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
\ No newline at end of file
try:
self.exc_info = sys.exc_info()
except:
self.exc_info = None
...@@ -119,13 +119,14 @@ class Logger(object): ...@@ -119,13 +119,14 @@ class Logger(object):
# pass exception information if debugging enabled # 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: if level == ERROR:
self.logger.exception(message, *args, **kwargs)
classes.ErrorViewer.add(classes.UIError(message)) classes.ErrorViewer.add(classes.UIError(message))
#if sickbeard.GIT_AUTOISSUES: #if sickbeard.GIT_AUTOISSUES:
# self.submit_errors() # self.submit_errors()
else:
self.logger.log(level, message, *args, **kwargs)
def log_error_and_exit(self, error_msg, *args, **kwargs): def log_error_and_exit(self, error_msg, *args, **kwargs):
self.log(error_msg, ERROR, *args, **kwargs) self.log(error_msg, ERROR, *args, **kwargs)
...@@ -139,8 +140,6 @@ class Logger(object): ...@@ -139,8 +140,6 @@ class Logger(object):
if not (sickbeard.GIT_USERNAME and sickbeard.GIT_PASSWORD and len(classes.ErrorViewer.errors) > 0): if not (sickbeard.GIT_USERNAME and sickbeard.GIT_PASSWORD and len(classes.ErrorViewer.errors) > 0):
return return
title = "[APP SUBMITTED]: "
gh_org = sickbeard.GIT_ORG or 'SiCKRAGETV' gh_org = sickbeard.GIT_ORG or 'SiCKRAGETV'
gh_repo = 'sickrage-issues' gh_repo = 'sickrage-issues'
...@@ -148,28 +147,26 @@ class Logger(object): ...@@ -148,28 +147,26 @@ class Logger(object):
user_agent="SiCKRAGE").get_organization(gh_org).get_repo(gh_repo) user_agent="SiCKRAGE").get_organization(gh_org).get_repo(gh_repo)
try: try:
# read log file
if self.logFile and os.path.isfile(self.logFile): if self.logFile and os.path.isfile(self.logFile):
with ek.ek(open, self.logFile) as f: with ek.ek(open, self.logFile) as f:
log_data = f.readlines() log_data = f.readlines()
except Exception as e: log_data = [line for line in reversed(log_data)]
pass
try: # parse and submit errors to issue tracker
for curError in sorted(classes.ErrorViewer.errors, key=lambda error: error.time, reverse=True)[:500]: for curError in sorted(classes.ErrorViewer.errors, key=lambda error: error.time, reverse=True)[:500]:
if not curError.title: if not curError.title:
continue continue
regex = "^(%s)\s*([A-Z]+)\s*(.+?)\s*\:\:\s*(.*)$" % curError.time
maxlines = 50
pastebin_url = None 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) x = ek.ss(x)
match = re.match(regex, x) match = re.match(regex, x)
if match: if match:
level = match.group(2) level = match.group(2)
if reverseNames[level] == ERROR: 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) pastebin_url = PastebinAPI().paste('f59b8e9fa1fc2d033e399e6c7fb09d19', paste_data)
break break
...@@ -187,14 +184,17 @@ class Logger(object): ...@@ -187,14 +184,17 @@ class Logger(object):
message += u"---\n" message += u"---\n"
message += u"_STAFF NOTIFIED_: @SiCKRAGETV/owners @SiCKRAGETV/moderators" 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: if issue:
self.log('Your issue ticket #%s was submitted successfully!' % issue.number) self.log('Your issue ticket #%s was submitted successfully!' % issue.number)
if not sickbeard.GIT_AUTOISSUES: if not sickbeard.GIT_AUTOISSUES:
ui.notifications.message('Your issue ticket #%s was submitted successfully!' % issue.number) 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): class Wrapper(object):
......
# 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)
\ No newline at end of file
...@@ -25,6 +25,7 @@ import sqlite3 ...@@ -25,6 +25,7 @@ import sqlite3
import sys import sys
import os.path import os.path
from configobj import ConfigObj
sys.path.append(os.path.abspath('..')) sys.path.append(os.path.abspath('..'))
sys.path.append(os.path.abspath('../lib')) sys.path.append(os.path.abspath('../lib'))
...@@ -54,9 +55,6 @@ FILEDIR = os.path.join(TESTDIR, SHOWNAME) ...@@ -54,9 +55,6 @@ FILEDIR = os.path.join(TESTDIR, SHOWNAME)
FILEPATH = os.path.join(FILEDIR, FILENAME) FILEPATH = os.path.join(FILEDIR, FILENAME)
SHOWDIR = os.path.join(TESTDIR, SHOWNAME + " final") 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 # prepare env functions
#================= #=================
...@@ -74,6 +72,7 @@ def createTestCacheFolder(): ...@@ -74,6 +72,7 @@ def createTestCacheFolder():
# sickbeard globals # sickbeard globals
#================= #=================
sickbeard.SYS_ENCODING = 'UTF-8' sickbeard.SYS_ENCODING = 'UTF-8'
sickbeard.showList = [] sickbeard.showList = []
sickbeard.QUALITY_DEFAULT = 4 # hdtv sickbeard.QUALITY_DEFAULT = 4 # hdtv
sickbeard.FLATTEN_FOLDERS_DEFAULT = 0 sickbeard.FLATTEN_FOLDERS_DEFAULT = 0
...@@ -90,13 +89,23 @@ sickbeard.providerList = providers.makeProviderList() ...@@ -90,13 +89,23 @@ sickbeard.providerList = providers.makeProviderList()
sickbeard.PROG_DIR = os.path.abspath('..') sickbeard.PROG_DIR = os.path.abspath('..')
sickbeard.DATA_DIR = sickbeard.PROG_DIR 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.LOG_DIR = os.path.join(TESTDIR, 'Logs')
sickbeard.logger.logFile = os.path.join(sickbeard.LOG_DIR, 'test_sickbeard.log')
createTestLogFolder() createTestLogFolder()
sickbeard.logger.initLogging(False)
sickbeard.CACHE_DIR = os.path.join(TESTDIR, 'cache') sickbeard.CACHE_DIR = os.path.join(TESTDIR, 'cache')
createTestCacheFolder() createTestCacheFolder()
sickbeard.logger.initLogging(False, True)
#================= #=================
# dummy functions # dummy functions
#================= #=================
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment