|
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] |
@@ -194,8 +198,8 @@ def do_move(crs, filename, outfilename): |
194 | 198 | waited += 1 |
195 | 199 | # time.sleep(0.5) |
196 | 200 | if not os.path.exists(filename): |
197 | | - raise Climaf_Cache_Error("File %s wasn't created upstream (or not quick enough)" % (filename)) |
198 | | - else : |
| 201 | + raise Climaf_Cache_Error("File %s wasn't created upstream (or not quick enough)" % filename) |
| 202 | + else: |
199 | 203 | if stamping is False: |
200 | 204 | clogger.debug('No stamping') |
201 | 205 | return do_move(crs, filename, outfilename) |
@@ -427,17 +431,16 @@ def cdrop(obj, rm=True, force=False): |
427 | 431 | else: |
428 | 432 | clogger.error("%s is not a CliMAF object" % repr(obj)) |
429 | 433 | return |
430 | | - fil=None |
431 | 434 | if crs in crs2filename: |
432 | 435 | clogger.info("Discarding cached value for %s (except if protected)" % crs) |
433 | 436 | fil = crs2filename[crs] |
434 | 437 | if not os.path.exists(fil): |
435 | 438 | fil = alternate_filename(fil) |
436 | 439 | else: |
437 | 440 | # In case the cache index is not up-to-date |
438 | | - fil=hasExactObject(obj) |
439 | | - if fil : |
440 | | - crs2filename[crs]=fil |
| 441 | + fil = hasExactObject(obj) |
| 442 | + if fil: |
| 443 | + crs2filename[crs] = fil |
441 | 444 | if fil: |
442 | 445 | if rm: |
443 | 446 | try: |
@@ -545,7 +548,7 @@ def csync(update=False): |
545 | 548 | try: |
546 | 549 | with open(fn, "w") as cacheIndexFile: |
547 | 550 | pickle.dump(crs2filename, cacheIndexFile, protocol=2) # Used for python 2 compatibility |
548 | | - dropped_crs = [] |
| 551 | + dropped_crs = list() |
549 | 552 | except: |
550 | 553 | if update: |
551 | 554 | if os.path.isfile(fn) and len(files_in_cache > 0): |
@@ -1074,8 +1077,10 @@ def sync_cvalues(): |
1074 | 1077 | global cvalues |
1075 | 1078 |
|
1076 | 1079 | if handle_cvalues is not False: |
1077 | | - ccache = "%s/cvalues.json" % currentCache |
1078 | | - 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"]) |
1079 | 1084 | # |
1080 | 1085 | try: |
1081 | 1086 | # Try to get pre-existing on-disk content |
|
0 commit comments