浏览代码

DataCollertor learned loadCache() & saveCache().

Heikki Hokkanen 17 年前
父节点
当前提交
1f1e6447dd
共有 1 个文件被更改,包括 23 次插入0 次删除
  1. 23
    0
      gitstats

+ 23
- 0
gitstats 查看文件

@@ -5,6 +5,7 @@ import subprocess
5 5
 import datetime
6 6
 import glob
7 7
 import os
8
+import pickle
8 9
 import re
9 10
 import shutil
10 11
 import sys
@@ -51,6 +52,7 @@ class DataCollector:
51 52
 	"""Manages data collection from a revision control repository."""
52 53
 	def __init__(self):
53 54
 		self.stamp_created = time.time()
55
+		self.cache = {}
54 56
 	
55 57
 	##
56 58
 	# This should be the main function to extract data from the repository.
@@ -58,6 +60,17 @@ class DataCollector:
58 60
 		self.dir = dir
59 61
 		self.projectname = os.path.basename(os.path.abspath(dir))
60 62
 	
63
+	##
64
+	# Load cacheable data
65
+	def loadCache(self, dir):
66
+		cachefile = os.path.join(dir, 'gitstats.cache')
67
+		if not os.path.exists(cachefile):
68
+			return
69
+		print 'Loading cache...'
70
+		f = open(os.path.join(dir, 'gitstats.cache'))
71
+		self.cache = pickle.load(f)
72
+		f.close()
73
+	
61 74
 	##
62 75
 	# Produce any additional statistics from the extracted data.
63 76
 	def refine(self):
@@ -102,6 +115,14 @@ class DataCollector:
102 115
 	
103 116
 	def getTotalLOC(self):
104 117
 		return -1
118
+	
119
+	##
120
+	# Save cacheable data
121
+	def saveCache(self, dir):
122
+		print 'Saving cache...'
123
+		f = open(os.path.join(dir, 'gitstats.cache'), 'w')
124
+		pickle.dump(self.cache, f)
125
+		f.close()
105 126
 
106 127
 class GitDataCollector(DataCollector):
107 128
 	def collect(self, dir):
@@ -857,8 +878,10 @@ os.chdir(gitpath)
857 878
 
858 879
 print 'Collecting data...'
859 880
 data = GitDataCollector()
881
+data.loadCache(gitpath)
860 882
 data.collect(gitpath)
861 883
 print 'Refining data...'
884
+data.saveCache(gitpath)
862 885
 data.refine()
863 886
 
864 887
 os.chdir(rundir)