diff options
author | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-08-22 14:15:52 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-08-22 14:15:52 (GMT) |
commit | bf8f1e30adf4894883a8a9dc024e067202c021a1 (patch) | |
tree | 6de942fa93bcc95299a9bc369d0e1545fb6b8239 /sugar | |
parent | 511fec421fd4f14f8d2d8d09ac8269101a3940ea (diff) |
Forgot to add these
Diffstat (limited to 'sugar')
-rw-r--r-- | sugar/conf/Profile.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/sugar/conf/Profile.py b/sugar/conf/Profile.py new file mode 100644 index 0000000..2a15f85 --- /dev/null +++ b/sugar/conf/Profile.py @@ -0,0 +1,50 @@ +import os +from ConfigParser import ConfigParser + +class Profile: + def __init__(self): + self._nick_name = None + + def _ensure_dirs(self): + try: + os.makedirs(self._path) + except OSError, exc: + if exc[0] != 17: # file exists + print "Could not create user directory." + + def get_nick_name(self): + return self._nick_name + + def set_nick_name(self, nick_name): + self._nick_name = nick_name + self.save() + + def get_path(self): + return self._path + + def read(self, profile_id): + self._profile_id = profile_id + + base_path = os.path.expanduser('~/.sugar') + self._path = os.path.join(base_path, profile_id) + self._ensure_dirs() + + cp = ConfigParser() + parsed = cp.read([self._get_config_path()]) + + if cp.has_option('Buddy', 'NickName'): + self._nick_name = cp.get('Buddy', 'NickName') + + def save(self): + cp = ConfigParser() + + section = 'Buddy' + cp.add_section(section) + cp.set(section, 'NickName', self._nick_name) + + fileobject = open(self._get_config_path(), 'w') + cp.write(fileobject) + fileobject.close() + + def _get_config_path(self): + return os.path.join(self._path, 'config') |