Skip to content

Commit

Permalink
DataCollertor learned loadCache() & saveCache().
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxu committed Jul 14, 2008
1 parent 2b852d8 commit 1f1e644
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions gitstats
Expand Up @@ -5,6 +5,7 @@ import subprocess
import datetime
import glob
import os
import pickle
import re
import shutil
import sys
Expand Down Expand Up @@ -51,13 +52,25 @@ class DataCollector:
"""Manages data collection from a revision control repository."""
def __init__(self):
self.stamp_created = time.time()
self.cache = {}

##
# This should be the main function to extract data from the repository.
def collect(self, dir):
self.dir = dir
self.projectname = os.path.basename(os.path.abspath(dir))

##
# Load cacheable data
def loadCache(self, dir):
cachefile = os.path.join(dir, 'gitstats.cache')
if not os.path.exists(cachefile):
return
print 'Loading cache...'
f = open(os.path.join(dir, 'gitstats.cache'))
self.cache = pickle.load(f)
f.close()

##
# Produce any additional statistics from the extracted data.
def refine(self):
Expand Down Expand Up @@ -102,6 +115,14 @@ class DataCollector:

def getTotalLOC(self):
return -1

##
# Save cacheable data
def saveCache(self, dir):
print 'Saving cache...'
f = open(os.path.join(dir, 'gitstats.cache'), 'w')
pickle.dump(self.cache, f)
f.close()

class GitDataCollector(DataCollector):
def collect(self, dir):
Expand Down Expand Up @@ -857,8 +878,10 @@ os.chdir(gitpath)

print 'Collecting data...'
data = GitDataCollector()
data.loadCache(gitpath)
data.collect(gitpath)
print 'Refining data...'
data.saveCache(gitpath)
data.refine()

os.chdir(rundir)
Expand Down

0 comments on commit 1f1e644

Please sign in to comment.