aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bb/data_dict.py
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2005-05-17 22:20:02 +0000
committerHolger Hans Peter Freyther <zecke@selfish.org>2005-05-17 22:20:02 +0000
commit3e4a93e745408f58009145b8b01e5740c406db91 (patch)
treea7a09e86f34eadce6582e1145f3d3067caa12acf /lib/bb/data_dict.py
parente629173521df39dbba8ff9b346ac7f1c727c1b18 (diff)
downloadbitbake-3e4a93e745408f58009145b8b01e5740c406db91.tar.gz
lib/bb/data.py:
· -Add a method to get the modify time of named bb.data instance · -Add a method to create a named bb.data instance. These instances · inherit the global configuration. lib/bb/data_dict.py: · -Add persistents to the data_dict implementation, on the commit method we will now pickle the internal dict lib/bb/make.py: -Use the new persistent/named bb.data methods.
Diffstat (limited to 'lib/bb/data_dict.py')
-rw-r--r--lib/bb/data_dict.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/lib/bb/data_dict.py b/lib/bb/data_dict.py
index 22dfdf2fe..b4d6fd73e 100644
--- a/lib/bb/data_dict.py
+++ b/lib/bb/data_dict.py
@@ -28,6 +28,14 @@ Based on functions from the base bb module, Copyright 2003 Holger Schurig
import os, re, sys, types, copy
from bb import note, debug, fatal
+try:
+ import cPickle as pickle
+except ImportError:
+ import pickle
+ print "NOTE: Importing cPickle failed. Falling back to a very slow implementation."
+
+
+
__setvar_regexp__ = {}
__setvar_regexp__["_append"] = re.compile('(?P<base>.*?)%s(_(?P<add>.*))?' % "_append")
__setvar_regexp__["_prepend"] = re.compile('(?P<base>.*?)%s(_(?P<add>.*))?' % "_prepend")
@@ -174,3 +182,63 @@ class DataDict:
def __setitem__(self,x,y):
self.dict.__setitem__(x,y)
+
+
+class DataDictPackage(DataDict):
+ """
+ Persistent Data Storage
+ """
+ def sanitize_filename(bbfile):
+ return bbfile.replace( '/', '_' )
+ sanitize_filename = staticmethod(sanitize_filename)
+
+ def unpickle(self):
+ """
+ Restore the dict from memory
+ """
+ cache_bbfile = self.sanitize_filename(self.bbfile)
+ p = pickle.Unpickler( file("%s/%s"%(self.cache,cache_bbfile),"rb"))
+ self.dict = p.load()
+ funcstr = self.getVar('__functions__', 0)
+ if funcstr:
+ comp = compile(funcstr, "<pickled>", "exec")
+ exec comp in __builtins__
+
+ def linkDataSet(self,parent):
+ if not parent == None:
+ self.initVar("_data")
+ self.dict["_data"] = parent
+
+
+ def __init__(self,cache,name,clean,parent):
+ """
+ Construct a persistent data instance
+ """
+ #Initialize the dictionary
+ DataDict.__init__(self)
+
+ self.cache = cache
+ self.bbfile = name
+
+ # Either unpickle the data or do copy on write
+ if clean:
+ self.linkDataSet(parent)
+ else:
+ self.unpickle()
+
+ def commit(self, mtime):
+ """
+ Save the package to a permanent storage
+ """
+ cache_bbfile = self.sanitize_filename(self.bbfile)
+ p = pickle.Pickler(file("%s/%s" %(self.cache,cache_bbfile), "wb" ), -1 )
+ p.dump( self.dict )
+
+ def mtime(cache,bbfile):
+ cache_bbfile = DataDictPackage.sanitize_filename(bbfile)
+ try:
+ return os.stat( "%s/%s" % (cache,cache_bbfile) )
+ except OSError:
+ return 0
+ mtime = staticmethod(mtime)
+