Mercurial > treepkg
changeset 38:dd88230dd762
Prefix some more attributes of Status with an underscore
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Thu, 15 Mar 2007 12:20:12 +0100 |
parents | eae021bb673d |
children | 17756cdce844 |
files | treepkg/status.py |
diffstat | 1 files changed, 20 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/treepkg/status.py Thu Mar 15 12:08:52 2007 +0100 +++ b/treepkg/status.py Thu Mar 15 12:20:12 2007 +0100 @@ -53,9 +53,16 @@ class Status(object): - magic = "Status 0.0\n" + # Overwrite in derived classes with a different magic string + _magic = "Status 0.0\n" - attrs = set(["_filename", "_values"]) + # Derived classes may extend a copy of this set with more instance + # variables. + _attrs = set(["_filename", "_values"]) + + # Derived classes should set this to a suitable list of attribute + # descriptors + _fields = () def __init__(self, filename): assert os.path.isabs(filename) @@ -72,24 +79,24 @@ f = open(self._filename) try: magic = f.next() - if magic != self.magic: + if magic != self._magic: raise ValueError("File %r has wrong magic" % self._filename) for line in f: field, value = line.split(":", 1) - self._values[field] = self.fields[field].deserialize(value) + self._values[field] = self._fields[field].deserialize(value) finally: f.close() def write(self): - lines = [self.magic] - for field, desc in self.fields.items(): + lines = [self._magic] + for field, desc in self._fields.items(): if field in self._values: lines.append("%s: %s\n" % (field, desc.serialize(self._values[field]))) util.writefile(self._filename, "".join(lines)) def __getattr__(self, attr): - desc = self.fields.get(attr) + desc = self._fields.get(attr) if desc is not None: if attr in self._values: return self._values[attr] @@ -98,10 +105,10 @@ raise AttributeError(attr) def __setattr__(self, attr, value): - if attr in self.fields: + if attr in self._fields: self._values[attr] = value self.write() - elif attr in self.attrs: + elif attr in self._attrs: self.__dict__[attr] = value else: raise AttributeError(attr) @@ -109,9 +116,9 @@ class RevisionStatus(Status): - magic = "TreePackagerStatus 0.0\n" + _magic = "TreePackagerStatus 0.0\n" - fields = dict(status=StringFieldDesc(default="unknown"), - start=DateFieldDesc(default=None), - stop=DateFieldDesc(default=None)) + _fields = dict(status=StringFieldDesc(default="unknown"), + start=DateFieldDesc(default=None), + stop=DateFieldDesc(default=None))