def testCacheLifetime(self): """Cache deleted if created by Service - else left alone""" dict = {'logger': self.logger, 'endpoint':'http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi', 'cacheduration': 100} os.environ.pop('TMPDIR', None) # Mac sets this by default service = Service(dict) cache_path = service['cachepath'] self.assertTrue(os.path.isdir(cache_path)) del service self.assertFalse(os.path.exists(cache_path)) cache_path = tempfile.mkdtemp() dict['cachepath'] = cache_path service = Service(dict) del service self.assertTrue(os.path.isdir(cache_path)) Permissions.owner_readwriteexec(cache_path)
def cachePath(self, given_path, service_name): """Return cache location""" if not service_name: service_name = 'REQUESTS' top = self.cacheTopPath(given_path, service_name) # deal with multiple Services that have the same service running and # with multiple users for a given Service if self.getUserName() is None: cachepath = os.path.join(top, self['endpoint_components'].netloc) else: cachepath = os.path.join(top, '%s-%s' % (self.getUserName(), self.getDomainName())) try: # only we should be able to write to this dir os.makedirs(cachepath, stat.S_IRWXU) except OSError: if not os.path.isdir(cachepath): raise Permissions.owner_readwriteexec(cachepath) return cachepath