Explorar el Código

Use zlib to compress the cache.

Heikki Hokkanen hace 17 años
padre
commit
29ef55792b
Se han modificado 1 ficheros con 10 adiciones y 2 borrados
  1. 10
    2
      gitstats

+ 10
- 2
gitstats Ver fichero

@@ -10,6 +10,7 @@ import re
10 10
 import shutil
11 11
 import sys
12 12
 import time
13
+import zlib
13 14
 
14 15
 GNUPLOT_COMMON = 'set terminal png transparent\nset size 0.5,0.5\n'
15 16
 
@@ -68,7 +69,12 @@ class DataCollector:
68 69
 			return
69 70
 		print 'Loading cache...'
70 71
 		f = open(cachefile)
71
-		self.cache = pickle.load(f)
72
+		try:
73
+			self.cache = pickle.loads(zlib.decompress(f.read()))
74
+		except:
75
+			# temporary hack to upgrade non-compressed caches
76
+			f.seek(0)
77
+			self.cache = pickle.load(f)
72 78
 		f.close()
73 79
 	
74 80
 	##
@@ -121,7 +127,9 @@ class DataCollector:
121 127
 	def saveCache(self, dir):
122 128
 		print 'Saving cache...'
123 129
 		f = open(os.path.join(dir, '.git', 'gitstats.cache'), 'w')
124
-		pickle.dump(self.cache, f)
130
+		#pickle.dump(self.cache, f)
131
+		data = zlib.compress(pickle.dumps(self.cache))
132
+		f.write(data)
125 133
 		f.close()
126 134
 
127 135
 class GitDataCollector(DataCollector):