send diagnostics

This commit is contained in:
j 2016-02-23 13:47:10 +05:30
parent 695deb0947
commit edcd933f2b
2 changed files with 40 additions and 0 deletions

View file

@ -11,6 +11,7 @@ import db
import state import state
import settings import settings
import update import update
import utils
import logging import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -30,6 +31,8 @@ class Downloads(Thread):
settings.server['last_update_check'] = now settings.server['last_update_check'] = now
update.download() update.download()
state.user().export_library() state.user().export_library()
if settings.preferences.get('sendDiagnostics'):
utils.send_debug()
def download_next(self): def download_next(self):
import item.models import item.models

View file

@ -480,3 +480,40 @@ def get_peer(peerid):
if peerid not in state.peers: if peerid not in state.peers:
state.peers[peerid] = library.Peer(peerid) state.peers[peerid] = library.Peer(peerid)
return state.peers[peerid] return state.peers[peerid]
def send_debug():
import settings
import tor_request
import gzip
import io
url = 'http://rnogx24drkbnrxa3.onion/debug'
headers = {
'User-Agent': settings.USER_AGENT,
}
debug_log = os.path.join(settings.data_path, 'debug.log')
try:
if os.path.exists(debug_log):
data = []
today = datetime.now().strftime('%Y-%m-%d').encode()
old = True
with open(debug_log, 'rb') as fd:
for line in fd:
if line.startswith(today):
old = False
if not old:
data.append(line)
data = b'\n'.join(data)
if data:
bytes_io = io.BytesIO()
gzip_file = gzip.GzipFile(fileobj=bytes_io, mode='wb')
gzip_file.write(data)
gzip_file.close()
result = bytes_io.getvalue()
bytes_io.close()
opener = tor_request.get_opener()
opener.addheaders = list(zip(headers.keys(), headers.values()))
r = opener.open(url, result)
if r.status != 200:
logger.debug('failed to send debug information')
except:
logger.debug('failed to send debug information')