|
30 | 30 |
|
31 | 31 | currentCache = None |
32 | 32 | cachedirs = None |
| 33 | +#: The place to write the index |
| 34 | +cacheIndexFileName = None |
33 | 35 | handle_cvalues = 'by_hash' # Can be False, "by_crs" or anything else. 'by_crs' means key=CRS; else means key=hash |
34 | 36 | cvalues = dict() |
35 | 37 | #: The length for truncating the hash value of CRS expressions when forming cache filenames |
|
49 | 51 | #: A dict containing cache index entries (as listed in index file), which |
50 | 52 | # were up to now not interpretable, given the set of defined projects |
51 | 53 | crs_not_yet_evaluable = dict() |
| 54 | +dic_special = dict() |
52 | 55 |
|
53 | 56 |
|
54 | 57 | 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 |
57 | 60 | """ |
58 | 61 | global currentCache |
59 | 62 | global cachedirs |
60 | 63 | global cacheIndexFileName |
61 | 64 |
|
| 65 | + path = os.path.expanduser(path) |
62 | 66 | cachedirs = [path] # The list of cache directories |
63 | 67 | cacheIndexFileName = cachedirs[0] + "/index" # The place to write the index |
64 | 68 | currentCache = cachedirs[0] |
@@ -193,7 +197,9 @@ def do_move(crs, filename, outfilename): |
193 | 197 | time.sleep(0.1) |
194 | 198 | waited += 1 |
195 | 199 | # 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: |
197 | 203 | if stamping is False: |
198 | 204 | clogger.debug('No stamping') |
199 | 205 | return do_move(crs, filename, outfilename) |
@@ -242,8 +248,6 @@ def do_move(crs, filename, outfilename): |
242 | 248 | elif stamping is None: |
243 | 249 | clogger.critical("Cannot stamp by %s" % command) |
244 | 250 | return True |
245 | | - else: |
246 | | - clogger.error("file %s does not exist (for crs %s)" % (filename, crs)) |
247 | 251 |
|
248 | 252 |
|
249 | 253 | def getCRS(filename): |
@@ -432,6 +436,12 @@ def cdrop(obj, rm=True, force=False): |
432 | 436 | fil = crs2filename[crs] |
433 | 437 | if not os.path.exists(fil): |
434 | 438 | 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: |
435 | 445 | if rm: |
436 | 446 | try: |
437 | 447 | if force: |
@@ -538,7 +548,7 @@ def csync(update=False): |
538 | 548 | try: |
539 | 549 | with open(fn, "w") as cacheIndexFile: |
540 | 550 | pickle.dump(crs2filename, cacheIndexFile, protocol=2) # Used for python 2 compatibility |
541 | | - dropped_crs = [] |
| 551 | + dropped_crs = list() |
542 | 552 | except: |
543 | 553 | if update: |
544 | 554 | if os.path.isfile(fn) and len(files_in_cache > 0): |
@@ -1067,8 +1077,10 @@ def sync_cvalues(): |
1067 | 1077 | global cvalues |
1068 | 1078 |
|
1069 | 1079 | 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"]) |
1072 | 1084 | # |
1073 | 1085 | try: |
1074 | 1086 | # Try to get pre-existing on-disk content |
|
0 commit comments