Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <mpg@redhat.com>2007-07-30 13:34:02 (GMT)
committer Marco Pesenti Gritti <mpg@redhat.com>2007-07-30 13:34:02 (GMT)
commite2beb5b566bbe81d29bdb0fd39122334706092ca (patch)
treef45d53dca1712570f00cae519d87cbf21d902a8f /sugar
parent72857326d28917131604837ca7e1201d320be606 (diff)
Start intro if config is absent or corrupted.
Cleanups.
Diffstat (limited to 'sugar')
-rw-r--r--sugar/profile.py32
1 files changed, 21 insertions, 11 deletions
diff --git a/sugar/profile.py b/sugar/profile.py
index b5e5b51..da99f28 100644
--- a/sugar/profile.py
+++ b/sugar/profile.py
@@ -49,6 +49,7 @@ class _Profile(object):
privkey_hash -- SHA has of the child's public key
"""
def __init__(self):
+ self.valid = True
self.name = None
self.color = None
self.pubkey = None
@@ -56,26 +57,29 @@ class _Profile(object):
self.server = None
self.server_registered = False
self.backup1 = None
+
+ self._config_path = os.path.join(env.get_profile_path(), 'config')
+
self._load()
def update(self):
self._load()
def _load(self):
- cp = ConfigParser()
- config_path = os.path.join(env.get_profile_path(), 'config')
- parsed = cp.read([config_path])
- self._load_config(cp)
- del cp
-
+ self._load_config()
self._load_pubkey()
self._hash_private_key()
- def _load_config(self, cp):
+ def _load_config(self):
+ cp = ConfigParser()
+ parsed = cp.read([self._config_path])
+
if cp.has_option('Buddy', 'NickName'):
name = cp.get('Buddy', 'NickName')
# decode nickname from ascii-safe chars to unicode
self.name = name.decode("utf-8")
+ else:
+ self.valid = False
if cp.has_option('Buddy', 'Color'):
self.color = XoColor(cp.get('Buddy', 'Color'))
@@ -91,6 +95,8 @@ class _Profile(object):
if cp.has_option('Server', 'Backup1'):
self.backup1 = cp.get('Server', 'Backup1')
+ del cp
+
def _load_pubkey(self):
self.pubkey = None
@@ -100,6 +106,7 @@ class _Profile(object):
lines = f.readlines()
f.close()
except IOError, e:
+ self.valid = False
logging.error("Error reading public key: %s" % e)
return
@@ -142,20 +149,23 @@ class _Profile(object):
def set_key(self, section, key, value):
cp = ConfigParser()
- config_path = os.path.join(env.get_profile_path(), 'config')
- parsed = cp.read([config_path])
+ parsed = cp.read([self._config_path])
if not cp.has_section(section):
cp.add_section(section)
cp.set(section, key, value)
- f = open(config_path, 'w')
+ f = open(self._config_path, 'w')
cp.write(f)
f.close()
- self._load_config(cp)
del cp
+ self._load_config()
+
+def is_valid():
+ return _profile.valid
+
def get_nick_name():
return _profile.name