import _winreg as wreg class WindowsRegistry: def __init__(self, company="Perforce", project="P4OFC", write=1): """ handle registry access """ self.write = write self.company = company self.project = project self.keyname = "Software\\%s\\%s" % (self.company, self.project) try: if self.write: self.key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, self.keyname, wrreg.KEY_WRITE) else: self.key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, self.keyname) except: if self.write: self.key = wreg.CreateKey(wreg.HKEY_CURRENT_USER, self.keyname) def set(self, name, value): " set value in registry " if not self.write: raise Exception, "registry is read only" wreg.SetValueEx(self.key, name, 0, wreg.REG_DWORD, int(value)) def get(self, name): " get value out of registry " val, type = wreg.QueryValueEx(self.key, name) if type == wreg.REG_DWORD: return int(val) else: return str(val) def close(self): " close the key finally " self.key.Close() def __del__(self): self.close() def pval(r, name): print "%s:" % name, r.get(name) if __name__=="__main__": r = WindowsRegistry(write=0) print r.keyname pval(r, "AutoLock") r = WindowsRegistry(write=1) r.set("AutoLock", 1) pval(r, "AutoLock") pval(r, "CheckInOnClose") pval(r, "CheckOutOnOpen") pval(r, "CheckOutOnReopen") pval(r, "CheckInAfterAddReminder")
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 11314 | Robert Cowham | Initial population of perforce_software version of P4OFC | ||
//guest/robert_cowham/perforce/P4OFC/main/test/registry.py | |||||
#1 | 10843 | Robert Cowham |
Initial version of P4OFC source code. See README.txt (and LICENSE.txt and doc\P4OFC-Design.docx) |