diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2004-01-06 06:20:22 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2004-01-06 06:20:22 +0000 |
commit | 7cbef35b32ee422d802dae7d61c8b4644d35f170 (patch) | |
tree | 71a1fcabec64e37c9efdd70fbef143e3c0cafe2b | |
parent | 010c079694d57a8bbfb57fadf63a542a53aa805d (diff) | |
download | bcfg2-7cbef35b32ee422d802dae7d61c8b4644d35f170.tar.gz bcfg2-7cbef35b32ee422d802dae7d61c8b4644d35f170.tar.bz2 bcfg2-7cbef35b32ee422d802dae7d61c8b4644d35f170.zip |
allow FileBacked to create files
2004/01/05 23:43:58-06:00 anl.gov!desai
make FileBacked Read-Write
(Logical change 1.12)
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@43 ce84e21b-d406-0410-9b95-82705330c041
-rw-r--r-- | src/GeneratorUtils.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/GeneratorUtils.py b/src/GeneratorUtils.py index 69fe86e3f..03895159f 100644 --- a/src/GeneratorUtils.py +++ b/src/GeneratorUtils.py @@ -5,14 +5,18 @@ from os import listdir, stat from stat import ST_MTIME class FileBacked(object): - '''FileBacked is a class that will cache file data and automatically reload it as required from disk. - This class is currently READ-ONLY.''' + '''FileBacked is a class that will cache file data and automatically reload it as required from disk.''' def __init__(self,filename): '''Setup initial structures''' self.filename = filename - self.mtime = stat(filename)[ST_MTIME] - self._data = file(filename).read() + try: + self.mtime = stat(filename)[ST_MTIME] + self._data = file(filename).read() + except OSError: + self.mtime = 0 + self._data = None + self.setdata('') def getdata(self): mtime = stat(self.filename)[ST_MTIME] @@ -22,12 +26,16 @@ class FileBacked(object): return self._data def setdata(self,val): - pass + if val != self._data: + self._data = val + file(self.filename,'w').write(val) + self.mtime = stat(self.filename)[ST_MTIME] data=property(getdata,setdata) class DirectoryBacked(object): - '''DirectoryBacked caches a complete directory (including proper negative caching)''' + '''DirectoryBacked caches a complete directory (including proper negative caching). + This class is READ-ONLY.''' def __init__(self,path): self.path = path |