forked from renefritze/spring-infolog
/
upload.py
executable file
·54 lines (49 loc) · 1.6 KB
/
upload.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from bottle import route,request,redirect
import bottle
from siteglobals import env, db,config,tasbot,cache
from utils import *
import hashlib,os,sys
from zipfile import ZipFile
import recordlist
@route('/upload', method='GET')
def output():
try:
return env.get_template('upload.html').render( )
except Exception, m:
return env.get_template('error.html').render(err_msg=str(m))
def parseZip( fn ):
members = dict()
zipfile = ZipFile( fn )
cache.invalidate(recordlist.output, 'list_output', )
files_of_interest = ['infolog.txt','ext.txt','platform.txt','script.txt','settings.txt','unitsync.log']
for info in zipfile.infolist():
if info.filename in files_of_interest and info.file_size < 20e5:
members[info.filename] = zipfile.read( info.filename )
return db.parseZipMembers( fn, members )
@route('/upload', method='POST')
def output_post():
try:
data = request.POST['file'].value
upload_dir = config.get('site','uploads')
fn = '%s/%s/%s.zip'%( os.getcwd(), upload_dir,hashlib.sha224(data).hexdigest() )
fd = open( fn, 'wb')
fd.write( data )
fd.close()
new_id = parseZip( fn )
base_url = config.get('site', 'baseurl' )
chan = config.get('tasbot', 'report_channel' )
tasbot.tasclient.say(chan,'new crash report uploaded: http://%s/details?id=%d'%(base_url,new_id))
return 'success'
except Exception, m:
print m
return env.get_template('error.html').render(err_msg=str(m))
if __name__=="__main__":
for fn in sys.argv[1:]:
try:
print 'parsing %s'%fn
parseZip( fn )
print '\t...done'
except Exception, e:
print '\tfailed: %s'%str(e)