Skip to content

Commit

Permalink
Adding zlib compression.
Browse files Browse the repository at this point in the history
  • Loading branch information
tarpas committed Jun 3, 2015
1 parent a3a45c3 commit 8feddb8
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions testmon/testmon_core.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import zlib

try:
import configparser
except ImportError:
import ConfigParser as configparser
import gzip
import json
import os
from collections import defaultdict
Expand All @@ -14,6 +15,8 @@
from testmon.process_code import checksum_coverage
from testmon.process_code import Module

if sys.version_info > (3,):
buffer = memoryview

def _get_python_lib_paths():
res = [sys.prefix]
Expand Down Expand Up @@ -164,20 +167,23 @@ def _fetch_attribute(self, attribute, default=None):
[self.variant + ':' + attribute])
result = cursor.fetchone()
if result:
return json.loads(result[0])
return json.loads(zlib.decompress(result[0]).decode('utf-8)'))
else:
return default

def _write_attribute(self, attribute, data):
dataid = self.variant + ':' + attribute
json_data = json.dumps(data).encode('utf-8')
compressed_data_buffer = buffer(zlib.compress(json_data))
cursor = self.connection.execute("UPDATE alldata SET data=? WHERE dataid=?",
[json.dumps(data), dataid])
[compressed_data_buffer, dataid])
if not cursor.rowcount:

cursor.execute("INSERT INTO alldata VALUES (?, ?)",
[dataid, json.dumps(data)])
[dataid, compressed_data_buffer])

def init_tables(self):
self.connection.execute('CREATE TABLE alldata (dataid text primary key, data text)')
self.connection.execute('CREATE TABLE alldata (dataid text primary key, data blob)')

def read_data(self):
self.mtimes, \
Expand Down

0 comments on commit 8feddb8

Please sign in to comment.