Fixes bug 723235

The XML templates have been converted into properties, thus we can
compare the mtime of the XML templates (libvirt and cpuinfo) each
time they are needed, checking if they have been modified and
reloading them. Added a function to read cached files.

Change-Id: I6cf0229c6435300e73f9d9a6b10b0bf9bf144a55
This commit is contained in:
Alvaro Lopez Garcia 2011-12-02 14:18:38 +01:00
parent ab8a42740d
commit 0addbc4c34

@ -1110,3 +1110,17 @@ def sanitize_hostname(hostname):
hostname = hostname.strip('.-')
return hostname
def read_cached_file(filename, cache_info):
"""Return the contents of a file. If the file hasn't changed since the
last invocation, a cached version will be returned.
"""
mtime = os.path.getmtime(filename)
if cache_info and mtime == cache_info.get('mtime', None):
return cache_info['data']
data = open(filename).read()
cache_info['data'] = data
cache_info['mtime'] = mtime
return data