Skip to content
This repository has been archived by the owner on Apr 13, 2021. It is now read-only.

Commit

Permalink
pickles!
Browse files Browse the repository at this point in the history
  • Loading branch information
orestis committed Nov 28, 2008
1 parent 0c339fd commit 3505f35
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions PerfTimer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
21 changes: 18 additions & 3 deletions pysmell/idehelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down

0 comments on commit 3505f35

Please sign in to comment.