def clearCache(name, arguments, matchExact=None): if matchExact: path, svr, fk = _genCachedComponentPath(name, arguments) _expireCacheFile(path) else: name = _normpath(name) md5, fullKey = _genCacheKey(arguments) if Configuration.numServers: names = ' '.join([ _shellEscape("%s/%s/%s" % (Configuration.componentCacheRoot, i, name)) for i in range(Configuration.numServers) ]) else: names = "%s/%s" % (Configuration.componentCacheRoot, _shellEscape(name)) greps = [] if fullKey is None: raise RuntimeError, \ "key files not written, but attempt to use inexact cache clear" for k, v in fullKey.items(): #print "--> %r %r" % (k, v) greps.append(_shellQuote("%r %r" % (k, v))) cmd = ('%(find)s %(names)s -name "*.cache" | %(sed)s ' "'s/.cache$/.key/' ") % { 'find': Configuration.findCommand, 'names': names, 'sed': Configuration.sedCommand } cmd += "|" + " | ".join([ "%s %s -l %s" % (Configuration.xargsCommand, Configuration.fgrepCommand, i) for i in greps ]) LOG('running command %s' % cmd) ret, out = commands.getstatusoutput(cmd) #LOG('code %s, out %s' % (ret, out)) if ret: ERROR('Command "%s" returned %d, output:\n%s' % (cmd, ret, out)) return out = [ out[:-3] + 'cache' for i in out.split('\n') if len(i.strip()) and i[:6] != 'find: ' ] LOG('Expiring %s' % out) for i in out: _expireCacheFile(i)
def _writeDisk(path, data): DEBUG(CACHE, "writing to disk %s" % path) try: dirname = os.path.split(path)[0] try: os.makedirs(dirname) except OSError, val: if val.errno != errno.EEXIST: raise global _tempCounter tempfile = "%s/%s.%d.%s" % (dirname, _tempPrefix, _tempCounter, _tempPostfix) _tempCounter += 1 open(tempfile, 'wb').write(data) except IOError, val: LOG("ERROR writing tempfile") return None try: os.rename(tempfile, path) except OSError, val: LOG("ERROR renaming tempfile %s" % str(val)) return None return 1 ## compile cache access def _writeCompileCache(name, thing, serializeFunc): DEBUG(CACHE, "writing compile cache") path = _fixPath(Configuration.compileCacheRoot, name + "c") try: _writeDisk(path, serializeFunc(thing))