Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell/conf/Profile.py
blob: c3ca053fa034bf819fb3ae4e6f2d892d2f92da44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
from ConfigParser import ConfigParser

from sugar.canvas.IconColor import IconColor
from sugar import env

class _Profile:
	def __init__(self,):
		self._path = env.get_profile_path()
		self._nick_name = None
		self._color = None

		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')
		if cp.has_option('Buddy', 'Color'):
			self._color = IconColor(cp.get('Buddy', 'Color'))

		if self._color == None:
			self.set_color(IconColor())

	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_color(self):
		return self._color

	def set_color(self, color):
		self._color = color

	def get_nick_name(self):
		return self._nick_name

	def set_nick_name(self, nick_name):
		self._nick_name = nick_name

	def get_path(self):
		return self._path

	def save(self):
		cp = ConfigParser()

		section = 'Buddy'	
		cp.add_section(section)
		cp.set(section, 'NickName', self._nick_name)
		cp.set(section, 'Color', self._color.get_fill_color())

		fileobject = open(self._get_config_path(), 'w')
		cp.write(fileobject)
		fileobject.close()

	def _get_config_path(self):
		return os.path.join(self._path, 'config')