瀏覽代碼

DataCollertor learned loadCache() & saveCache().

Heikki Hokkanen 17 年之前
父節點
當前提交
1f1e6447dd
共有 1 個文件被更改,包括 23 次插入0 次删除
  1. 23
    0
      gitstats

+ 23
- 0
gitstats 查看文件

5
 import datetime
5
 import datetime
6
 import glob
6
 import glob
7
 import os
7
 import os
8
+import pickle
8
 import re
9
 import re
9
 import shutil
10
 import shutil
10
 import sys
11
 import sys
51
 	"""Manages data collection from a revision control repository."""
52
 	"""Manages data collection from a revision control repository."""
52
 	def __init__(self):
53
 	def __init__(self):
53
 		self.stamp_created = time.time()
54
 		self.stamp_created = time.time()
55
+		self.cache = {}
54
 	
56
 	
55
 	##
57
 	##
56
 	# This should be the main function to extract data from the repository.
58
 	# This should be the main function to extract data from the repository.
58
 		self.dir = dir
60
 		self.dir = dir
59
 		self.projectname = os.path.basename(os.path.abspath(dir))
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
 	# Produce any additional statistics from the extracted data.
75
 	# Produce any additional statistics from the extracted data.
63
 	def refine(self):
76
 	def refine(self):
102
 	
115
 	
103
 	def getTotalLOC(self):
116
 	def getTotalLOC(self):
104
 		return -1
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
 class GitDataCollector(DataCollector):
127
 class GitDataCollector(DataCollector):
107
 	def collect(self, dir):
128
 	def collect(self, dir):
857
 
878
 
858
 print 'Collecting data...'
879
 print 'Collecting data...'
859
 data = GitDataCollector()
880
 data = GitDataCollector()
881
+data.loadCache(gitpath)
860
 data.collect(gitpath)
882
 data.collect(gitpath)
861
 print 'Refining data...'
883
 print 'Refining data...'
884
+data.saveCache(gitpath)
862
 data.refine()
885
 data.refine()
863
 
886
 
864
 os.chdir(rundir)
887
 os.chdir(rundir)