Permalink
Browse files

pickles!

  • Loading branch information...
1 parent 0c339fd commit 3505f3517158941e2b668da4359ecbe5149e7f14 @orestis committed Nov 28, 2008
Showing with 19 additions and 3 deletions.
  1. +1 −0 PerfTimer.py
  2. +18 −3 pysmell/idehelper.py
View
@@ -17,6 +17,7 @@ def add(self, name):
def report(self, (startName, startTime), (endName, endTime)):
print >> OUT, '%s: from %s to %s: %0.3f' % (self.name, startName, endName,
(endTime - startTime).microseconds / 1000.0)
+ OUT.flush()
def _end(self):
self.add('end')
View
@@ -15,6 +15,11 @@
from pysmell.codefinder import findRootPackageList, getImports, getNames, getClassAndParents, analyzeFile, getSafeTree
from pysmell.matchers import MATCHERS
+try:
+ import cPickle as pickle
+except:
+ import pickle
+
def findBase(line, col):
index = col
# col points at the end of the completed string
@@ -38,18 +43,28 @@ def updatePySmellDict(master, partial):
def tryReadPYSMELLDICT(directory, filename, dictToUpdate):
from PerfTimer import PerfTimer
t = PerfTimer('tryRead: ' + directory + ' ' + filename, 2)
- if os.path.exists(os.path.join(directory, filename)):
+ fullPath = os.path.join(directory, filename)
+ pickleFileName = os.path.join(directory, 'pickle_' + filename)
+ if os.path.exists(pickleFileName):
+ t.BeforeLoadPickle
+ d = pickle.load(open(pickleFileName, 'rb'))
+ elif os.path.exists(fullPath):
t.BeforeOpen
tagsFile = open(os.path.join(directory, filename), 'r')
try:
t.BeforeRead
contents = tagsFile.read()
t.BeforeEval
d = eval(contents)
- t.BeforeUpdate
- updatePySmellDict(dictToUpdate, d)
+ t.BeforePickle
+ pickleFile = open(pickleFileName, 'wb')
+ pickle.dump(d, pickleFile, protocol=pickle.HIGHEST_PROTOCOL)
+ pickleFile.close()
finally:
tagsFile.close()
+ t.BeforeUpdate
+ updatePySmellDict(dictToUpdate, d)
+
t.end

0 comments on commit 3505f35

Please sign in to comment.