-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin_ops.py
111 lines (98 loc) · 3.99 KB
/
admin_ops.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# ###
# Copyright (c) 2010 Konstantinos Spyropoulos <inigo.aldana@gmail.com>
#
# This file is part of inimailbot
#
# inimailbot 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.
#
# inimailbot 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 inimailbot.
# If not, see http://www.gnu.org/licenses/.
# #####
import os, sys, logging, re, hashlib
from urllib import quote_plus
from string import strip
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '1.1')
# Force Django to reload its settings.
from django.conf import settings
settings._target = None
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template
from google.appengine.api.urlfetch import fetch
from google.appengine.api.urlfetch import Error
from receive_ankicrashes import CrashReport
from receive_ankicrashes import HospitalizedReport
from receive_ankicrashes import Bug
from BeautifulSoup import BeautifulSoup
# Remove the standard version of Django
#for k in [k for k in sys.modules if k.startswith('django')]:
# del sys.modules[k]
#webapp.template.register_template_library('templatetags.basic_math')
class ShowCrashBody(webapp.RequestHandler):
def get(self):
crId = long(self.request.get('id'))
cr = CrashReport.get_by_id(crId)
m = re.search(r'^(.*--\> END REPORT 1 \<--).*$', cr.report, re.S)
new_report = m.group(1)
template_values = {'crash_body': cr.report,
'new_crash_body': new_report}
logging.info(cr.report)
logging.info(new_report)
path = os.path.join(os.path.dirname(__file__), 'templates/admin_ops_show.html')
self.response.out.write(template.render(path, template_values))
class AdminOps(webapp.RequestHandler):
@classmethod
def getCrashSignature2(cls, body):
result1 = ''
result2 = ''
m1 = re.search(r"Begin Stacktrace\s*(<br>\s*)*([^<\s][^<]*[^<\s])\s*<br>", body, re.M|re.U)
if m1 and m1.groups():# and m2 and m2.groups():
result1 = re.sub(r"\$[a-fA-F0-9@]*", "", m1.group(2))
m2 = re.search(r"<br>\s*(at\scom\.ichi2\.anki\.[^<]*[^<\s])\s*<br>", body, re.M|re.U)
#"<br>\s*(at\scom\.ichi2\.anki\..*?\S)\s*<br>", body, re.M|re.U)
if m2 and m2.groups():# and m2 and m2.groups():
result2 = re.sub(r"\$[a-fA-F0-9@]*", "", m2.group(1))
return result1 + "\n" + result2
def get(self):
#bugs_query = Bug.all()
#bugs = []
#bugs = bugs_query.fetch(200)
#for bg in bugs:
# bg.delete()
crashes_query = CrashReport.all()
crashes_query.filter("bugKey =", None)
crashes = []
crashes = crashes_query.fetch(200)
results_list=[]
tags=set()
for cr in crashes:
#cr.linkToBug()
pass
#signa = CrashReport.getCrashSignature(cr.report)
#logging.debug("ID: " + str(cr.key().id()) + " sign: '" + signa + "'")
#cr.crashSignature = CrashReport.getCrashSignature(cr.report)
#cr.signHash = hashlib.sha256(cr.crashSignature).hexdigest()
#cr.bugKey = None
#cr.put()
#cr.linkToBug()
#if CrashReport.getCrashSignature(cr.report) != self.getCrashSignature2(cr.report):
results_list.append({'id': cr.key().id(), 'sig1': cr.crashId, 'sig2': str(cr.key().id())})
template_values = {'results_list': results_list, 'tags': tags}
path = os.path.join(os.path.dirname(__file__), 'templates/admin_ops.html')
self.response.out.write(template.render(path, template_values))
application = webapp.WSGIApplication(
[(r'^/ankidroid_triage/admin_show.*$', ShowCrashBody),
(r'^/ankidroid_triage/admin_ops$', AdminOps)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()