14
14
# You should have received a copy of the GNU General Public License along with ankidroid-triage.
15
15
# If not, see http://www.gnu.org/licenses/.
16
16
# #####
17
+ from __future__ import with_statement
17
18
18
19
import os , sys , logging , re , hashlib , time
19
20
from datetime import datetime
28
29
settings ._target = None
29
30
30
31
from google .appengine .ext import webapp
32
+ from google .appengine .ext import db
33
+ from google .appengine .ext import blobstore
31
34
from google .appengine .ext .webapp .util import run_wsgi_app
32
35
from google .appengine .ext .webapp import template
33
36
from google .appengine .api .urlfetch import fetch
34
37
from google .appengine .api .urlfetch import Error
35
38
from google .appengine .api import taskqueue
36
39
from google .appengine .api import memcache
40
+ from google .appengine .api import files
41
+ from google .appengine .ext .webapp import blobstore_handlers
37
42
38
43
from receive_ankicrashes import AppVersion
39
44
from receive_ankicrashes import Feedback
40
45
from receive_ankicrashes import CrashReport
41
- from receive_ankicrashes import HospitalizedReport
42
46
from receive_ankicrashes import Bug
43
47
from BeautifulSoup import BeautifulSoup
44
48
from Cnt import Cnt
49
+ from FileWr import FileWr
45
50
from Lst import Lst
46
51
47
- # Remove the standard version of Django
48
- #for k in [k for k in sys.modules if k.startswith('django')]:
49
- # del sys.modules[k]
50
52
webapp .template .register_template_library ('templatetags.basic_math' )
51
53
52
- class AdminOpsBackendManager (webapp .RequestHandler ):
54
+ class BlobSetter (webapp .RequestHandler ):
53
55
def get (self ):
54
- vq = AppVersion .all ()
55
- vq .order ("-activeFrom" )
56
- vo = vq .fetch (2000 )
57
- vn = [v .name for v in vo ]
58
- vn .insert (0 , 'all' )
59
- Lst .set ("all_version_names_list" , vn )
60
-
61
- outputstr = repr (Lst .get ("all_version_names_list" ))
62
- self .response .out .write (outputstr )
63
-
64
- def post (self ):
65
- params = {'op' : self .request .get ('op' ), 'cmd' : self .request .get ('cmd' )}
66
- #taskqueue.add(queue_name='admin-ops-queue', url='/backend/testing', params=params, method='GET', target='admin-ops-handler')
67
- for i in range (1 , 98 ):
68
- taskqueue .add (queue_name = 'admin-ops-queue' , url = '/backend/testing' , params = params , method = 'GET' )#, target='admin-ops-handler')
69
-
70
- #time.sleep(5)
71
- #self.redirect('/admin_ops/backend')
56
+ fwe = FileWr .get_by_key_name ("export_csv" )
57
+ fwc = FileWr (key_name = "crash_export_csv" )
58
+ fwc .bkey = fwe .bkey
59
+ fwc .put ()
60
+ self .response .out .write ("OK" )
72
61
73
62
class ShowCrashBody (webapp .RequestHandler ):
74
63
def get (self ):
@@ -82,135 +71,9 @@ def get(self):
82
71
path = os .path .join (os .path .dirname (__file__ ), 'templates/admin_ops_show.html' )
83
72
self .response .out .write (template .render (path , template_values ))
84
73
85
- ###
86
- # This class is used for bulk ad hoc operations in the DB, eg reparsing signatures, rebuilding the
87
- # bugs table or adding new properties to the entities.
88
- #
89
- # Due to limitations of time and memory in the AppEngine, we can't process all the entities in a
90
- # big loop, we have to work in batches. Each page loaded is a batch, following Next we can process
91
- # the next one, until all are done.
92
- ##########
93
- class RebuildVersions (webapp .RequestHandler ):
94
- batch_size = 400
95
- def get (self ):
96
- batch = RebuildVersions .batch_size
97
- crashes_query = CrashReport .all ()
98
- crashes = []
99
- page = int (self .request .get ('page' , 0 ))
100
- if page == 0 :
101
- # Reset appVersion crashCount & lastIncident
102
- versions_query = AppVersion .all ()
103
- versions = versions_query .fetch (2000 )
104
- for v in versions :
105
- v .crashCount = 0
106
- v .lastIncident = datetime (2000 ,1 ,1 )
107
- v .put ()
108
-
109
- total_results = crashes_query .count (1000000 )
110
- logging .info ("Admin ops - total_results: " , total_results )
111
- last_page = max ((total_results - 1 ) // batch , 0 )
112
- if page > last_page :
113
- page = last_page
114
- crashes = crashes_query .fetch (batch , page * batch )
115
- versionCounts = {}
116
- versionLastIncidents = {}
117
- for cr in crashes :
118
- vname = cr .versionName .strip ()
119
- if cr .versionName <> vname :
120
- cr .versionName = vname
121
- cr .put ()
122
- if vname in versionCounts :
123
- versionCounts [vname ] = versionCounts [vname ] + 1
124
- else :
125
- versionCounts [vname ] = 1
126
-
127
- if cr .versionName in versionLastIncidents :
128
- if versionLastIncidents [vname ] < cr .crashTime :
129
- versionLastIncidents [vname ] = cr .crashTime
130
- else :
131
- versionLastIncidents [vname ] = cr .crashTime
132
-
133
- for vname in versionCounts :
134
- versions_query = AppVersion .all ()
135
- versions_query .filter ('name =' , vname )
136
- versions = versions_query .fetch (1 )
137
- if versions :
138
- version = versions [0 ]
139
- version .crashCount = version .crashCount + versionCounts [vname ]
140
- if version .lastIncident < versionLastIncidents [vname ]:
141
- version .lastIncident = versionLastIncidents [vname ]
142
- version .put ()
143
- else :
144
- logging .info ("missing version: " + vname )
145
-
146
- template_values = {
147
- 'values' : versionCounts ,
148
- 'page' : page ,
149
- 'last_page' : last_page ,
150
- 'page_size' : batch ,
151
- 'op_link' : 'rebuild_versions' ,
152
- 'column_key' : 'Version' ,
153
- 'column_value' : 'Count' ,
154
- 'page_results' : len (crashes ),
155
- 'total_results' : total_results }
156
- path = os .path .join (os .path .dirname (__file__ ), 'templates/admin_ops.html' )
157
- self .response .out .write (template .render (path , template_values ))
158
-
159
- class RebuildBugs (webapp .RequestHandler ):
160
- def get (self ):
161
- batch = RebuildBugs .batch_size
162
- crashes_query = CrashReport .all ()
163
- crashes = []
164
- page = int (self .request .get ('page' , 0 ))
165
- if page == 0 :
166
- # Remove Bugs
167
- bugs_query = Bug .all ()
168
- bugs = bugs_query .fetch (2000 )
169
- for b in bugs :
170
- b .delete ()
171
-
172
- total_results = crashes_query .count (1000000 )
173
- last_page = max ((total_results - 1 ) // batch , 0 )
174
- if page > last_page :
175
- page = last_page
176
- logging .info ("Admin ops - total_results: " , str (total_results ) + ", page: " + str (page ) + "/" + str (last_page ))
177
- crashes = crashes_query .fetch (batch , page * batch )
178
- valueSet = {}
179
- valueSet ["unlinked" ] = 0
180
- # Main ops loop
181
- for cr in crashes :
182
- cr .bugKey = None
183
- cr .crashSignature = CrashReport .getCrashSignature (cr .report )
184
- cr .put ()
185
- if cr .crashSignature == '\n ' :
186
- logging .warning ("Can't get signature for CrashReport: " + str (cr .key ().id ()))
187
- valueSet ["unlinked" ] = valueSet ["unlinked" ] + 1
188
- else :
189
- cr .signHash = hashlib .sha1 (cr .crashSignature ).hexdigest ()
190
- cr .linkToBug ()
191
- bugId = str (cr .bugKey .key ().id ())
192
- if bugId in valueSet :
193
- valueSet [bugId ] = valueSet [bugId ] + 1
194
- else :
195
- valueSet [bugId ] = 1
196
- template_values = {
197
- 'values' : valueSet ,
198
- 'page' : page ,
199
- 'last_page' : last_page ,
200
- 'page_size' : batch ,
201
- 'op_link' : 'rebuild_bugs' ,
202
- 'column_key' : 'BugId' ,
203
- 'column_value' : 'Count' ,
204
- 'page_results' : len (crashes ),
205
- 'total_results' : total_results }
206
- path = os .path .join (os .path .dirname (__file__ ), 'templates/admin_ops.html' )
207
- self .response .out .write (template .render (path , template_values ))
208
-
209
74
application = webapp .WSGIApplication (
210
75
[(r'^/admin_show.*$' , ShowCrashBody ),
211
- (r'^/admin_ops/rebuild_versions$' , RebuildVersions ),
212
- #(r'^/admin_ops/rebuild_bugs$', RebuildBugs)],
213
- (r'^/admin_ops/backend.*$' , AdminOpsBackendManager )],
76
+ (r'^/admin_ops/bset.*$' , BlobSetter )],
214
77
debug = True )
215
78
216
79
def main ():
0 commit comments