Posted By

manatlan on 02/02/10


Tagged

python config tech xdg


Versions (?)

python, simplest ini/config container (with folder in xdg_config_home)


 / Published in: Python
 

  1. from xdg import BaseDirectory
  2. import os
  3. import ConfigParser
  4.  
  5. class Config(object):
  6. def __init__(self):
  7. self._dir=os.path.join(BaseDirectory.xdg_config_home,"freetp")
  8. if not os.path.isdir(self._dir):
  9. os.mkdir(self._dir)
  10. self._file=os.path.join(self._dir,"freetp.conf")
  11.  
  12. self._cfg = ConfigParser.RawConfigParser()
  13. if not os.path.isfile(self._file):
  14. self._cfg.add_section('Config')
  15. self._setMail("")
  16. else:
  17. self._cfg.read(self._file)
  18.  
  19. def _getMail(self):
  20. return self._cfg.get('Config', 'mail')
  21.  
  22. def _setMail(self,v):
  23. self._cfg.set('Config', 'mail',v)
  24. self._save()
  25.  
  26. mail=property(_getMail,_setMail)
  27.  
  28.  
  29. def _save(self):
  30. fid=open(self._file, 'wb')
  31. if fid:
  32. self._cfg.write(fid)
  33. fid.close()

Report this snippet  

You need to login to post a comment.