Skip to content

Commit 78ddecb

Browse files
committed
Typo and conventions changes.
1 parent 6e9d9df commit 78ddecb

36 files changed

+541
-612
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: 16 additions & 11 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]
@@ -194,8 +198,8 @@ def do_move(crs, filename, outfilename):
194198
waited += 1
195199
# time.sleep(0.5)
196200
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:
199203
if stamping is False:
200204
clogger.debug('No stamping')
201205
return do_move(crs, filename, outfilename)
@@ -427,17 +431,16 @@ def cdrop(obj, rm=True, force=False):
427431
else:
428432
clogger.error("%s is not a CliMAF object" % repr(obj))
429433
return
430-
fil=None
431434
if crs in crs2filename:
432435
clogger.info("Discarding cached value for %s (except if protected)" % crs)
433436
fil = crs2filename[crs]
434437
if not os.path.exists(fil):
435438
fil = alternate_filename(fil)
436439
else:
437440
# 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
441444
if fil:
442445
if rm:
443446
try:
@@ -545,7 +548,7 @@ def csync(update=False):
545548
try:
546549
with open(fn, "w") as cacheIndexFile:
547550
pickle.dump(crs2filename, cacheIndexFile, protocol=2) # Used for python 2 compatibility
548-
dropped_crs = []
551+
dropped_crs = list()
549552
except:
550553
if update:
551554
if os.path.isfile(fn) and len(files_in_cache > 0):
@@ -1074,8 +1077,10 @@ def sync_cvalues():
10741077
global cvalues
10751078

10761079
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"])
10791084
#
10801085
try:
10811086
# Try to get pre-existing on-disk content

0 commit comments

Comments
 (0)