From 11b4705dede5510cec70dd45b9cf0293de8c6090 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 2 Jan 2014 08:23:40 +0400 Subject: [PATCH] fixed a bug in buildcache -- now it both loads the latest version of images AND merges diffs... Signed-off-by: Alex A. Naanou --- buildcache.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/buildcache.py b/buildcache.py index 98cae7cc..914502da 100755 --- a/buildcache.py +++ b/buildcache.py @@ -2,7 +2,7 @@ #======================================================================= __version__ = '''0.0.01''' -__sub_version__ = '''20131228083526''' +__sub_version__ = '''20140102074435''' __copyright__ = '''(c) Alex A. Naanou 2011''' @@ -258,7 +258,8 @@ def make_inline_report_progress(state=None): #----------------------------------------------------------mergediffs--- ##!!! this is generic, move to pli? -def mergediffs(path, base, isdiff, merge, dfl, cmp=None, verbosity=0): +def mergediffs(path, base, isdiff, merge, dfl, + get_latest_base=True, isversion=None, load=None, cmp=None, verbosity=0): ''' load the base file and merge in all the diff files in order. ''' @@ -267,11 +268,21 @@ def mergediffs(path, base, isdiff, merge, dfl, cmp=None, verbosity=0): if not os.path.exists(path): return res # base images file... - target = pathjoin(path, base) - if os.path.exists(target): - if verbosity >= 1: - print 'Loading: %s' % target - merge(res, target) + if get_latest_base: + res.update(loadlatest( + path, + isversion if isversion != None else lambda n: n.endswith(base), + lambda n: n == base, + load if load != None else lambda path: json.load(open(path)), + {}, + cmp, + verbosity=verbosity)) + else: + target = pathjoin(path, base) + if os.path.exists(target): + if verbosity >= 1: + print 'Loading: %s' % target + merge(res, target) # apply diff files... files = os.listdir(path) if cmp == None: @@ -326,6 +337,7 @@ def loadlatest(path, isversion, isbase, load, dfl, cmp=None, verbosity=0): return data + #----------------------------------------------------------------------- # API... #-----------------------------------------------------------getimages---