Skip to content

Commit 22eace0

Browse files
authored
Merge pull request #187 from rigoudyg/V2.0.1
V2.0.1
2 parents b58eeac + 78ddecb commit 22eace0

39 files changed

+611
-632
lines changed

climaf/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def tim(string=None):
3030
delta = time.time() - tim.last
3131
tim.last = time.time()
3232
# if ("dotiming" in vars() and dotiming) :
33-
if False:
33+
print_delta = False
34+
if print_delta:
3435
print("Duration %.1f for step %s" % (delta, string), file=sys.stderr)
3536

3637

climaf/cache.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
currentCache = None
3232
cachedirs = None
33+
#: The place to write the index
34+
cacheIndexFileName = None
3335
handle_cvalues = 'by_hash' # Can be False, "by_crs" or anything else. 'by_crs' means key=CRS; else means key=hash
3436
cvalues = dict()
3537
#: The length for truncating the hash value of CRS expressions when forming cache filenames
@@ -49,16 +51,18 @@
4951
#: A dict containing cache index entries (as listed in index file), which
5052
# were up to now not interpretable, given the set of defined projects
5153
crs_not_yet_evaluable = dict()
54+
dic_special = dict()
5255

5356

5457
def setNewUniqueCache(path, raz=True):
55-
""" Define PATH as the sole cache to use from now. And clear it
56-
58+
"""
59+
Define PATH as the sole cache to use from now. And clear it
5760
"""
5861
global currentCache
5962
global cachedirs
6063
global cacheIndexFileName
6164

65+
path = os.path.expanduser(path)
6266
cachedirs = [path] # The list of cache directories
6367
cacheIndexFileName = cachedirs[0] + "/index" # The place to write the index
6468
currentCache = cachedirs[0]
@@ -193,7 +197,9 @@ def do_move(crs, filename, outfilename):
193197
time.sleep(0.1)
194198
waited += 1
195199
# time.sleep(0.5)
196-
if os.path.exists(filename):
200+
if not os.path.exists(filename):
201+
raise Climaf_Cache_Error("File %s wasn't created upstream (or not quick enough)" % filename)
202+
else:
197203
if stamping is False:
198204
clogger.debug('No stamping')
199205
return do_move(crs, filename, outfilename)
@@ -242,8 +248,6 @@ def do_move(crs, filename, outfilename):
242248
elif stamping is None:
243249
clogger.critical("Cannot stamp by %s" % command)
244250
return True
245-
else:
246-
clogger.error("file %s does not exist (for crs %s)" % (filename, crs))
247251

248252

249253
def getCRS(filename):
@@ -432,6 +436,12 @@ def cdrop(obj, rm=True, force=False):
432436
fil = crs2filename[crs]
433437
if not os.path.exists(fil):
434438
fil = alternate_filename(fil)
439+
else:
440+
# In case the cache index is not up-to-date
441+
fil = hasExactObject(obj)
442+
if fil:
443+
crs2filename[crs] = fil
444+
if fil:
435445
if rm:
436446
try:
437447
if force:
@@ -538,7 +548,7 @@ def csync(update=False):
538548
try:
539549
with open(fn, "w") as cacheIndexFile:
540550
pickle.dump(crs2filename, cacheIndexFile, protocol=2) # Used for python 2 compatibility
541-
dropped_crs = []
551+
dropped_crs = list()
542552
except:
543553
if update:
544554
if os.path.isfile(fn) and len(files_in_cache > 0):
@@ -1067,8 +1077,10 @@ def sync_cvalues():
10671077
global cvalues
10681078

10691079
if handle_cvalues is not False:
1070-
ccache = "%s/cvalues.json" % currentCache
1071-
tmp = "%s/cvalues_tmp.json" % currentCache
1080+
if not os.path.isdir(currentCache):
1081+
os.makedirs(currentCache)
1082+
ccache = os.path.sep.join([currentCache, "cvalues.json"])
1083+
tmp = os.path.sep.join([currentCache, "cvalues_tmp.json"])
10721084
#
10731085
try:
10741086
# Try to get pre-existing on-disk content

0 commit comments

Comments
 (0)