def dumpcache(): try: path_cache = os.path.join(CONF_PATH, CACHE_FILE) sc = ShelveCache(path_cache) for k in list(sc.keys()): uprint(repr(sc[k])) except: pass
def purgecache(): try: path_cache = os.path.join(CONF_PATH, CACHE_FILE) sc = ShelveCache(path_cache) if sc.purge(): print('Cache: has %s records' % len(sc)) except: pass
# set CONF_PATH if CONF_PATH is None: if VIRTUAL: CONF_PATH = os.path.join(sys.prefix, 'isbntools') else: CONF_PATH = os.path.expanduser('~/isbntools') # set metadata cache if config.options.get('CACHE', 'UNDEFINED').lower() == 'no': registry.set_cache(None) else: CACHE_FILE = '.metacache' cache_path = os.path.join(CONF_PATH, CACHE_FILE) from isbnlib.dev.helpers import ShelveCache try: registry.set_cache(ShelveCache(cache_path)) except: # stay with the default in-memory cache pass # set logger fmt = "%(asctime)s;%(levelname)s;%(message)s" if CONF_PATH: log_path = os.path.join(CONF_PATH, 'isbntools.log') debug = config.options.get('DEBUG', 'False') level = logging.DEBUG if debug == 'True' else logging.CRITICAL log_file = 'isbntools.DEBUG.log' if debug == 'True' else 'isbntools.log' log_path = os.path.join(CONF_PATH, log_file) logging.basicConfig(filename=log_path, level=level, format=fmt) else: logging.basicConfig(level=logging.CRITICAL, format=fmt)