From 1f1e6447ddaafef9961523bf3e0dfe5a427744c8 Mon Sep 17 00:00:00 2001 From: Heikki Hokkanen Date: Mon, 14 Jul 2008 19:23:16 +0300 Subject: [PATCH] DataCollertor learned loadCache() & saveCache(). --- gitstats | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/gitstats b/gitstats index af69473..c01804e 100755 --- a/gitstats +++ b/gitstats @@ -5,6 +5,7 @@ import subprocess import datetime import glob import os +import pickle import re import shutil import sys @@ -51,6 +52,7 @@ 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. @@ -59,6 +61,17 @@ class DataCollector: 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): pass @@ -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): @@ -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) -- 2.11.4.GIT