Paul Belanger 6316206005 Disable cache for cmd testcases
Right now, we don't actually need a cache for our current tests, so
for now we'll disable it.  Future cmd tests, will enable this making
sure we have the proper coverage.

Change-Id: If7a25c3281fd57257473054348555aa06b5b6d95
Signed-off-by: Paul Belanger <pabelanger@redhat.com>
2015-10-19 22:09:56 -04:00

53 lines
1.5 KiB
Python

# Copyright 2015 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import logging
import os
from dogpile.cache.region import make_region
LOG = logging.getLogger(__name__)
class Cache(object):
def __init__(self, cachedir):
cache_dir = self._get_cache_dir(cachedir)
filename = os.path.join(cache_dir, 'cache.dbm')
LOG.debug('Using cache: %s' % filename)
self.region = make_region().configure(
'dogpile.cache.dbm',
arguments={
'filename': filename,
}
)
def get(self, title):
res = self.region.get(title)
return res if res else None
def has_changed(self, title, md5):
if self.get(title) == md5:
return False
return True
def set(self, title, md5):
self.region.set(title, md5)
def _get_cache_dir(self, cachedir):
path = os.path.expanduser(cachedir)
if not os.path.isdir(path):
os.makedirs(path)
return path